Skip to content

Commit

Permalink
Fix null parentStyleSheet issue (cburgmer#3), by creating a new style…
Browse files Browse the repository at this point in the history
… sheet for the parsing, instead of using the parentStyleSheet property
  • Loading branch information
Quentin Spencer-Harper committed Feb 19, 2016
1 parent 1f1ef7c commit 4a23fd0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/cssSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ exports.cssRulesToText = function (cssRules) {
};

exports.exchangeRule = function (cssRules, rule, newRuleText) {
var ruleIdx = cssRules.indexOf(rule),
styleSheet = rule.parentStyleSheet;

// Generate a new rule
styleSheet.insertRule(newRuleText, ruleIdx+1);
styleSheet.deleteRule(ruleIdx);
// Exchange with the new
cssRules[ruleIdx] = styleSheet.cssRules[ruleIdx];
var ruleIdx = cssRules.indexOf(rule);

// We create a new document and stylesheet to parse the rule,
// instead of relying on rule.parentStyleSheet, because
// rule.parentStyleSheet may be null
// (https://github.com/cburgmer/inlineresources/issues/3)
cssRules[ruleIdx] = exports.rulesForCssText(newRuleText)[0];
};

// Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=443978
Expand Down

0 comments on commit 4a23fd0

Please sign in to comment.