aboutsummaryrefslogtreecommitdiff
path: root/js/panels/css-panel/declaration.reel/declaration.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/panels/css-panel/declaration.reel/declaration.js')
-rw-r--r--js/panels/css-panel/declaration.reel/declaration.js192
1 files changed, 192 insertions, 0 deletions
diff --git a/js/panels/css-panel/declaration.reel/declaration.js b/js/panels/css-panel/declaration.reel/declaration.js
new file mode 100644
index 00000000..873d2ce4
--- /dev/null
+++ b/js/panels/css-panel/declaration.reel/declaration.js
@@ -0,0 +1,192 @@
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 ShorthandProps = require("js/panels/CSSPanel/css-shorthand-map");
10
11exports.Declaration = Montage.create(Component, {
12 focusDelegate : {
13 value: null
14 },
15 includeEmptyStyle : {
16 value: true
17 },
18 templateDidLoad : {
19 value: function() {
20 console.log("declaration - template did load");
21
22 if(this.focusDelegate) {
23 this.treeController.delegate = this.focusDelegate;
24 }
25 }
26 },
27 prepareForDraw : {
28 value: function(e) {
29 console.log("Declaration :: prepare for draw");
30 this._element.addEventListener('drop', this, false);
31 this.element.addEventListener('dragenter', this, false);
32 this.element.addEventListener('dragleave', this, false);
33 }
34 },
35 _declaration: {
36 value: null
37 },
38 declaration: {
39 get: function() {
40 return this._declaration;
41 },
42 set: function(dec) {
43 this._declaration = dec;
44
45 ///// creates data structure to use with tree component
46 this.buildStyleTree();
47
48 if(this.includeEmptyStyle) {
49 this.styleTree.properties.push({
50 "name": "property",
51 "value" : "value",
52 "isEmpty": true
53 });
54 }
55//debugger;
56 this.needsDraw = true;
57 }
58 },
59
60 buildStyleTree : {
61 value: function() {
62 var styles = Array.prototype.slice.call(this._declaration).sort();
63 this.styleTree = {
64 properties : styles.map(this.styleTreeMapper, this)
65 };
66 }
67 },
68 styleTreeMapper : {
69 value: function arrayToTreeMapper(property, i, styleArray) {
70 var shorthands = ShorthandProps.CSS_SHORTHAND_MAP[property],
71 subProps, hasAll;
72
73 ///// Is this a sub property of a shorthand property?
74 if(shorthands) {
75 //debugger;
76 ///// Yes.
77 ///// Now, are all sub properties in the declaration?
78 subProps = ShorthandProps.CSS_SHORTHAND_TO_SUBPROP_MAP[shorthands[0]];
79 hasAll = subProps.every(function(subProp) {
80 return styleArray.indexOf(subProp) !== -1;
81 });
82
83 if(hasAll) {
84 ///// It has all sub properties
85 ///// Let's return a tree branch and remove the
86 ///// sub properties from the flat array
87
88 this._removeItemsFromArray(styleArray, subProps);
89
90 return {
91 name: shorthands[0],
92 value: this._declaration.getPropertyValue(shorthands[0]),
93 properties: subProps.map(function(p, i, array) {
94 return {
95 name: p,
96 value: this._declaration.getPropertyValue(p)
97 };
98 }, this)
99 };
100 }
101 }
102
103
104 return {
105 name: property,
106 value: this._declaration.getPropertyValue(property)
107 };
108 }
109 },
110 _removeItemsFromArray : {
111 value: function(array, items) {
112 items.forEach(function(item) {
113 var index = array.indexOf(item);
114 array.splice(index, 1);
115 }, this);
116 }
117 },
118 styleTree : {
119 value: {
120 "properties" : []
121 },
122 distinct: true
123 },
124
125 addNewStyleAfter : {
126 value: function(style) {
127 //this.treeController.branchControllers[0].addObjects({
128 foo1 = style.parentComponent.parentComponent;
129 style.parentComponent.parentComponent.contentController.addObjects({
130 name: 'property',
131 value: 'value',
132 isEmpty: true,
133 treeNodeType: 'leaf'
134 });
135 style.parentComponent.parentComponent.needsDraw = true;
136 }
137 },
138
139 /* drag/drop events */
140 handleDrop : {
141 value: function(e) {
142 console.log('dropped');
143 }
144 },
145 handleDragenter : {
146 value: function(e) {
147 console.log("dec - drag enter");
148 this.element.classList.add("drag-over");
149 }
150 },
151 handleDragleave : {
152 value: function(e) {
153 if(this.element === e._event.toElement || this._containsElement(e._event.toElement)) {
154 //// Dragged-over element is inside of component element
155 //// I.e. it's not really a "drag leave"
156 e.stopPropagation();
157 e.preventDefault();
158 return false;
159 }
160
161 console.log("DECLARATION - ELEMENT NOT IN DEC", e._event.toElement);
162
163 //console.log("dec - drag leave");
164 this.element.classList.remove("drag-over");
165 }
166 },
167
168 draw: {
169 value: function() {
170 if(this._declaration) {
171
172 }
173 }
174 },
175
176 _containsElement : {
177 value: function(innerElement) {
178 var isInComponent = false,
179 parent = innerElement.parentNode;
180
181 while (parent !== document) {
182 if(parent === this.element) {
183 isInComponent = true;
184 break;
185 }
186 parent = parent.parentNode;
187 }
188
189 return isInComponent;
190 }
191 }
192}); \ No newline at end of file