aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/styles-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/styles-controller.js')
-rwxr-xr-xjs/controllers/styles-controller.js33
1 files changed, 26 insertions, 7 deletions
diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js
index 0f847653..6e363798 100755
--- a/js/controllers/styles-controller.js
+++ b/js/controllers/styles-controller.js
@@ -213,6 +213,9 @@ var stylesController = exports.StylesController = Montage.create(Component, {
213 213
214 stylesheet.insertRule(ruleText, index); 214 stylesheet.insertRule(ruleText, index);
215 215
216 ///// Invalidate cache because rule dominance is affected
217 this._clearCache();
218
216 this.styleSheetModified(stylesheet); 219 this.styleSheetModified(stylesheet);
217 220
218 rule = stylesheet.rules[index]; 221 rule = stylesheet.rules[index];
@@ -629,7 +632,7 @@ var stylesController = exports.StylesController = Montage.create(Component, {
629 if(!rule) { 632 if(!rule) {
630 ///// This should never be hit if providing cssText from existing rule (like those 633 ///// This should never be hit if providing cssText from existing rule (like those
631 ///// returned from getMatchedCSSRules() 634 ///// returned from getMatchedCSSRules()
632 console.warn('StylesController::_getRuleWithCSSText - No rule found with given cssText.'); 635 //console.warn('StylesController::_getRuleWithCSSText - No rule found with given cssText.');
633 } 636 }
634 637
635 return rule; 638 return rule;
@@ -643,16 +646,31 @@ var stylesController = exports.StylesController = Montage.create(Component, {
643 getMatchingRules : { //TODO: Remove omitPseudos from here and usages 646 getMatchingRules : { //TODO: Remove omitPseudos from here and usages
644 value: function(element, omitPseudos, useStageStyleSheet) { 647 value: function(element, omitPseudos, useStageStyleSheet) {
645 var rules, 648 var rules,
649 matchedRules,
646 mappedRules, 650 mappedRules,
647 doc = element.ownerDocument, 651 doc = element.ownerDocument,
648 win = doc.defaultView; 652 win = doc.defaultView;
649 653
654 if(!element.parentNode) {
655 //console.warn('StylesController::getMatchingRules - Un-attached element queried');
656 return [];
657 }
658
650 try { 659 try {
651 mappedRules = nj.toArray(win.getMatchedCSSRules(element)).map(function(rule) { 660 matchedRules = win.getMatchedCSSRules(element);
661
662 if(!matchedRules) {
663 //console.warn('StylesController::getMatchingRules - matched rules are null');
664 return [];
665 }
666
667 mappedRules = nj.toArray(matchedRules).map(function(rule) {
652 return this._getRuleWithCSSText(rule.cssText, doc); 668 return this._getRuleWithCSSText(rule.cssText, doc);
653 }, this); 669 }, this);
654 670
655 rules = mappedRules.filter(function(rule) { 671 rules = mappedRules.filter(function(rule) {
672 if(!rule) { return false; }
673
656 //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, 674 //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet,
657 //// or only use rules for other stylesheets 675 //// or only use rules for other stylesheets
658 676
@@ -673,7 +691,8 @@ var stylesController = exports.StylesController = Montage.create(Component, {
673 }, this); 691 }, this);
674 692
675 } catch(ERROR) { 693 } catch(ERROR) {
676 console.warn('StylesController::getMatchingRules - Un-attached element queried.'); 694 //console.warn('StylesController::getMatchingRules - getMatchedCSSRules Exception.');
695 return [];
677 } 696 }
678 ///// Function for sorting by specificity values 697 ///// Function for sorting by specificity values
679 function sorter(ruleA, ruleB) { 698 function sorter(ruleA, ruleB) {
@@ -775,7 +794,7 @@ var stylesController = exports.StylesController = Montage.create(Component, {
775 var a = this._getMostSpecificSelectorForElement(element, rule1[this.CONST.SPECIFICITY_KEY]), 794 var a = this._getMostSpecificSelectorForElement(element, rule1[this.CONST.SPECIFICITY_KEY]),
776 b = this._getMostSpecificSelectorForElement(element, rule2[this.CONST.SPECIFICITY_KEY]), 795 b = this._getMostSpecificSelectorForElement(element, rule2[this.CONST.SPECIFICITY_KEY]),
777 win = element.ownerDocument.defaultView, 796 win = element.ownerDocument.defaultView,
778 order; 797 order, sheetAIndex, sheetBIndex, ruleAIndex, ruleBIndex;
779 798
780 order = this.compareSpecificity(a.specificity, b.specificity); 799 order = this.compareSpecificity(a.specificity, b.specificity);
781 800
@@ -786,9 +805,9 @@ var stylesController = exports.StylesController = Montage.create(Component, {
786 /// If tied again (same sheet), determine which is further down in the sheet 805 /// If tied again (same sheet), determine which is further down in the sheet
787 if(sheetAIndex === sheetBIndex) { 806 if(sheetAIndex === sheetBIndex) {
788 ruleAIndex = this.getRuleIndex(rule1); ruleBIndex = this.getRuleIndex(rule2); 807 ruleAIndex = this.getRuleIndex(rule1); ruleBIndex = this.getRuleIndex(rule2);
789 return ruleAIndex < ruleBIndex ? 1 : (ruleAIndex > ruleBIndex) ? -1 : 0; 808 return ruleAIndex < ruleBIndex ? false : (ruleAIndex > ruleBIndex) ? true : false;
790 } else { 809 } else {
791 return sheetAIndex < sheetBIndex ? 1 : (sheetAIndex > sheetBIndex) ? -1 : 0; 810 return sheetAIndex < sheetBIndex ? false : (sheetAIndex > sheetBIndex) ? true : false;
792 } 811 }
793 } 812 }
794 813
@@ -1437,11 +1456,11 @@ var stylesController = exports.StylesController = Montage.create(Component, {
1437 1456
1438 ///// Dispatch modified event 1457 ///// Dispatch modified event
1439 NJevent('styleSheetModified', eventData); 1458 NJevent('styleSheetModified', eventData);
1459 this.currentDocument.model.needsSave = true;
1440 1460
1441 ///// If the sheet doesn't already exist in the list of modified 1461 ///// If the sheet doesn't already exist in the list of modified
1442 ///// sheets, dispatch dirty event and add the sheet to the list 1462 ///// sheets, dispatch dirty event and add the sheet to the list
1443 if(sheetSearch.length === 0) { 1463 if(sheetSearch.length === 0) {
1444 this.currentDocument.model.needsSave = true;
1445 this.dirtyStyleSheets.push({ 1464 this.dirtyStyleSheets.push({
1446 document : sheet.ownerNode.ownerDocument, 1465 document : sheet.ownerNode.ownerDocument,
1447 stylesheet : sheet 1466 stylesheet : sheet