Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashing in FireFox #39

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
9 changes: 6 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# JSS
v0.7.1

A simple JavaScript library for retrieving and setting CSS stylesheet rules.

Expand Down Expand Up @@ -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
jss.remove(); // removes all JSS styles
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jss",
"version": "0.6",
"version": "0.7.1",
"main": "jss.js",
"ignore": [ "test", "test/*" ]
}
34 changes: 23 additions & 11 deletions jss.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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;
},
Expand Down Expand Up @@ -287,4 +299,4 @@ var jss = (function() {
return exports;
})();

typeof module !== 'undefined' && module.exports && (module.exports = jss); // CommonJS support
typeof module !== 'undefined' && module.exports && (module.exports = jss); // CommonJS support
2 changes: 1 addition & 1 deletion jss.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jss",
"version": "0.6.0",
"version": "0.7.1",
"devDependencies": {
"gulp": "~3.5.6",
"gulp-uglify": "~0.2.1",
Expand Down