cssomtools
Version:
The 'jQuery-for-the-CSSOM', a library for working with CSS stylesheets and rules in the browser
1 lines • 2.57 kB
JavaScript
var cssomtools=\u00e7=function(){function d(a){return a&&a.cssRules&&a.cssRules.length}function f(a){a=a||"";var c=document.createElement("iframe");document.head.appendChild(c);var b=c.contentDocument.createElement("style");b.textContent=a;c.contentDocument.head.appendChild(b);a=c.contentDocument.styleSheets[0];document.head.removeChild(c);return a}function k(a,c){function b(a){d(a)&&[].slice.call(a.cssRules).forEach(function(a){c(a);d(a)&&b(a)})}a=a||e();c=c||function(a){return a};Array.isArray(a)?a.map(function(a){return k(a,c)}):b(a);return a}function h(a,c,b){c=c||e().length&&e()[e().length-1]||f();b=b||c.cssRules.length;Array.isArray(a)?a.forEach(function(a){return h(a,c,b)}):d(a)?[].slice.call(a.cssRules).forEach(function(a){return h(a,c,b)}):a.cssText?c.insertRule(a.cssText,b):"string"===typeof a&&h(f(a),c,b);return c}function l(a){a=a||f();Array.isArray(a)?a.map(l):d(a)?[].slice.call(a.cssRules).map(l):a.parentRule?a.parentRule.deleteRule([].slice.call(a.parentRule.cssRules).indexOf(a)):a.parentStyleSheet&&a.parentStyleSheet.deleteRule([].slice.call(a.parentStyleSheet.cssRules).indexOf(a));return a}function m(a){function c(a){return a.cssText||""}a=a||e();return Array.isArray(a)?a.map(m).join("\n"):d(a)?[].slice.call(a.cssRules).map(c).join("\n"):c(a)}function e(){return [].slice.call(document.styleSheets).map(function(a){try{a.cssRules}catch(c){return null}return a}).filter(d)}function g(a,c){a=a||f();c=c||function(a){return a};var b={cssRules:[]};k(a,function(a){c(a)&&b.cssRules.push(a)});return b}return{parse:f,process:k,add:h,remove:l,stringify:m,all:e,filter:g,selector:function(a,c,b){a=a||"";c=c||!1;b=b||e();b.cssRules&&(b=[b]);return b.map(function(b){return g(b,function(b){return c?b.selectorText&&b.selectorText.trim()===a:b.selectorText&&-1!==b.selectorText.indexOf(a)})}).filter(d)},property:function(a,c,b){a=a||"";c=c||!1;b=b||e();b.cssRules&&(b=[b]);return b.map(function(b){return g(b,function(b){return b.style&&[].slice.call(b.style).some(function(b){return c?b.trim()===a:-1!==b.indexOf(a)})})}).filter(d)},value:function(a,c,b){a=a||"";c=c||!1;b=b||e();b.cssRules&&(b=[b]);return b.map(function(b){return g(b,function(b){return b.style&&[].slice.call(b.style).some(function(d){return c?b.style.getPropertyValue(d).trim()===a:-1!==b.style.getPropertyValue(d).indexOf(a)})})}).filter(d)},query:function(a,c,b){a=a||"";c=c||!1;b=b||e();b.cssRules&&(b=[b]);return b.map(function(b){return g(b,function(b){return c?b.media&&b.media.mediaText.trim()===a:b.media&&-1!==b.media.mediaText.indexOf(a)})}).filter(d)}}}();