aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/styles-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/styles-controller.js')
-rw-r--r--js/controllers/styles-controller.js77
1 files changed, 71 insertions, 6 deletions
diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js
index 21024125..44e0e798 100644
--- a/js/controllers/styles-controller.js
+++ b/js/controllers/styles-controller.js
@@ -175,10 +175,16 @@ var stylesController = exports.StylesController = Montage.create(Component, {
175 } 175 }
176 176
177 stylesheet.insertRule(ruleText, index); 177 stylesheet.insertRule(ruleText, index);
178
179 this.styleSheetModified(stylesheet);
178 180
179 rule = stylesheet.rules[index]; 181 rule = stylesheet.rules[index];
180 182
181 ///// attach specificity to rule object 183 ///// attach specificity to rule object
184 // if rule is css keyframes, return rule and don't attach specificity
185 if (rule instanceof WebKitCSSKeyframesRule) {
186 return rule;
187 }
182 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); 188 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText);
183 189
184 ///// return the rule we just inserted 190 ///// return the rule we just inserted
@@ -283,6 +289,8 @@ var stylesController = exports.StylesController = Montage.create(Component, {
283 sheet.deleteRule(index); 289 sheet.deleteRule(index);
284 } 290 }
285 291
292 this.styleSheetModified(sheet);
293
286 return index; 294 return index;
287 } 295 }
288 }, 296 },
@@ -531,6 +539,9 @@ var stylesController = exports.StylesController = Montage.create(Component, {
531 value : function(rule, selector) { 539 value : function(rule, selector) {
532 rule.selectorText = selector; 540 rule.selectorText = selector;
533 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(selector); 541 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(selector);
542
543 this.styleSheetModified(rule.parentStyleSheet);
544
534 return rule; 545 return rule;
535 } 546 }
536 }, 547 },
@@ -780,6 +791,8 @@ var stylesController = exports.StylesController = Montage.create(Component, {
780 ///// method to apply/test the new value 791 ///// method to apply/test the new value
781 dec.setProperty(property, value, priority); 792 dec.setProperty(property, value, priority);
782 793
794 this.styleSheetModified(rule.parentStyleSheet);
795
783 ///// Return browser value for value we just set 796 ///// Return browser value for value we just set
784 return dec.getPropertyValue(property); 797 return dec.getPropertyValue(property);
785 } 798 }
@@ -838,7 +851,10 @@ var stylesController = exports.StylesController = Montage.create(Component, {
838 851
839 deleteStyle : { 852 deleteStyle : {
840 value : function(rule, property) { 853 value : function(rule, property) {
854 this.styleSheetModified(rule.parentStyleSheet);
855
841 rule.style.removeProperty(property); 856 rule.style.removeProperty(property);
857
842 return rule; 858 return rule;
843 } 859 }
844 }, 860 },
@@ -1070,9 +1086,10 @@ var stylesController = exports.StylesController = Montage.create(Component, {
1070 1086
1071 createStylesheet : { 1087 createStylesheet : {
1072 value: function(id, document) { 1088 value: function(id, document) {
1073 var doc = document || this._activeDocument; 1089 var doc = document || this._activeDocument._document,
1090 sheetElement, sheet;
1074 1091
1075 sheet = nj.make('style', { 1092 sheetElement = nj.make('style', {
1076 type : 'text/css', 1093 type : 'text/css',
1077 rel : 'stylesheet', 1094 rel : 'stylesheet',
1078 id : id || "", 1095 id : id || "",
@@ -1080,9 +1097,12 @@ var stylesController = exports.StylesController = Montage.create(Component, {
1080 title : 'Temp' 1097 title : 'Temp'
1081 }); 1098 });
1082 1099
1083 doc.head.appendChild(sheet); 1100 doc.head.appendChild(sheetElement);
1084 1101 sheet = this.getSheetFromElement(sheetElement, doc);
1085 return this.getSheetFromElement(sheet, doc); 1102
1103 this.styleSheetModified(sheet);
1104
1105 return sheet;
1086 } 1106 }
1087 }, 1107 },
1088 1108
@@ -1103,7 +1123,52 @@ var stylesController = exports.StylesController = Montage.create(Component, {
1103 1123
1104 } 1124 }
1105 }, 1125 },
1106 1126
1127 ///// Style Sheet Modified
1128 ///// Method to call whenever a stylesheet change is made
1129 ///// Dispatches an event, and keeps list of dirty style sheets
1130
1131 styleSheetModified : {
1132 value: function(sheet, eventData) {
1133 var sheetSearch = this.dirtyStyleSheets.filter(function(sheetObj) {
1134 return sheetObj.stylesheet === sheet;
1135 });
1136
1137 ///// If the sheet doesn't already exist in the list of modified
1138 ///// sheets, dispatch dirty event and add the sheet to the list
1139 if(sheetSearch.length === 0) {
1140 NJevent('styleSheetDirty', eventData);
1141 this.dirtyStyleSheets.push({
1142 document : sheet.ownerNode.ownerDocument,
1143 stylesheet : sheet
1144 });
1145 }
1146 }
1147 },
1148
1149 ///// Dirty Style Sheets
1150 ///// List of modified style sheets
1151
1152 dirtyStyleSheets : {
1153 value : []
1154 },
1155
1156 ///// Clear Dirty Style Sheets
1157 ///// Refreshes the list of dirty style sheets
1158 ///// If optional document object is supplied, only the styles sheets
1159 ///// of a particular document are cleared
1160 ///// Useful to call after a "Save" or "Save All" event
1161
1162 clearDirtyStyleSheets : {
1163 value: function(doc) {
1164 if(!doc) {
1165 this.dirtyStyleSheets = null;
1166 this.dirtyStyleSheets = [];
1167 }
1168
1169 }
1170 },
1171
1107 /* ----------------- Utils ------------------- */ 1172 /* ----------------- Utils ------------------- */
1108 1173
1109 _generateRandomAlphaNumeric : { 1174 _generateRandomAlphaNumeric : {