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.js105
1 files changed, 105 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..34819df5
--- /dev/null
+++ b/js/panels/css-panel/declaration.reel/declaration.js
@@ -0,0 +1,105 @@
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 templateDidLoad : {
13 value: function() {
14 console.log("declaration - template did load");
15 }
16 },
17 _declaration: {
18 value: null
19 },
20 declaration: {
21 get: function() {
22 return this._declaration;
23 },
24 set: function(dec) {
25 this._declaration = dec;
26 console.log('here');
27 ///// creates data structure to use with tree component
28 this.buildStyleTree();
29 console.log('there');
30 this.needsDraw = true;
31 }
32 },
33
34 buildStyleTree : {
35 value: function() {
36 var styles = Array.prototype.slice.call(this._declaration).sort();
37 this.styleTree = {
38 properties : styles.map(this.styleTreeMapper, this)
39 };
40 }
41 },
42 styleTreeMapper : {
43 value: function arrayToTreeMapper(property, i, styleArray) {
44 var shorthands = ShorthandProps.CSS_SHORTHAND_MAP[property],
45 subProps, hasAll;
46
47 ///// Is this a sub property of a shorthand property?
48 if(shorthands) {
49 //debugger;
50 ///// Yes.
51 ///// Now, are all sub properties in the declaration?
52 subProps = ShorthandProps.CSS_SHORTHAND_TO_SUBPROP_MAP[shorthands[0]];
53 hasAll = subProps.every(function(subProp) {
54 return styleArray.indexOf(subProp) !== -1;
55 });
56
57 if(hasAll) {
58 ///// It has all sub properties
59 ///// Let's return a tree branch and remove the
60 ///// sub properties from the flat array
61
62 this._removeItemsFromArray(styleArray, subProps);
63
64 return {
65 name: shorthands[0],
66 value: this._declaration.getPropertyValue(shorthands[0]),
67 properties: subProps.map(function(p, i, array) {
68 return {
69 name: p,
70 value: this._declaration.getPropertyValue(p)
71 };
72 }, this)
73 };
74 }
75 }
76
77
78 return {
79 name: property,
80 value: this._declaration.getPropertyValue(property)
81 };
82 }
83 },
84 _removeItemsFromArray : {
85 value: function(array, items) {
86 items.forEach(function(item) {
87 var index = array.indexOf(item);
88 array.splice(index, 1);
89 }, this);
90 }
91 },
92 styleTree : {
93 value: {
94 "properties" : []
95 },
96 distinct: true
97 },
98 draw: {
99 value: function() {
100 if(this._declaration) {
101
102 }
103 }
104 }
105}); \ No newline at end of file