diff options
author | Eric Guzman | 2012-05-08 13:26:36 -0700 |
---|---|---|
committer | Eric Guzman | 2012-05-08 13:26:36 -0700 |
commit | eb80f8a610100f908b5cb9ffc65bfa94f8a23c21 (patch) | |
tree | 5f9d1f17e532d68019eafc69e82b9228216aac95 /js/panels/css-panel/style-declaration.reel/style-declaration.js | |
parent | af4dac82d2e76fe90191d6c085740d855bf961f3 (diff) | |
download | ninja-eb80f8a610100f908b5cb9ffc65bfa94f8a23c21.tar.gz |
CSS Panel - Create non-tree declaration (optimized). And add updating functionality.
Diffstat (limited to 'js/panels/css-panel/style-declaration.reel/style-declaration.js')
-rw-r--r-- | js/panels/css-panel/style-declaration.reel/style-declaration.js | 261 |
1 files changed, 261 insertions, 0 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 new file mode 100644 index 00000000..80d8ff7b --- /dev/null +++ b/js/panels/css-panel/style-declaration.reel/style-declaration.js | |||
@@ -0,0 +1,261 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage/core/core").Montage, | ||
8 | Component = require("montage/ui/component").Component, | ||
9 | ShorthandProps = require("js/panels/CSSPanel/css-shorthand-map"); | ||
10 | |||
11 | exports.StyleDeclaration = Montage.create(Component, { | ||
12 | cssText : { | ||
13 | value: null | ||
14 | }, | ||
15 | focusDelegate : { | ||
16 | value: null | ||
17 | }, | ||
18 | includeEmptyStyle : { | ||
19 | value: true | ||
20 | }, | ||
21 | styles : { | ||
22 | value: [], | ||
23 | distinct: true | ||
24 | }, | ||
25 | |||
26 | templateDidLoad : { | ||
27 | value: function() { | ||
28 | console.log("Style declaration - template did load"); | ||
29 | |||
30 | if(this.focusDelegate) { | ||
31 | //this.treeController.delegate = this.focusDelegate; | ||
32 | this.styleComponent.delegate = this.focusDelegate; | ||
33 | } | ||
34 | } | ||
35 | }, | ||
36 | prepareForDraw : { | ||
37 | value: function(e) { | ||
38 | console.log("Style Declaration :: prepare for draw"); | ||
39 | this._element.addEventListener('drop', this, false); | ||
40 | this.element.addEventListener('dragenter', this, false); | ||
41 | this.element.addEventListener('dragleave', this, false); | ||
42 | } | ||
43 | }, | ||
44 | _declaration: { | ||
45 | value: null | ||
46 | }, | ||
47 | declaration: { | ||
48 | get: function() { | ||
49 | return this._declaration; | ||
50 | }, | ||
51 | set: function(dec) { | ||
52 | if(this._declaration) { | ||
53 | this.arrayController.removeObjects(this.styles); | ||
54 | } | ||
55 | console.log("dec being set", this); | ||
56 | this._declaration = dec; | ||
57 | |||
58 | this.cssText = dec.cssText; | ||
59 | |||
60 | Array.prototype.slice.call(dec).forEach(function(prop, index) { | ||
61 | this.styles.push({ | ||
62 | name: prop, | ||
63 | value: dec.getPropertyValue(prop) | ||
64 | }); | ||
65 | |||
66 | }, this); | ||
67 | |||
68 | if(this.includeEmptyStyle) { | ||
69 | this.styles.push({ | ||
70 | "name": "property", | ||
71 | "value" : "value", | ||
72 | "isEmpty": true | ||
73 | }); | ||
74 | } | ||
75 | ///// creates data structure to use with tree component | ||
76 | //this.buildStyleTree(); | ||
77 | |||
78 | // if(this.includeEmptyStyle) { | ||
79 | // this.styleTree.properties.push({ | ||
80 | // "name": "property", | ||
81 | // "value" : "value", | ||
82 | // "isEmpty": true | ||
83 | // }); | ||
84 | // } | ||
85 | |||
86 | this.needsDraw = true; | ||
87 | } | ||
88 | }, | ||
89 | |||
90 | update : { | ||
91 | value: function() { | ||
92 | if(this.declaration.cssText !== this.cssText) { | ||
93 | ///// Needs update | ||
94 | //debugger; | ||
95 | |||
96 | this.styles = null; | ||
97 | this.styles = []; | ||
98 | |||
99 | Array.prototype.slice.call(this.declaration).forEach(function(prop, index) { | ||
100 | this.styles.push({ | ||
101 | name: prop, | ||
102 | value: this.declaration.getPropertyValue(prop) | ||
103 | }); | ||
104 | |||
105 | }, this); | ||
106 | |||
107 | if(this.includeEmptyStyle) { | ||
108 | this.styles.push({ | ||
109 | "name": "property", | ||
110 | "value" : "value", | ||
111 | "isEmpty": true | ||
112 | }); | ||
113 | } | ||
114 | //debugger; | ||
115 | this.needsDraw = true; | ||
116 | } | ||
117 | } | ||
118 | }, | ||
119 | |||
120 | // buildStyleTree : { | ||
121 | // value: function() { | ||
122 | // var styles = Array.prototype.slice.call(this._declaration).sort(); | ||
123 | // this.styleTree = { | ||
124 | // properties : styles.map(this.styleTreeMapper, this) | ||
125 | // }; | ||
126 | // } | ||
127 | // }, | ||
128 | styleTreeMapper : { | ||
129 | value: function arrayToTreeMapper(property, i, styleArray) { | ||
130 | var shorthands = ShorthandProps.CSS_SHORTHAND_MAP[property], | ||
131 | subProps, hasAll; | ||
132 | |||
133 | ///// Is this a sub property of a shorthand property? | ||
134 | if(shorthands) { | ||
135 | //debugger; | ||
136 | ///// Yes. | ||
137 | ///// Now, are all sub properties in the declaration? | ||
138 | subProps = ShorthandProps.CSS_SHORTHAND_TO_SUBPROP_MAP[shorthands[0]]; | ||
139 | hasAll = subProps.every(function(subProp) { | ||
140 | return styleArray.indexOf(subProp) !== -1; | ||
141 | }); | ||
142 | |||
143 | if(hasAll) { | ||
144 | ///// It has all sub properties | ||
145 | ///// Let's return a tree branch and remove the | ||
146 | ///// sub properties from the flat array | ||
147 | |||
148 | this._removeItemsFromArray(styleArray, subProps); | ||
149 | |||
150 | return { | ||
151 | name: shorthands[0], | ||
152 | value: this._declaration.getPropertyValue(shorthands[0]), | ||
153 | properties: subProps.map(function(p, i, array) { | ||
154 | return { | ||
155 | name: p, | ||
156 | value: this._declaration.getPropertyValue(p) | ||
157 | }; | ||
158 | }, this) | ||
159 | }; | ||
160 | } | ||
161 | } | ||
162 | |||
163 | |||
164 | return { | ||
165 | name: property, | ||
166 | value: this._declaration.getPropertyValue(property) | ||
167 | }; | ||
168 | } | ||
169 | }, | ||
170 | _removeItemsFromArray : { | ||
171 | value: function(array, items) { | ||
172 | items.forEach(function(item) { | ||
173 | var index = array.indexOf(item); | ||
174 | array.splice(index, 1); | ||
175 | }, this); | ||
176 | } | ||
177 | }, | ||
178 | styleTree : { | ||
179 | value: { | ||
180 | "properties" : [] | ||
181 | }, | ||
182 | distinct: true | ||
183 | }, | ||
184 | |||
185 | // addNewStyleAfter : { | ||
186 | // value: function(style) { | ||
187 | // style.parentComponent.parentComponent.contentController.addObjects({ | ||
188 | // name: 'property', | ||
189 | // value: 'value', | ||
190 | // isEmpty: true, | ||
191 | // treeNodeType: 'leaf' | ||
192 | // }); | ||
193 | // style.parentComponent.parentComponent.needsDraw = true; | ||
194 | // } | ||
195 | // }, | ||
196 | |||
197 | addNewStyle : { | ||
198 | value: function() { | ||
199 | this.styles.push({ | ||
200 | "name": "property", | ||
201 | "value" : "value", | ||
202 | "isEmpty": true | ||
203 | }); | ||
204 | } | ||
205 | }, | ||
206 | |||