aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/controllers/styles-controller.js81
-rw-r--r--js/panels/css-panel/rule-list.reel/rule-list.js2
2 files changed, 54 insertions, 29 deletions
diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js
index 1c1e75ed..1eb7bc7f 100755
--- a/js/controllers/styles-controller.js
+++ b/js/controllers/styles-controller.js
@@ -604,51 +604,76 @@ 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 debugger;
632 rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) { 652
633 //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, 653 mappedRules = nj.toArray(win.getMatchedCSSRules(element)).map(function(rule) {
634 //// or only use rules for other stylesheets 654 return this._getRuleWithCSSText(rule.cssText, doc);
655 }, this);
635 656
636 var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null, 657 rules = mappedRules.filter(function(rule) {
637 isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID; 658 //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet,
659 //// or only use rules for other stylesheets
638 660
639 ///// filter out (return false) depending on flag 661 var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null,
640 if(useStageStyleSheet && !isStageStyleSheet) { return false; } 662 isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID;
641 if(!useStageStyleSheet && isStageStyleSheet) { return false; }
642 663
643 ///// Non-filter code - just assigning specificity to the rule 664 ///// filter out (return false) depending on flag
644 if(!rule[this.CONST.SPECIFICITY_KEY]) { 665 if(useStageStyleSheet && !isStageStyleSheet) { return false; }
645 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); 666 if(!useStageStyleSheet && isStageStyleSheet) { return false; }
646 }
647 667
648 return true; 668 ///// Non-filter code - just assigning specificity to the rule
669 if(!rule[this.CONST.SPECIFICITY_KEY]) {
670 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText);
671 }
672
673 return true;
649 674
650 }, this));
651 }, this); 675 }, this);
676
652 } catch(ERROR) { 677 } catch(ERROR) {
653 console.warn('StylesController::getMatchingRules - Un-attached element queried.'); 678 console.warn('StylesController::getMatchingRules - Un-attached element queried.');
654 } 679 }
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);