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