diff options
Diffstat (limited to 'js/panels/css-panel/style-declaration.reel/style-declaration.js')
-rw-r--r-- | js/panels/css-panel/style-declaration.reel/style-declaration.js | 245 |
1 files changed, 118 insertions, 127 deletions
diff --git a/js/panels/css-panel/style-declaration.reel/style-declaration.js b/js/panels/css-panel/style-declaration.reel/style-declaration.js index 80d8ff7b..33e77297 100644 --- a/js/panels/css-panel/style-declaration.reel/style-declaration.js +++ b/js/panels/css-panel/style-declaration.reel/style-declaration.js | |||
@@ -9,38 +9,61 @@ var Montage = require("montage/core/core").Montage, | |||
9 | ShorthandProps = require("js/panels/CSSPanel/css-shorthand-map"); | 9 | ShorthandProps = require("js/panels/CSSPanel/css-shorthand-map"); |
10 | 10 | ||
11 | exports.StyleDeclaration = Montage.create(Component, { | 11 | exports.StyleDeclaration = Montage.create(Component, { |
12 | cssText : { | 12 | cssText : { value: null }, |
13 | value: null | 13 | focusDelegate : { value: null }, |
14 | }, | 14 | |
15 | focusDelegate : { | ||
16 | value: null | ||
17 | }, | ||
18 | includeEmptyStyle : { | 15 | includeEmptyStyle : { |
19 | value: true | 16 | value: true, |
17 | distinct: true | ||
20 | }, | 18 | }, |
21 | styles : { | 19 | styles : { |
22 | value: [], | 20 | value: [], |
23 | distinct: true | 21 | distinct: true |
24 | }, | 22 | }, |
25 | 23 | ||
26 | templateDidLoad : { | 24 | _styleSortFunction : { |
27 | value: function() { | 25 | value: function(styleA, styleB) { |
28 | console.log("Style declaration - template did load"); | 26 | ///// If the style is an empty style (with Add button) |
27 | ///// push to end of declaration | ||
28 | if(styleA.isEmpty) { | ||
29 | return 1; | ||
30 | } else if (styleB.isEmpty) { | ||
31 | return -1; | ||
32 | } | ||
29 | 33 | ||
30 | if(this.focusDelegate) { | 34 | ///// Alphabetic sort based on property name |
31 | //this.treeController.delegate = this.focusDelegate; | 35 | if (styleA.name < styleB.name) { |
32 | this.styleComponent.delegate = this.focusDelegate; | 36 | return -1; |
37 | } else if (styleA.name > styleB.name) { | ||
38 | return 1; | ||
39 | } else { | ||
40 | return 0; | ||
33 | } | 41 | } |
34 | } | 42 | } |
35 | }, | 43 | }, |
36 | prepareForDraw : { | 44 | _styleFilterFunction: { |
37 | value: function(e) { | 45 | value: function(style, styleArray) { |
38 | console.log("Style Declaration :: prepare for draw"); | 46 | var shorthands = ShorthandProps.CSS_SHORTHAND_MAP[style.name]; |
39 | this._element.addEventListener('drop', this, false); | 47 | |
40 | this.element.addEventListener('dragenter', this, false); | 48 | ///// No shorthands, return true to include style |
41 | this.element.addEventListener('dragleave', this, false); | 49 | if(!shorthands) { return true; } |
50 | |||
51 | var subProps = ShorthandProps.CSS_SHORTHAND_TO_SUBPROP_MAP[shorthands[0]], | ||
52 | stylesArray = styleArray, | ||
53 | hasAll; | ||
54 | |||
55 | debugger; | ||
56 | hasAll = subProps.every(function(subProp) { | ||
57 | debugger; | ||
58 | return this.declaration[subProp]; | ||
59 | }, this); | ||
60 | |||
61 | if(hasAll) { | ||
62 | return false; | ||
63 | } | ||
42 | } | 64 | } |
43 | }, | 65 | }, |
66 | |||
44 | _declaration: { | 67 | _declaration: { |
45 | value: null | 68 | value: null |
46 | }, | 69 | }, |
@@ -49,21 +72,17 @@ exports.StyleDeclaration = Montage.create(Component, { | |||
49 | return this._declaration; | 72 | return this._declaration; |
50 | }, | 73 | }, |
51 | set: function(dec) { | 74 | set: function(dec) { |
75 | var stylesArray; | ||
76 | |||
52 | if(this._declaration) { | 77 | if(this._declaration) { |
53 | this.arrayController.removeObjects(this.styles); | 78 | this.styles = null; |
79 | this.styles = []; | ||
54 | } | 80 | } |
55 | console.log("dec being set", this); | ||
56 | this._declaration = dec; | ||
57 | 81 | ||
82 | ///// Take snapshot of declaration | ||
58 | this.cssText = dec.cssText; | 83 | this.cssText = dec.cssText; |
59 | 84 | ||
60 | Array.prototype.slice.call(dec).forEach(function(prop, index) { | 85 | stylesArray = Array.prototype.slice.call(dec); |
61 | this.styles.push({ | ||
62 | name: prop, | ||
63 | value: dec.getPropertyValue(prop) | ||
64 | }); | ||
65 | |||
66 | }, this); | ||
67 | 86 | ||
68 | if(this.includeEmptyStyle) { | 87 | if(this.includeEmptyStyle) { |
69 | this.styles.push({ | 88 | this.styles.push({ |
@@ -72,109 +91,85 @@ console.log("dec being set", this); | |||
72 | "isEmpty": true | 91 | "isEmpty": true |
73 | }); | 92 | }); |
74 | } | 93 | } |
75 | ///// creates data structure to use with tree component | ||
76 | //this.buildStyleTree(); | ||
77 | 94 | ||
78 | // if(this.includeEmptyStyle) { | 95 | stylesArray.forEach(function(prop, index) { |
79 | // this.styleTree.properties.push({ | 96 | this.styles.push({ |
80 | // "name": "property", | 97 | name: prop, |
81 | // "value" : "value", | 98 | value: dec.getPropertyValue(prop) |
82 | // "isEmpty": true | 99 | }); |
83 | // }); | 100 | }, this); |
84 | // } | ||
85 | 101 | ||
102 | this._declaration = dec; | ||
86 | this.needsDraw = true; | 103 | this.needsDraw = true; |
87 | } | 104 | } |
88 | }, | 105 | }, |
89 | 106 | ||
90 | update : { | 107 | styleShorthander : { |
91 | value: function() { | 108 | value: function(styles) { |
92 | if(this.declaration.cssText !== this.cssText) { | 109 | var shorthandsToAdd = [], |
93 | ///// Needs update | 110 | subProps, hasAll; |
94 | //debugger; | ||
95 | |||
96 | this.styles = null; | ||
97 | this.styles = []; | ||
98 | |||
99 | Array.prototype.slice.call(this.declaration).forEach(function(prop, index) { | ||
100 | this.styles.push({ | ||
101 | name: prop, | ||
102 | value: this.declaration.getPropertyValue(prop) | ||
103 | }); | ||
104 | 111 | ||
105 | }, this); | 112 | styles.forEach(function(property, index, styleArray) { |
113 | var shorthands = ShorthandProps.CSS_SHORTHAND_MAP[property]; | ||
106 | 114 | ||
107 | if(this.includeEmptyStyle) { | 115 | if(!shorthands) { return false; } |
108 | this.styles.push({ | ||
109 | "name": "property", | ||
110 | "value" : "value", | ||
111 | "isEmpty": true | ||
112 | }); | ||
113 | } | ||
114 | //debugger; | ||
115 | this.needsDraw = true; | ||
116 | } | ||
117 | } | ||
118 | }, | ||
119 | 116 | ||
120 | // buildStyleTree : { | 117 | var subProps = ShorthandProps.CSS_SHORTHAND_TO_SUBPROP_MAP[shorthands[0]], |
121 | // value: function() { | 118 | stylesArray = styleArray; |
122 | // var styles = Array.prototype.slice.call(this._declaration).sort(); | ||
123 | // this.styleTree = { | ||
124 | // properties : styles.map(this.styleTreeMapper, this) | ||
125 | // }; | ||
126 | // } | ||
127 | // }, | ||
128 | styleTreeMapper : { | ||
129 | value: function arrayToTreeMapper(property, i, styleArray) { | ||
130 | var shorthands = ShorthandProps.CSS_SHORTHAND_MAP[property], | ||
131 | subProps, hasAll; | ||
132 | 119 | ||
133 | ///// Is this a sub property of a shorthand property? | ||
134 | if(shorthands) { | ||
135 | //debugger; | ||
136 | ///// Yes. | ||
137 | ///// Now, are all sub properties in the declaration? | ||
138 | subProps = ShorthandProps.CSS_SHORTHAND_TO_SUBPROP_MAP[shorthands[0]]; | ||
139 | hasAll = subProps.every(function(subProp) { | 120 | hasAll = subProps.every(function(subProp) { |
140 | return styleArray.indexOf(subProp) !== -1; | 121 | return stylesArray.indexOf(subProp) !== -1; |
141 | }); | 122 | }); |
142 | 123 | ||
143 | if(hasAll) { |