aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAnanya Sen2012-02-21 16:46:24 -0800
committerAnanya Sen2012-02-21 16:46:24 -0800
commit539fb19b2327a9f6fb39403e27c29a8f8d733198 (patch)
tree7bc8bc1286fe45908cc8d90193a71fcf60f4caa8 /js
parent86996190d6a4dd59343d4ce482a9c0e6ef0f1eac (diff)
downloadninja-539fb19b2327a9f6fb39403e27c29a8f8d733198.tar.gz
edit by Eric G.: catch the error instead of doing the null check for the stale element
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js')
-rwxr-xr-xjs/controllers/styles-controller.js46
1 files changed, 21 insertions, 25 deletions
diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js
index 31beb6d0..662816f5 100755
--- a/js/controllers/styles-controller.js
+++ b/js/controllers/styles-controller.js
@@ -318,10 +318,6 @@ var stylesController = exports.StylesController = Montage.create(Component, {
318 style : element.style 318 style : element.style
319 }; 319 };
320 320
321 if((typeof matchedRules === "undefined") || (matchedRules === null)){
322 return null;
323 }
324
325 ///// Now splice it into the matched rules 321 ///// Now splice it into the matched rules
326 ///// By inserting the inline style at the beginning, 322 ///// By inserting the inline style at the beginning,
327 ///// we keep the correct order of specificity 323 ///// we keep the correct order of specificity
@@ -576,37 +572,36 @@ var stylesController = exports.StylesController = Montage.create(Component, {
576 win = element.ownerDocument.defaultView, 572 win = element.ownerDocument.defaultView,
577 self = this; 573 self = this;
578 574
579 if(!win) {
580 return null;
581 }
582
583 if(!omitPseudos) { 575 if(!omitPseudos) {
584 pseudos.concat(['link', 'visited', 'active', 'hover', 'focus', 'first-letter', 576 pseudos.concat(['link', 'visited', 'active', 'hover', 'focus', 'first-letter',
585 'first-line', 'first-child', 'before', 'after', 'lang', 'target']); 577 'first-line', 'first-child', 'before', 'after', 'lang', 'target']);
586 } 578 }
587 579
588 pseudos.forEach(function(pseudo) { 580 try {
589 rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) { 581 pseudos.forEach(function(pseudo) {
590 //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, 582 rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) {
591 //// or only use rules for other stylesheets 583 //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet,
584 //// or only use rules for other stylesheets
592 585
593 var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null, 586 var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null,
594 isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID; 587 isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID;
595 588
596 ///// filter out (return false) depending on flag 589 ///// filter out (return false) depending on flag
597 if(useStageStyleSheet && !isStageStyleSheet) { return false; } 590 if(useStageStyleSheet && !isStageStyleSheet) { return false; }
598 if(!useStageStyleSheet && isStageStyleSheet) { return false; } 591 if(!useStageStyleSheet && isStageStyleSheet) { return false; }
599 592
600 ///// Non-filter code - just assigning specificity to the rule 593 ///// Non-filter code - just assigning specificity to the rule
601 if(!rule[this.CONST.SPECIFICITY_KEY]) { 594 if(!rule[this.CONST.SPECIFICITY_KEY]) {
602 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); 595 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText);
603 } 596 }
604 597
605 return true; 598 return true;
606
607 }, this));
608 }, this);
609 599
600 }, this));
601 }, this);
602 } catch(ERROR) {
603 console.warn('StylesController::getMatchingRules - Un-attached element queried.');
604 }
610 ///// Function for sorting by specificity values 605 ///// Function for sorting by specificity values
611 function sorter(ruleA, ruleB) { 606 function sorter(ruleA, ruleB) {
612 var a, b, order, sheetAIndex, sheetBIndex, ruleAIndex, ruleBIndex; 607 var a, b, order, sheetAIndex, sheetBIndex, ruleAIndex, ruleBIndex;
@@ -985,6 +980,7 @@ var stylesController = exports.StylesController = Montage.create(Component, {
985 ///// Pass "true" to method to return an override object, which 980 ///// Pass "true" to method to return an override object, which
986 ///// has the rule to override, and whether the !important flag is needed 981 ///// has the rule to override, and whether the !important flag is needed
987 dominantRule = this.getDominantRuleForElement(element, property, true, isStageElement); 982 dominantRule = this.getDominantRuleForElement(element, property, true, isStageElement);
983
988 } 984 }
989 985
990 ///// Did we find a dominant rule? 986 ///// Did we find a dominant rule?