aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Guzman2012-02-08 10:39:17 -0800
committerEric Guzman2012-02-08 10:39:17 -0800
commit9154cff2ce10aae54d9a7bd37a9d8b5578b0e297 (patch)
tree8491f9bc1884de87486131886175a5cb2f750b83
parent8950b342d1eda8bfa195372e1c17363a409651cd (diff)
downloadninja-9154cff2ce10aae54d9a7bd37a9d8b5578b0e297.tar.gz
Styles Controller - Added array of dirty stylesheets and event dispatch when a sheet is dirtied.
-rw-r--r--js/controllers/styles-controller.js73
1 files changed, 67 insertions, 6 deletions
diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js
index 21024125..011caec5 100644
--- a/js/controllers/styles-controller.js
+++ b/js/controllers/styles-controller.js
@@ -175,6 +175,8 @@ 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
@@ -283,6 +285,8 @@ var stylesController = exports.StylesController = Montage.create(Component, {
283 sheet.deleteRule(index); 285 sheet.deleteRule(index);
284 } 286 }
285 287
288 this.styleSheetModified(sheet);
289
286 return index; 290 return index;
287 } 291 }
288 }, 292 },
@@ -531,6 +535,9 @@ var stylesController = exports.StylesController = Montage.create(Component, {
531 value : function(rule, selector) { 535 value : function(rule, selector) {
532 rule.selectorText = selector; 536 rule.selectorText = selector;
533 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(selector); 537 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(selector);
538
539 this.styleSheetModified(rule.parentStyleSheet);
540
534 return rule; 541 return rule;
535 } 542 }
536 }, 543 },
@@ -780,6 +787,8 @@ var stylesController = exports.StylesController = Montage.create(Component, {
780 ///// method to apply/test the new value 787 ///// method to apply/test the new value
781 dec.setProperty(property, value, priority); 788 dec.setProperty(property, value, priority);
782 789
790 this.styleSheetModified(rule.parentStyleSheet);
791
783 ///// Return browser value for value we just set 792 ///// Return browser value for value we just set
784 return dec.getPropertyValue(property); 793 return dec.getPropertyValue(property);
785 } 794 }
@@ -838,7 +847,10 @@ var stylesController = exports.StylesController = Montage.create(Component, {
838 847
839 deleteStyle : { 848 deleteStyle : {
840 value : function(rule, property) { 849 value : function(rule, property) {
850 this.styleSheetModified(rule.parentStyleSheet);
851
841 rule.style.removeProperty(property); 852 rule.style.removeProperty(property);
853
842 return rule; 854 return rule;
843 } 855 }
844 }, 856 },
@@ -1070,9 +1082,10 @@ var stylesController = exports.StylesController = Montage.create(Component, {
1070 1082
1071 createStylesheet : { 1083 createStylesheet : {
1072 value: function(id, document) { 1084 value: function(id, document) {
1073 var doc = document || this._activeDocument; 1085 var doc = document || this._activeDocument._document,
1086 sheetElement, sheet;
1074 1087
1075 sheet = nj.make('style', { 1088 sheetElement = nj.make('style', {
1076 type : 'text/css', 1089 type : 'text/css',
1077 rel : 'stylesheet', 1090 rel : 'stylesheet',
1078 id : id || "", 1091 id : id || "",
@@ -1080,9 +1093,12 @@ var stylesController = exports.StylesController = Montage.create(Component, {
1080 title : 'Temp' 1093 title : 'Temp'
1081 }); 1094 });
1082 1095
1083 doc.head.appendChild(sheet); 1096 doc.head.appendChild(sheetElement);
1084 1097 sheet = this.getSheetFromElement(sheetElement, doc);
1085 return this.getSheetFromElement(sheet, doc); 1098
1099 this.styleSheetModified(sheet);
1100
1101 return sheet;
1086 } 1102 }
1087 }, 1103 },
1088 1104
@@ -1103,7 +1119,52 @@ var stylesController = exports.StylesController = Montage.create(Component, {
1103 1119
1104 } 1120 }
1105 }, 1121 },
1106 1122
1123 ///// Style Sheet Modified
1124 ///// Method to call whenever a stylesheet change is made
1125 ///// Dispatches an event, and keeps list of dirty style sheets
1126
1127 styleSheetModified : {
1128 value: function(sheet, eventData) {
1129 var sheetSearch = this.dirtyStyleSheets.filter(function(sheetObj) {
1130 return sheetObj.stylesheet === sheet;
1131 });
1132
1133 ///// If the sheet doesn't already exist in the list of modified
1134 ///// sheets, dispatch dirty event and add the sheet to the list
1135 if(sheetSearch.length === 0) {
1136 NJevent('styleSheetDirty', eventData);
1137 this.dirtyStyleSheets.push({
1138 document : sheet.ownerNode.ownerDocument,
1139 stylesheet : sheet
1140 });
1141 }
1142 }
1143 },
1144
1145 ///// Dirty Style Sheets
1146 ///// List of modified style sheets
1147
1148 dirtyStyleSheets : {
1149 value : []
1150 },
1151
1152 ///// Clear Dirty Style Sheets
1153 ///// Refreshes the list of dirty style sheets
1154 ///// If optional document object is supplied, only the styles sheets
1155 ///// of a particular document are cleared
1156 ///// Useful to call after a "Save" or "Save All" event
1157
1158 clearDirtyStyleSheets : {
1159 value: function(doc) {
1160 if(!doc) {
1161 this.dirtyStyleSheets = null;
1162 this.dirtyStyleSheets = [];
1163 }
1164
1165 }
1166 },
1167
1107 /* ----------------- Utils ------------------- */ 1168 /* ----------------- Utils ------------------- */
1108 1169
1109 _generateRandomAlphaNumeric : { 1170 _generateRandomAlphaNumeric : {