diff options
Diffstat (limited to 'js/panels/css-panel/style.reel/style.js')
-rw-r--r-- | js/panels/css-panel/style.reel/style.js | 369 |
1 files changed, 369 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..a8939bc6 --- /dev/null +++ b/js/panels/css-panel/style.reel/style.js | |||
@@ -0,0 +1,369 @@ | |||
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 | remove : { | ||
135 | value: function() { | ||
136 | var branchController = this.parentComponent.parentComponent.contentController; | ||
137 | |||
138 | ///// Remove style property from declaration | ||
139 | this.treeView.parentComponent.declaration.removeProperty(this.propertyField._preEditValue); | ||
140 | |||
141 | ///// Remove data from branch controller and update UI | ||
142 | branchController.removeObjects(this.sourceObject); | ||
143 | } | ||
144 | }, | ||
145 | |||
146 | getRule : { | ||
147 | value: function() { | ||
148 | return this.treeView.parentComponent.declaration.parentRule; | ||
149 | } | ||
150 | }, | ||
151 | |||
152 | handleEvent : { | ||
153 | value: function(e) { | ||
154 | console.log(e); | ||
155 | } | ||
156 | }, | ||
157 | |||
158 | handleDragstart : { | ||
159 | value: function(e) { | ||
160 | e.dataTransfer.effectAllowed = 'move'; | ||
161 | e.dataTransfer.setData('Text', 'my styles, baby!'); | ||
162 | this.element.classList.add("dragged"); | ||
163 | } | ||
164 | }, | ||
165 | |||
166 | handleDragend : { | ||
167 | value: function(e) { | ||
168 | this.element.classList.remove("dragging"); | ||
169 | this.element.classList.remove("dragged"); | ||
170 | } | ||
171 | }, | ||
172 | handleDrag : { | ||
173 | value: function(e) { | ||
174 | this.element.classList.add("dragging"); | ||
175 | } | ||
176 | }, | ||
177 | handleDrop : { | ||
178 | value: function(e) { | ||
179 | this.element.classList.remove("drag-enter"); | ||
180 | } | ||
181 | }, | ||
182 | |||
183 | handleWebkitTransitionEnd : { | ||
184 | value: function(e) { | ||
185 | console.log("trans end"); | ||
186 | } | ||
187 | }, | ||
188 | handleClick : { | ||
189 | value: function(e) { | ||
190 | console.log("handle Add button click"); | ||
191 | this.propertyField.start(); | ||
192 | //this.editingNewStyle = true; | ||
193 | this.editingNewStyle = this.editing = true; | ||
194 | } | ||
195 | }, | ||
196 | |||
197 | handleStart : { | ||
198 | value: function(e) { | ||
199 | this.editing = true; | ||
200 | } | ||
201 | }, | ||
202 | |||
203 | //// Handler for both hintable components | ||
204 | handleStop : { | ||
205 | value: function(e) { | ||
206 | var event = e; | ||
207 | ///// Function to determine if an empty (new) style should return | ||
208 | ///// to showing the add button, i.e. the fields were not clicked | ||
209 | function fieldsClicked() { | ||
210 | var clicked; | ||
211 | if(e._event.detail.originalEventType === 'mousedown') { | ||
212 | clicked = e._event.detail.originalEvent.target; | ||
213 | return clicked === this.propertyField.element || clicked === this.valueField.element; | ||
214 | } | ||
215 | return false; | ||
216 | } | ||
217 | |||
218 | this.editing = false; | ||
219 | |||
220 | if(this.sourceObject.isEmpty && !this.dirty && !fieldsClicked.bind(this)()) { | ||
221 | ///// Show add button | ||
222 | this.editingNewStyle = false; | ||
223 | } | ||
224 | |||
225 | this.delegate.handleStyleStop(e); | ||
226 | } | ||
227 | }, | ||
228 | |||
229 | handlePropertyChange : { | ||
230 | value: function(e) { | ||
231 | var property = this.propertyField.value, | ||
232 | oldProperty = this.propertyField._preEditValue, | ||
233 | value = this.valueField.value, | ||
234 | rule = this.getRule(); | ||
235 | |||