aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorValerio Virgillito2012-06-27 09:50:21 -0700
committerValerio Virgillito2012-06-27 09:50:21 -0700
commit2ebf3e3ea24d0d580575dfa13d31588dac1de445 (patch)
tree2bf23250a605ca42a33f7bc75698357e0258d624 /js
parent46174eb0ce93d660c8d2e9276fbdc4f9a03f056a (diff)
parent31a164700e95fb9bf37169eccdb009895452b8bf (diff)
downloadninja-2ebf3e3ea24d0d580575dfa13d31588dac1de445.tar.gz
Merge pull request #341 from ericguzman/Chrome20_CSS_Workaround
Styles Controller - Chrome 20 Fix
Diffstat (limited to 'js')
-rwxr-xr-xjs/controllers/styles-controller.js79
-rw-r--r--js/panels/css-panel/rule-list.reel/rule-list.js2
2 files changed, 52 insertions, 29 deletions
diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js
index 1c1e75ed..0f847653 100755
--- a/js/controllers/styles-controller.js
+++ b/js/controllers/styles-controller.js
@@ -604,51 +604,74 @@ var stylesController = exports.StylesController = Montage.create(Component, {
604 604
605 getRuleIndex : { 605 getRuleIndex : {
606 value : function(rule) { 606 value : function(rule) {
607 var rules = nj.toArray(rule.parentStyleSheet.rules), 607 var rules = nj.toArray(rule.parentStyleSheet.rules);
608 i;
609 608
610 return rules.indexOf(rule); 609 return rules.indexOf(rule);
611 } 610 }
612 }, 611 },
613 612
613 _getRuleWithCSSText : {
614 value: function(cssText, doc) {
615 var _doc = doc || this.currentDocument.model.views.design._document,
616 ruleIndex, rule;
617
618 for(var i = 0; i < _doc.styleSheets.length; i++) {
619 ruleIndex = nj.toArray(_doc.styleSheets[i].rules).map(function(rule) {
620 return rule.cssText;
621 }).indexOf(cssText);
622
623 if(ruleIndex !== -1) {
624 rule = _doc.styleSheets[i].rules[ruleIndex];
625 break;
626 }
627 }
628
629 if(!rule) {
630 ///// This should never be hit if providing cssText from existing rule (like those
631 ///// returned from getMatchedCSSRules()
632 console.warn('StylesController::_getRuleWithCSSText - No rule found with given cssText.');
633 }
634
635 return rule;
636 }
637 },
638
614 ///// Get All Matching Rules 639 ///// Get All Matching Rules
615 ///// Returns an array of css rules for an element 640 ///// Returns an array of css rules for an element
616 ///// Optionally sorted by specificity, and can omit pseudo elements 641 ///// Optionally sorted by specificity, and can omit pseudo elements
617 642
618 getMatchingRules : { 643 getMatchingRules : { //TODO: Remove omitPseudos from here and usages
619 value: function(element, omitPseudos, useStageStyleSheet) { 644 value: function(element, omitPseudos, useStageStyleSheet) {
620 var pseudos = [null], 645 var rules,
621 rules = [], 646 mappedRules,
622 win = element.ownerDocument.defaultView, 647 doc = element.ownerDocument,
623 self = this; 648 win = doc.defaultView;
624
625 if(!omitPseudos) {
626 pseudos.concat(['link', 'visited', 'active', 'hover', 'focus', 'first-letter',
627 'first-line', 'first-child', 'before', 'after', 'lang', 'target']);
628 }
629 649
630 try { 650 try {
631 pseudos.forEach(function(pseudo) { 651 mappedRules = nj.toArray(win.getMatchedCSSRules(element)).map(function(rule) {
632 rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) { 652 return this._getRuleWithCSSText(rule.cssText, doc);
633 //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, 653 }, this);
634 //// or only use rules for other stylesheets
635 654
636 var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null, 655 rules = mappedRules.filter(function(rule) {
637 isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID; 656 //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet,
657 //// or only use rules for other stylesheets
638 658
639 ///// filter out (return false) depending on flag 659 var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null,
640 if(useStageStyleSheet && !isStageStyleSheet) { return false; } 660 isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID;
641 if(!useStageStyleSheet && isStageStyleSheet) { return false; }
642 661
643 ///// Non-filter code - just assigning specificity to the rule 662 ///// filter out (return false) depending on flag
644 if(!rule[this.CONST.SPECIFICITY_KEY]) { 663 if(useStageStyleSheet && !isStageStyleSheet) { return false; }
645 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); 664 if(!useStageStyleSheet && isStageStyleSheet) { return false; }
646 }
647 665
648 return true; 666 ///// Non-filter code - just assigning specificity to the rule
667 if(!rule[this.CONST.SPECIFICITY_KEY]) {
668 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText);
669 }
670
671 return true;
649 672
650 }, this));
651 }, this); 673 }, this);
674
652 } catch(ERROR) { 675 } catch(ERROR) {
653 console.warn('StylesController::getMatchingRules - Un-attached element queried.'); 676 console.warn('StylesController::getMatchingRules - Un-attached element queried.');
654 } 677 }
diff --git a/js/panels/css-panel/rule-list.reel/rule-list.js b/js/panels/css-panel/rule-list.reel/rule-list.js
index 27d74b2f..b4cd9e97 100644
--- a/js/panels/css-panel/rule-list.reel/rule-list.js
+++ b/js/panels/css-panel/rule-list.reel/rule-list.js
@@ -81,7 +81,7 @@ exports.RuleList = Montage.create(Component, {
81 // found rule in our component list, or it's the inline rule 81 // found rule in our component list, or it's the inline rule
82 ruleComponent.update(); 82 ruleComponent.update();
83 foundIndices.push(index); 83 foundIndices.push(index);
84 } else if(!rule.applied) { /// remove rule (unless unapplied) 84 } else if(!ruleComponent.applied) { /// remove rule (unless unapplied)
85 this.rulesToRemove.push(ruleComponent); 85 this.rulesToRemove.push(ruleComponent);
86 } 86 }
87 }, this); 87 }, this);