diff options
Diffstat (limited to 'js/panels/css-panel/style.reel/style.js')
-rw-r--r-- | js/panels/css-panel/style.reel/style.js | 351 |
1 files changed, 351 insertions, 0 deletions
diff --git a/js/panels/css-panel/style.reel/style.js b/js/panels/css-panel/style.reel/style.js new file mode 100644 index 00000000..b86be0ae --- /dev/null +++ b/js/panels/css-panel/style.reel/style.js | |||
@@ -0,0 +1,351 @@ | |||
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 | TreeNode = require("js/components/treeview/tree-node").TreeNode; | ||
9 | |||
10 | exports.Style = Montage.create(TreeNode, { | ||
11 | delegate : { | ||
12 | value: null | ||
13 | }, | ||
14 | disabledClass : { | ||
15 | value: 'style-item-disabled' | ||
16 | }, | ||
17 | editingStyleClass : { | ||
18 | value: 'edit-style-item' | ||
19 | }, | ||
20 | editNewEmptyClass : { | ||
21 | value: 'edit-empty-style' | ||
22 | }, | ||
23 | invalidStyleClass : { | ||
24 | value: "style-item-invalid" | ||
25 | }, | ||
26 | propertyText : { | ||
27 | value: "property" | ||
28 | }, | ||
29 | _valueText : { | ||
30 | value: "value" | ||
31 | }, | ||
32 | valueText : { | ||
33 | get: function() { | ||
34 | return this._valueText; | ||
35 | }, | ||
36 | set: function(text) { | ||
37 | this._valueText = text; | ||
38 | this.units = this.getUnits(text); | ||
39 | } | ||
40 | }, | ||
41 | _priority: { value: "", distinct: true }, | ||
42 | priority: { | ||
43 | get: function() { | ||
44 | return this._priority; | ||
45 | }, | ||
46 | set: function(value) { | ||
47 | this._priority = value; | ||
48 | } | ||
49 | }, | ||
50 | |||
51 | getUnits : { | ||
52 | value: function(val) { | ||
53 | if(val.split(/\s/).length > 1) { | ||
54 | return false; | ||
55 | } else if(/(px|em|pt|in|cm|mm|ex|pc|%)$/.test(val)) { | ||
56 | return val.replace(/^.*(px|em|pt|in|cm|mm|ex|pc|%).*/, '$1'); | ||
57 | } | ||
58 | return null; | ||
59 | } | ||
60 | }, | ||
61 | |||
62 | _enabled : { value: true, distinct: true }, | ||
63 | enabled : { | ||
64 | get: function() { | ||
65 | return this._enabled; | ||
66 | }, | ||
67 | set: function(value) { | ||
68 | this._enabled = value; | ||
69 | this.delegate.handleStyleToggle(this.getRule(), this._enabled, this); | ||
70 | this.needsDraw = true; | ||
71 | } | ||
72 | }, | ||
73 | |||
74 | _empty : { value: null }, | ||
75 | empty : { | ||
76 | get: function() { | ||
77 | return this._empty; | ||
78 | }, | ||
79 | set: function(isEmpty) { | ||
80 | if(this._empty === isEmpty) { return false; } | ||
81 | this._empty = isEmpty; | ||
82 | this.needsDraw = true; | ||
83 | } | ||
84 | }, | ||
85 | |||
86 | dirty : { | ||
87 | get: function() { | ||
88 | return this.propertyField.isDirty || this.valueField.isDirty; | ||
89 | }, | ||
90 | set: function(value) { | ||
91 | return false; | ||
92 | } | ||
93 | }, | ||
94 | |||
95 | _invalid: { value: null }, | ||
96 | invalid : { | ||
97 | get: function() { return this._invalid; }, | ||
98 | set: function(value) { | ||
99 | this._invalid = value; | ||
100 | this.needsDraw = true; | ||
101 | } | ||
102 | }, | ||
103 | |||
104 | _editing : { value : null }, | ||
105 | editing : { | ||
106 | get: function() { | ||
107 | return this._editing; | ||
108 | }, | ||
109 | set: function(value) { | ||
110 | if(this._editing === value) { return false; } | ||
111 | |||
112 | this._editing = value; | ||
113 | this.needsDraw = true; | ||
114 | } | ||
115 | }, | ||
116 | |||
117 | _editingNewStyle : { | ||
118 | value: null | ||
119 | }, | ||
120 | editingNewStyle : { | ||
121 | get: function() { | ||
122 | return this._editingNewStyle; | ||
123 | }, | ||
124 | set: function(value) { | ||
125 | if(this._editingNewStyle === value) { | ||
126 | return false; | ||
127 | } | ||
128 | |||
129 | this._editingNewStyle = value; | ||
130 | this.needsDraw = true; | ||
131 | } | ||
132 | }, | ||
133 | |||
134 | getRule : { | ||
135 | value: function() { | ||
136 | return this.treeView.parentComponent.declaration.parentRule; | ||
137 | } | ||
138 | }, | ||
139 | |||
140 | handleEvent : { | ||
141 | value: function(e) { | ||
142 | console.log(e); | ||
143 | } | ||
144 | }, | ||
145 | |||
146 | handleDragstart : { | ||
147 | value: function(e) { | ||
148 | e.dataTransfer.effectAllowed = 'move'; | ||
149 | e.dataTransfer.setData('Text', 'my styles, baby!'); | ||
150 | this.element.classList.add("dragged"); | ||
151 | } | ||
152 | }, | ||
153 | |||
154 | handleDragend : { | ||
155 | value: function(e) { | ||
156 | this.element.classList.remove("dragging"); | ||
157 | this.element.classList.remove("dragged"); | ||
158 | } | ||
159 | }, | ||
160 | handleDrag : { | ||
161 | value: function(e) { | ||
162 | this.element.classList.add("dragging"); | ||
163 | } | ||
164 | }, | ||
165 | handleDrop : { | ||
166 | value: function(e) { | ||
167 | this.element.classList.remove("drag-enter"); | ||
168 | } | ||
169 | }, | ||
170 | |||
171 | handleWebkitTransitionEnd : { | ||
172 | value: function(e) { | ||
173 | console.log("trans end"); | ||
174 | } | ||
175 | }, | ||
176 | handleClick : { | ||
177 | value: function(e) { | ||
178 | console.log("handle Add button click"); | ||
179 | this.propertyField.start(); | ||
180 | //this.editingNewStyle = true; | ||
181 | this.editingNewStyle = this.editing = true; | ||
182 | } | ||
183 | }, | ||
184 | |||
185 | handleStart : { | ||
186 | value: function(e) { | ||
187 | this.editing = true; | ||
188 | } | ||
189 | }, | ||
190 | |||
191 | //// Handler for both hintable components | ||
192 | handleStop : { | ||
193 | value: function(e) { | ||
194 | var event = e; | ||
195 | ///// Function to determine if an empty (new) style should return | ||
196 | ///// to showing the add button, i.e. the fields were not clicked | ||
197 | function fieldsClicked() { | ||
198 | var clicked; | ||
199 | if(e._event.detail.originalEventType === 'mousedown') { | ||
200 | clicked = e._event.detail.originalEvent.target; | ||
201 | return clicked === this.propertyField.element || clicked === this.valueField.element; | ||
202 | } | ||
203 | return false; | ||
204 | } | ||
205 | |||
206 | this.editing = false; | ||
207 | |||
208 | if(this.sourceObject.isEmpty && !this.dirty && !fieldsClicked.bind(this)()) { | ||
209 | ///// Show add button | ||
210 | this.editingNewStyle = false; | ||
211 | } | ||
212 | |||
213 | this.delegate.handleStyleStop(e); | ||
214 | } | ||
215 | }, | ||
216 | |||
217 | handlePropertyChange : { | ||
218 | value: function(e) { | ||
219 | var property = this.propertyField.value, | ||
220 | oldProperty = this.propertyField._preEditValue, | ||
221 | value = this.valueField.value, | ||
222 | rule = this.getRule(); | ||
223 | |||
224 | this.delegate.handlePropertyChange(rule, property, value, oldProperty, this); | ||
225 | } | ||
226 | }, | ||
227 | handleValueChange : { | ||
228 | value: function(e) { | ||
229 | var property = this.propertyField.value, | ||
230 | value = this.valueField.value, | ||
231 | rule = this.getRule(); | ||
232 | |||
233 | this.delegate.handleValueChange(rule, property, value, this); | ||
234 | } | ||
235 | }, | ||
236 | |||
237 | handlePropertyDirty : { | ||