aboutsummaryrefslogtreecommitdiff
path: root/js/panels/css-panel
diff options
context:
space:
mode:
authorEric Guzman2012-05-22 09:27:25 -0700
committerEric Guzman2012-05-22 09:27:25 -0700
commit1f4d7643b484cab4258cda2bb8eefcc6a60452df (patch)
tree04e1616df883bf1ad999d07fa49f355fc71413a2 /js/panels/css-panel
parent6686f2f0bc3ea1b4f589409c78a99bd07a41e7c3 (diff)
downloadninja-1f4d7643b484cab4258cda2bb8eefcc6a60452df.tar.gz
CSS Style Declaration - Improve shorthand filtering
Diffstat (limited to 'js/panels/css-panel')
-rw-r--r--js/panels/css-panel/style-declaration.reel/style-declaration.js38
1 files changed, 19 insertions, 19 deletions
diff --git a/js/panels/css-panel/style-declaration.reel/style-declaration.js b/js/panels/css-panel/style-declaration.reel/style-declaration.js
index 711879ce..57cbdb63 100644
--- a/js/panels/css-panel/style-declaration.reel/style-declaration.js
+++ b/js/panels/css-panel/style-declaration.reel/style-declaration.js
@@ -84,8 +84,7 @@ exports.StyleDeclaration = Montage.create(Component, {
84 ///// Take snapshot of declaration 84 ///// Take snapshot of declaration
85 this.cssText = dec.cssText; 85 this.cssText = dec.cssText;
86 86
87 stylesArray = Array.prototype.slice.call(dec); 87 stylesArray = this.filterShorthands(Array.prototype.slice.call(dec));
88
89 stylesArray.forEach(function(prop, index) { 88 stylesArray.forEach(function(prop, index) {
90 this.styles.push({ 89 this.styles.push({
91 name: prop, 90 name: prop,
@@ -107,28 +106,32 @@ exports.StyleDeclaration = Montage.create(Component, {
107 } 106 }
108 }, 107 },
109 108
110 styleShorthander : { 109 filterShorthands : {
111 value: function(styles) { 110 value: function(styles) {
112 var shorthandsToAdd = [], 111 var shorthandsToAdd = [],
113 subProps, hasAll; 112 subProps, hasAll;
114 113
115 styles.forEach(function(property, index, styleArray) { 114 var stylesCopy = styles.map(function(style) {
116 var shorthands = ShorthandProps.CSS_SHORTHAND_MAP[property]; 115 return style;
116 });
117 117
118 if(!shorthands) { return false; } 118 stylesCopy.forEach(function(property, index) {
119 var shorthands = ShorthandProps.CSS_SHORTHAND_MAP[property];
120 if(shorthands) {
121 subProps = ShorthandProps.CSS_SHORTHAND_TO_SUBPROP_MAP[shorthands[0]];
119 122
120 var subProps = ShorthandProps.CSS_SHORTHAND_TO_SUBPROP_MAP[shorthands[0]], 123 hasAll = subProps.every(function(subProp) {
121 stylesArray = styleArray; 124 return styles.indexOf(subProp) !== -1;
125 });
122 126
123 hasAll = subProps.every(function(subProp) { 127 if(hasAll) {
124 return stylesArray.indexOf(subProp) !== -1; 128 for(var i = subProps.length-1; i>=0; i--) {
125 }); 129 styles.splice(styles.indexOf(subProps[i]), 1);
130 }
131 shorthandsToAdd.push(shorthands[0]);
132 }
126 133
127 if(hasAll) { 134 return true;
128 subProps.forEach(function(subProp) {
129 stylesArray.splice(stylesArray.indexOf(subProp), 1);
130 }, this);
131 shorthandsToAdd.push(shorthands[0]);
132 } 135 }
133 }, this); 136 }, this);
134 137
@@ -227,8 +230,6 @@ exports.StyleDeclaration = Montage.create(Component, {
227 isEmpty: false 230 isEmpty: false
228 }, prop; 231 }, prop;
229 232
230 console.log('adding "'+ property+'" with value "' + value + '"');
231
232 for(prop in data) { 233 for(prop in data) {
233 if(data.hasOwnProperty(prop)) { 234 if(data.hasOwnProperty(prop)) {
234 styleDescriptor[prop] = data[prop]; 235 styleDescriptor[prop] = data[prop];
@@ -244,7 +245,6 @@ exports.StyleDeclaration = Montage.create(Component, {
244 removeStyle : { 245 removeStyle : {
245 value: function(styleDescriptor) { 246 value: function(styleDescriptor) {
246 var styleDescriptorIndex = this.styles.indexOf(styleDescriptor); 247 var styleDescriptorIndex = this.styles.indexOf(styleDescriptor);
247console.log("removing style", styleDescriptor);
248 //this.styles.splice(styleDescriptorIndex, 1); 248 //this.styles.splice(styleDescriptorIndex, 1);
249 this.arrayController.removeObjects(styleDescriptor); 249 this.arrayController.removeObjects(styleDescriptor);
250 250