css-has-pseudo
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -1,1 +0,1 @@ | ||
function cssHasPseudo(n){var t=[],r=n.createElement("x");function e(){t.forEach(function(t){var e=[];Array.prototype.forEach.call(n.querySelectorAll(t.n),function(u){var o=Array.prototype.indexOf.call(u.parentNode.children,u)+1,i=t.t.map(function(n){return t.n+":nth-child("+o+") "+n}).join(),c=u.parentNode.querySelector(i);(t.r?!c:c)&&(e.push(u),r.innerHTML="<x "+t.e+">",u.attributes.setNamedItem(r.firstChild.attributes[0].cloneNode()),n.documentElement.style.zoom=1,n.documentElement.style.zoom=null)}),t.u.forEach(function(r){-1===e.indexOf(r)&&(r.removeAttribute(t.e),n.documentElement.style.zoom=1,n.documentElement.style.zoom=null)}),t.u=e})}function u(n){Array.prototype.forEach.call(n.cssRules,function(n){var r=decodeURIComponent(n.selectorText.replace(/\\(.)/g,"$1")).match(/^(.*?)\[:(not-)?has\((.+?)\)\](.*?)$/);if(r){var e=":"+(r[2]?"not-":"")+"has("+r[3].replace(/%3A/g,":").replace(/%5B/g,"[").replace(/%5D/g,"]").replace(/%2C/g,",")+")";t.push({o:n,n:r[1],r:r[2],t:r[3].split(/\s*,\s*/),e:e,u:[]})}})}Array.prototype.forEach.call(n.styleSheets,u),e(),new MutationObserver(function(r){r.forEach(function(r){Array.prototype.forEach.call(r.addedNodes||[],function(n){1===n.nodeType&&n.sheet&&u(n.sheet)}),Array.prototype.push.apply(t,t.splice(0).filter(function(t){return t.o.parentStyleSheet&&t.o.parentStyleSheet.ownerNode&&n.documentElement.contains(t.o.parentStyleSheet.ownerNode)})),e()})}).observe(n,{childList:!0,subtree:!0}),n.addEventListener("focus",function(){return setImmediate(e)},!0),n.addEventListener("blur",function(){return setImmediate(e)},!0),n.addEventListener("input",function(){return setImmediate(e)})} | ||
function cssHasPseudo(n){var t=[],r=n.createElement("x");function e(){t.forEach(function(t){var e=[];Array.prototype.forEach.call(n.querySelectorAll(t.n),function(u){var o=Array.prototype.indexOf.call(u.parentNode.children,u)+1,i=t.t.map(function(n){return t.n+":nth-child("+o+") "+n}).join(),c=u.parentNode.querySelector(i);(t.r?!c:c)&&(e.push(u),r.innerHTML="<x "+t.e+">",u.setAttributeNode(r.children[0].attributes[0].cloneNode()),n.documentElement.style.zoom=1,n.documentElement.style.zoom=null)}),t.u.forEach(function(r){-1===e.indexOf(r)&&(r.removeAttribute(t.e),n.documentElement.style.zoom=1,n.documentElement.style.zoom=null)}),t.u=e})}function u(n){Array.prototype.forEach.call(n.cssRules,function(n){var r=decodeURIComponent(n.selectorText.replace(/\\(.)/g,"$1")).match(/^(.*?)\[:(not-)?has\((.+?)\)\](.*?)$/);if(r){var e=":"+(r[2]?"not-":"")+"has("+r[3].replace(/%3A/g,":").replace(/%5B/g,"[").replace(/%5D/g,"]").replace(/%2C/g,",")+")";t.push({o:n,n:r[1],r:r[2],t:r[3].split(/\s*,\s*/),e:e,u:[]})}})}Array.prototype.forEach.call(n.styleSheets,u),e(),new MutationObserver(function(r){r.forEach(function(r){Array.prototype.forEach.call(r.addedNodes||[],function(n){1===n.nodeType&&n.sheet&&u(n.sheet)}),Array.prototype.push.apply(t,t.splice(0).filter(function(t){return t.o.parentStyleSheet&&t.o.parentStyleSheet.ownerNode&&n.documentElement.contains(t.o.parentStyleSheet.ownerNode)})),e()})}).observe(n,{childList:!0,subtree:!0}),n.addEventListener("focus",function(){return setImmediate(e)},!0),n.addEventListener("blur",function(){return setImmediate(e)},!0),n.addEventListener("input",function(){return setImmediate(e)})} |
# Changes to CSS Has Pseudo | ||
### 0.5.0 (November 21, 2018) | ||
- Further optimize script; from 775 bytes to 757 bytes | ||
### 0.4.0 (November 21, 2018) | ||
@@ -4,0 +8,0 @@ |
'use strict'; | ||
function cssHasPseudo(document) { | ||
const observedItems = []; | ||
const observedItems = []; // document.createAttribute() doesn't support `:` in the name. innerHTML does | ||
const attributeElement = document.createElement('x'); // walk all stylesheets to collect observed css rules | ||
@@ -45,5 +46,6 @@ | ||
nodes.push(element); // set an attribute with an irregular attribute name | ||
// document.createAttribute() doesn't support special characters | ||
attributeElement.innerHTML = '<x ' + item.attributeName + '>'; | ||
element.attributes.setNamedItem(attributeElement.firstChild.attributes[0].cloneNode()); // trigger a style refresh in IE and Edge | ||
element.setAttributeNode(attributeElement.children[0].attributes[0].cloneNode()); // trigger a style refresh in IE and Edge | ||
@@ -50,0 +52,0 @@ document.documentElement.style.zoom = 1; |
{ | ||
"name": "css-has-pseudo", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Style elements relative to other elements in CSS", | ||
@@ -5,0 +5,0 @@ "author": "Jonathan Neal <jonathantneal@hotmail.com>", |
@@ -44,3 +44,3 @@ # CSS Has Pseudo [<img src="http://jonathantneal.github.io/js-logo.svg" alt="" width="90" height="90" align="right">][CSS Has Pseudo] | ||
That’s it. The script is 768 bytes and works in all browsers, including | ||
That’s it. The script is 757 bytes and works in all browsers, including | ||
Internet Explorer 11. With a [Mutation Observer polyfill], the script will work | ||
@@ -47,0 +47,0 @@ down to Internet Explorer 9. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54778
372