diff options
author | Jose Antonio Marquez | 2012-06-27 09:58:09 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-06-27 09:58:09 -0700 |
commit | f9e4f6de44e667b535077c69a8383e76372b7de8 (patch) | |
tree | 0c7d88a9ca212c839617c04b7c272e8f3404f0e1 | |
parent | bf5b9e509d034fc9b2cf3aacdcae306781f59f7e (diff) | |
parent | 2ebf3e3ea24d0d580575dfa13d31588dac1de445 (diff) | |
download | ninja-f9e4f6de44e667b535077c69a8383e76372b7de8.tar.gz |
Merge branch 'refs/heads/Ninja-Internal' into Color
-rwxr-xr-x | js/controllers/styles-controller.js | 79 | ||||
-rw-r--r-- | js/panels/css-panel/rule-list.reel/rule-list.js | 2 |
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); |