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