diff --git a/README.markdown b/README.markdown index b87719e..eaced72 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,5 @@ # JSS +v0.7.1 A simple JavaScript library for retrieving and setting CSS stylesheet rules. @@ -50,17 +51,19 @@ If your project uses Bower for package management you can run the following comm } -**jss.getAll(selector)** to retrieve all rules that are specified using the selector (not necessarily added via JSS): +**jss.getAll(selector[,sheetname])** to retrieve all rules that are specified using the selector (not necessarily added via JSS): - jss.getAll('.demo'); + jss.getAll('.demo'); // search through whole CSS stack // returns the following: { 'font-size': '15px', 'color': 'red', 'font-weight': 'bold' } + + jss.getAll('.demo','this_file_only.css'); // search only the given CSS file (which must be included in the page) **jss.remove([selector])** to remove rules added via JSS: jss.remove('.demo'); // removes all JSS styles matching the selector - jss.remove(); // removes all JSS styles \ No newline at end of file + jss.remove(); // removes all JSS styles diff --git a/bower.json b/bower.json index 7c6d3ac..9da4153 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jss", - "version": "0.6", + "version": "0.7.1", "main": "jss.js", "ignore": [ "test", "test/*" ] } diff --git a/jss.js b/jss.js index ca4cde0..09dc766 100644 --- a/jss.js +++ b/jss.js @@ -1,5 +1,5 @@ /* - * JSS v0.6 - JavaScript Stylesheets + * JSS v0.7.1 - JavaScript Stylesheets * https://github.com/Box9/jss * * Copyright (c) 2011, David Tang @@ -177,14 +177,16 @@ var jss = (function() { function setStyleProperties(rule, properties) { for (var key in properties) { var value = properties[key]; - var importantIndex = value.indexOf(' !important'); - - // Modern browsers seem to handle overrides fine, but IE9 doesn't - rule.style.removeProperty(key); - if (importantIndex > 0) { - rule.style.setProperty(key, value.substr(0, importantIndex), 'important'); - } else { - rule.style.setProperty(key, value); + if ( typeof value !== "undefined" ) { + var importantIndex = value.indexOf(' !important'); + + // Modern browsers seem to handle overrides fine, but IE9 doesn't + rule.style.removeProperty(key); + if (importantIndex > 0) { + rule.style.setProperty(key, value.substr(0, importantIndex), 'important'); + } else { + rule.style.setProperty(key, value); + } } } } @@ -231,10 +233,20 @@ var jss = (function() { return rules; }, // Returns all rules (selector is required) - getAll: function(selector) { + getAll: function(selector,sheet_name) { var properties = {}; + var regex_search; + if ( ( typeof sheet_name !== "undefined" ) && ( sheet_name != null ) ) { + regex_search = new RegExp( sheet_name, "g" ); + } for (var i = 0; i < this.sheets.length; i++) { + if ( regex_search ) { + if ( regex_search.test( this.sheets[i].href ) ) { + extend(properties, aggregateStyles(getRules(this.sheets[i], selector))); + } + } else { extend(properties, aggregateStyles(getRules(this.sheets[i], selector))); + } } return properties; }, @@ -287,4 +299,4 @@ var jss = (function() { return exports; })(); -typeof module !== 'undefined' && module.exports && (module.exports = jss); // CommonJS support \ No newline at end of file +typeof module !== 'undefined' && module.exports && (module.exports = jss); // CommonJS support diff --git a/jss.min.js b/jss.min.js index 29bed50..72d2534 100644 --- a/jss.min.js +++ b/jss.min.js @@ -1 +1 @@ -var jss=function(){function e(e){for(var t=e.cssRules||e.rules||[],r={},n=0;n0?e.style.setProperty(r,n.substr(0,s),"important"):e.style.setProperty(r,n)}}function v(e){return e.replace(/-([a-z])/g,function(e,t){return t.toUpperCase()})}function m(e){var t={};for(var r in e)t[g(r)]=e[r];return t}function g(e){return e.replace(/([A-Z])/g,function(e,t){return"-"+t.toLowerCase()})}var p,y=/((?:\.|#)[^\.\s#]+)((?:\.|#)[^\.\s#]+)/g,x=/(::)(before|after|first-line|first-letter|selection)/,S=/([^:])(:)(before|after|first-line|first-letter|selection)/,R=function(e){this.doc=e,this.head=this.doc.head||this.doc.getElementsByTagName("head")[0],this.sheets=this.doc.styleSheets||[]};R.prototype={get:function(r){if(!this.defaultSheet)return{};if(r)return l(t(this.defaultSheet,r));var n=e(this.defaultSheet);for(r in n)n[r]=l(n[r]);return n},getAll:function(e){for(var r={},n=0;n0){rule.style.setProperty(key,value.substr(0,importantIndex),'important')}else{rule.style.setProperty(key,value)}}}}function toCamelCase(str){return str.replace(/-([a-z])/g,function(match,submatch){return submatch.toUpperCase()})}function transformCamelCasedPropertyNames(oldProps){var newProps={};for(var key in oldProps){newProps[unCamelCase(key)]=oldProps[key]}return newProps}function unCamelCase(str){return str.replace(/([A-Z])/g,function(match,submatch){return'-'+submatch.toLowerCase()})}var Jss=function(doc){this.doc=doc;this.head=this.doc.head||this.doc.getElementsByTagName('head')[0];this.sheets=this.doc.styleSheets||[]};Jss.prototype={get:function(selector){if(!this.defaultSheet){return{}}if(selector){return aggregateStyles(getRules(this.defaultSheet,selector))}var rules=getSelectorsAndRules(this.defaultSheet);for(selector in rules){rules[selector]=aggregateStyles(rules[selector])}return rules},getAll:function(selector,sheet_name){var properties={};var regex_search;if((typeof sheet_name!=="undefined")&&(sheet_name!=null)){regex_search=new RegExp(sheet_name,"g")}for(var i=0;i