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