From 2555d46db0bfb7628c86977f573e0c2cd0ba43ac Mon Sep 17 00:00:00 2001 From: AtmanActive Date: Tue, 21 Jun 2016 20:45:49 +0200 Subject: [PATCH 01/13] Fix security error for getAll On big sites with dozens of CSS files included, where some of them are included from other domains, FireFox throws security error on getAll because jss traverses all available CSS files. To bypass this error and make it work with FireFox, I have added a second argument to getAll function: sheet_name, where consumers can specify which CSS filename to take into account. This enables getAll to work on only one CSS file and thus to avoid security error. --- jss.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/jss.js b/jss.js index ca4cde0..a00a48b 100644 --- a/jss.js +++ b/jss.js @@ -231,10 +231,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++) { - extend(properties, aggregateStyles(getRules(this.sheets[i], selector))); + 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 +297,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 From 7cefb70946ca9a8952bdcc20a73500726e313575 Mon Sep 17 00:00:00 2001 From: AtmanActive Date: Tue, 21 Jun 2016 20:49:01 +0200 Subject: [PATCH 02/13] Update jss.js --- jss.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/jss.js b/jss.js index a00a48b..3e2ae4e 100644 --- a/jss.js +++ b/jss.js @@ -233,18 +233,18 @@ var jss = (function() { // Returns all rules (selector is required) 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" ); - } + 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))); + 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; }, From 9dc9b9050372f30577694be7681fe19d417fba9b Mon Sep 17 00:00:00 2001 From: AtmanActive Date: Tue, 21 Jun 2016 20:57:16 +0200 Subject: [PATCH 03/13] describe getAll functions's new optional parameter Fix security error for getAll On big sites with dozens of CSS files included, where some of them are included from other domains, FireFox throws security error on getAll because jss traverses all available CSS files. To bypass this error and make it work with FireFox, I have added a second argument to getAll function: sheet_name, where consumers can specify which CSS filename to take into account. This enables getAll to work on only one CSS file and thus to avoid security error. --- README.markdown | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index b87719e..13f97c8 100644 --- a/README.markdown +++ b/README.markdown @@ -50,17 +50,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 From e188e4afbb00e830a14b74a50a911c88f763c21e Mon Sep 17 00:00:00 2001 From: AtmanActive Date: Tue, 21 Jun 2016 20:58:25 +0200 Subject: [PATCH 04/13] up version number Fix security error for getAll On big sites with dozens of CSS files included, where some of them are included from other domains, FireFox throws security error on getAll because jss traverses all available CSS files. To bypass this error and make it work with FireFox, I have added a second argument to getAll function: sheet_name, where consumers can specify which CSS filename to take into account. This enables getAll to work on only one CSS file and thus to avoid security error. --- jss.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jss.js b/jss.js index 3e2ae4e..2f54e8e 100644 --- a/jss.js +++ b/jss.js @@ -1,5 +1,5 @@ /* - * JSS v0.6 - JavaScript Stylesheets + * JSS v0.7 - JavaScript Stylesheets * https://github.com/Box9/jss * * Copyright (c) 2011, David Tang From 07d67fbcc6ffa7994ee9c2441b7a18ded7be6f30 Mon Sep 17 00:00:00 2001 From: AtmanActive Date: Tue, 21 Jun 2016 21:00:16 +0200 Subject: [PATCH 05/13] Fix security error for getAll On big sites with dozens of CSS files included, where some of them are included from other domains, FireFox throws security error on getAll because jss traverses all available CSS files. To bypass this error and make it work with FireFox, I have added a second argument to getAll function: sheet_name, where consumers can specify which CSS filename to take into account. This enables getAll to work on only one CSS file and thus to avoid security error. --- jss.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jss.min.js b/jss.min.js index 29bed50..0345b26 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 Date: Tue, 21 Jun 2016 21:01:12 +0200 Subject: [PATCH 06/13] up version number On big sites with dozens of CSS files included, where some of them are included from other domains, FireFox throws security error on getAll because jss traverses all available CSS files. To bypass this error and make it work with FireFox, I have added a second argument to getAll function: sheet_name, where consumers can specify which CSS filename to take into account. This enables getAll to work on only one CSS file and thus to avoid security error. --- README.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/README.markdown b/README.markdown index 13f97c8..b27cbf0 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,5 @@ # JSS +v0.7 A simple JavaScript library for retrieving and setting CSS stylesheet rules. From 6a0ed49a50d7189a5342fc4412d70b78fe7232dd Mon Sep 17 00:00:00 2001 From: AtmanActive Date: Tue, 21 Jun 2016 21:01:46 +0200 Subject: [PATCH 07/13] up version number On big sites with dozens of CSS files included, where some of them are included from other domains, FireFox throws security error on getAll because jss traverses all available CSS files. To bypass this error and make it work with FireFox, I have added a second argument to getAll function: sheet_name, where consumers can specify which CSS filename to take into account. This enables getAll to work on only one CSS file and thus to avoid security error. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f808786..eb6df74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jss", - "version": "0.6.0", + "version": "0.7.0", "devDependencies": { "gulp": "~3.5.6", "gulp-uglify": "~0.2.1", From 3c83d4dbe1eff4d30c3008e1ab2322347491092a Mon Sep 17 00:00:00 2001 From: AtmanActive Date: Tue, 21 Jun 2016 21:02:40 +0200 Subject: [PATCH 08/13] up version number On big sites with dozens of CSS files included, where some of them are included from other domains, FireFox throws security error on getAll because jss traverses all available CSS files. To bypass this error and make it work with FireFox, I have added a second argument to getAll function: sheet_name, where consumers can specify which CSS filename to take into account. This enables getAll to work on only one CSS file and thus to avoid security error. --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 7c6d3ac..fea9fe1 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jss", - "version": "0.6", + "version": "0.7", "main": "jss.js", "ignore": [ "test", "test/*" ] } From f839f89afd2521970e5670e9677be00b3fdff9fe Mon Sep 17 00:00:00 2001 From: AtmanActive Date: Tue, 21 Jun 2016 21:05:45 +0200 Subject: [PATCH 09/13] Fix crashing in FireFox FireFox adds properties that are undefined on read, which then crashes set function later on. --- jss.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/jss.js b/jss.js index 2f54e8e..09dc766 100644 --- a/jss.js +++ b/jss.js @@ -1,5 +1,5 @@ /* - * JSS v0.7 - 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); + } } } } From fbe621c260ca2c58e599d5dfcaf3f7d87aa2d469 Mon Sep 17 00:00:00 2001 From: AtmanActive Date: Tue, 21 Jun 2016 21:08:32 +0200 Subject: [PATCH 10/13] Fix crashing in FireFox FireFox adds properties that are undefined on read, which then crashes set function later on. --- jss.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jss.min.js b/jss.min.js index 0345b26..72d2534 100644 --- a/jss.min.js +++ b/jss.min.js @@ -1 +1 @@ -var jss=(function(){var adjSelAttrRegex=/((?:\.|#)[^\.\s#]+)((?:\.|#)[^\.\s#]+)/g;var doubleColonPseudoElRegex=/(::)(before|after|first-line|first-letter|selection)/;var singleColonPseudoElRegex=/([^:])(:)(before|after|first-line|first-letter|selection)/;var singleColonForPseudoElements;function getSelectorsAndRules(sheet){var rules=sheet.cssRules||sheet.rules||[];var results={};for(var i=0;i0){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;i0){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 Date: Tue, 21 Jun 2016 21:08:59 +0200 Subject: [PATCH 11/13] Fix crashing in FireFox FireFox adds properties that are undefined on read, which then crashes set function later on. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eb6df74..a55462b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jss", - "version": "0.7.0", + "version": "0.7.1", "devDependencies": { "gulp": "~3.5.6", "gulp-uglify": "~0.2.1", From 1245ca43892816d84498c2f6ab2b8efa45764052 Mon Sep 17 00:00:00 2001 From: AtmanActive Date: Tue, 21 Jun 2016 21:09:28 +0200 Subject: [PATCH 12/13] Fix crashing in FireFox FireFox adds properties that are undefined on read, which then crashes set function later on. --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index fea9fe1..9da4153 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jss", - "version": "0.7", + "version": "0.7.1", "main": "jss.js", "ignore": [ "test", "test/*" ] } From e8c8901a0dbee1566a8510aeb16fa9c9204ce04c Mon Sep 17 00:00:00 2001 From: AtmanActive Date: Tue, 21 Jun 2016 21:09:55 +0200 Subject: [PATCH 13/13] Fix crashing in FireFox FireFox adds properties that are undefined on read, which then crashes set function later on. --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index b27cbf0..eaced72 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,5 @@ # JSS -v0.7 +v0.7.1 A simple JavaScript library for retrieving and setting CSS stylesheet rules.