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