aboutsummaryrefslogtreecommitdiff
path: root/js/panels/css-panel/style.reel/style.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/panels/css-panel/style.reel/style.js')
-rw-r--r--js/panels/css-panel/style.reel/style.js178
1 files changed, 178 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..adf17a84
--- /dev/null
+++ b/js/panels/css-panel/style.reel/style.js
@@ -0,0 +1,178 @@
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 TreeNode = require("js/components/treeview/tree-node").TreeNode;
9
10exports.Style = Montage.create(TreeNode, {
11 disabledClass : {
12 value: 'style-item-disabled'
13 },
14 editNewEmptyClass : {
15 value: 'edit-empty-style'
16 },
17 propertyText : {
18 value: "property"
19 },
20 valueText : {
21 value: "value"
22 },
23
24 _enabled : { value: true, distinct: true },
25 enabled : {
26 get: function() {
27 return this._enabled;
28 },
29 set: function(value) {
30 this._enabled = value;
31 this.needsDraw = true;
32 }
33 },
34
35
36 dirty : {
37 get: function() {
38 return this.propertyField.isDirty || this.valueField.isDirty;
39 },
40 set: function(value) {
41
42 }
43 },
44
45 _editingNewStyle : {
46 value: null
47 },
48 editingNewStyle : {
49 get: function() {
50 return this._editingNewStyle;
51 },
52 set: function(value) {
53 this._editingNewStyle = value;
54 this.needsDraw = true;
55 }
56 },
57
58 handleEvent : {
59 value: function(e) {
60 console.log(e);
61 }
62 },
63
64 handleDragstart : {
65 value: function(e) {
66 e.dataTransfer.effectAllowed = 'move';
67 e.dataTransfer.setData('Text', 'my styles, baby!');
68 this.element.classList.add("dragged");
69 }
70 },
71
72 handleDragend : {
73 value: function(e) {
74 this.element.classList.remove("dragging");
75 this.element.classList.remove("dragged");
76 }
77 },
78 handleDrag : {
79 value: function(e) {
80 this.element.classList.add("dragging");
81 }
82 },
83 handleDrop : {
84 value: function(e) {
85 this.element.classList.remove("drag-enter");
86 }
87 },
88 handleSourceObjectSet: {
89 value: function() {
90 //debugger;
91 this.propertyText = this.sourceObject.name;
92 this.valueText = this.sourceObject.value;
93 }
94 },
95 handleWebkitTransitionEnd : {
96 value: function(e) {
97 console.log("trans end");
98 }
99 },
100 handleClick : {
101 value: function(e) {
102 console.log("handleAction");
103 this.editingNewStyle = true;
104 }
105 },
106
107 //// Handler for both hintable components
108 handleStop : {
109 value: function(e) {
110 var event = e;
111 ///// Function to determine if an empty (new) style should return
112 ///// to showing the add button, i.e. the fields were not clicked
113 function shouldStopEditing() {
114 var clicked;
115 if(e._event.detail.originalEventType === 'mousedown') {
116 clicked = e._event.detail.originalEvent.target;
117 return clicked !== this.propertyField.element && clicked !== this.valueField.element;
118 }
119 return
120 }
121
122 if(this.sourceObject.isEmpty && !this.dirty && shouldStopEditing.bind(this)()) {
123
124 this.editingNewStyle = false;
125 }
126 }
127 },
128 prepareForDraw : {
129 value: function() {
130 console.log("style's prepare for draw");
131 this.element.addEventListener('dragstart', this, false);
132 this.element.addEventListener('drag', this, false);
133 this.element.addEventListener('dragend', this, false);
134 this.element.addEventListener('drop', this, false);
135 this.element.addEventListener('webkitTransitionEnd', this, false);
136
137 if(this.sourceObject.isEmpty) {
138 this.element.draggable = false;
139 this.addStyleButton.addEventListener('click', this, false);
140 this.propertyField.addEventListener('stop', this, false);
141 this.valueField.addEventListener('stop', this, false);
142 } else {
143 this.element.removeChild(this.addStyleButton);
144 delete this.addStyleButton;
145 }
146 }
147 },
148
149 draw : {
150 value : function() {
151 //debugger;
152 if(this.sourceObject[this.labelKey]) {
153 this._labelText = this.sourceObject[this.labelKey];
154 } else {
155 console.log("Label key unknown");
156 }
157
158 if(this.sourceObject.isEmpty) {
159 this.element.classList.add('empty-css-style');
160 } else {
161 this.element.classList.remove('empty-css-style');
162 }
163
164 if(this._enabled) {
165 this.element.classList.remove(this.disabledClass);
166 } else {
167 this.element.classList.add(this.disabledClass);
168 }
169
170 if(this._editingNewStyle) {
171 this.propertyField.start();
172 this.element.classList.add(this.editNewEmptyClass);
173 } else {
174 this.element.classList.remove(this.editNewEmptyClass);
175 }
176 }
177 }
178}); \ No newline at end of file