diff options
Diffstat (limited to 'js/panels/css-panel/styles-view-container.reel/styles-view-container.js')
-rw-r--r-- | js/panels/css-panel/styles-view-container.reel/styles-view-container.js | 133 |
1 files changed, 129 insertions, 4 deletions
diff --git a/js/panels/css-panel/styles-view-container.reel/styles-view-container.js b/js/panels/css-panel/styles-view-container.reel/styles-view-container.js index 41e16192..6164a14c 100644 --- a/js/panels/css-panel/styles-view-container.reel/styles-view-container.js +++ b/js/panels/css-panel/styles-view-container.reel/styles-view-container.js | |||
@@ -8,28 +8,153 @@ var Montage = require("montage/core/core").Montage, | |||
8 | Component = require("montage/ui/component").Component; | 8 | Component = require("montage/ui/component").Component; |
9 | 9 | ||
10 | exports.StylesViewContainer = Montage.create(Component, { | 10 | exports.StylesViewContainer = Montage.create(Component, { |
11 | noDocumentCondition : { | 11 | noStylesCondition : { |
12 | value: true | 12 | value: true |
13 | }, | 13 | }, |
14 | contentController : { | ||
15 | value: null | ||
16 | }, | ||
14 | contentPanel : { | 17 | contentPanel : { |
15 | value: 'rules' | 18 | value: 'rules' |
16 | }, | 19 | }, |
17 | displayedList : { | 20 | _hasStyles : { |
18 | value: null | 21 | value: false |
19 | }, | 22 | }, |
20 | deserializedFromTemplate : { | 23 | hasStyles : { |
24 | get: function() { | ||
25 | return this._hasStyles; | ||
26 | }, | ||
27 | set: function(hasThem) { | ||
28 | this._hasStyles = hasThem; | ||
29 | this.needsDraw = true; | ||
30 | } | ||
31 | }, | ||
32 | templateDidLoad : { | ||
21 | value: function() { | 33 | value: function() { |
22 | console.log("styles view container - deserialized"); | 34 | console.log("styles view container - deserialized"); |
35 | this.eventManager.addEventListener('styleSheetsReady', this, false); | ||
36 | } | ||
37 | }, | ||
38 | handleStyleSheetsReady: { | ||
39 | value: function(e) { | ||
40 | this.eventManager.addEventListener( "selectionChange", this, false); | ||
41 | } | ||
42 | }, | ||
43 | handleSelectionChange: { | ||
44 | value: function() { | ||
45 | var elements = this.application.ninja.selectedElements, | ||
46 | type, selection, ruleList; | ||
47 | |||
48 | if(elements.length === 0) { | ||
49 | return false; | ||
50 | } else if(elements.length >= 1) { | ||
51 | type = 'ELEMENTS'; | ||
52 | selection = elements; | ||
53 | } else { | ||
54 | type = 'ELEMENTS'; | ||
55 | selection = elements[0] | ||
56 | } | ||
57 | |||
58 | ruleList = this._getRuleList({ | ||
59 | selectionType : type, | ||
60 | selection : selection | ||
61 | }); | ||
62 | |||
63 | if(ruleList) { | ||
64 | this.displayedList = ruleList; | ||
65 | } | ||
66 | } | ||
67 | }, | ||
68 | _lastDisplayedList : { | ||
69 | value: null | ||
70 | }, | ||
71 | _displayedList : { | ||
72 | value: null | ||
73 | }, | ||
74 | displayedList : { | ||
75 | get: function() { | ||
76 | return this._displayedList; | ||
77 | }, | ||
78 | set: function(list) { | ||
79 | this._hasStyles = true; | ||
80 | this._lastDisplayedList = this._displayedList; | ||
81 | this._displayedList = list; | ||
82 | this.needsDraw = true; | ||
83 | } | ||
84 | }, | ||
85 | _ruleList : { | ||
86 | value: [] | ||
87 | }, | ||
88 | ruleList : { | ||
89 | get: function() { | ||
90 | return this._ruleList; | ||
91 | }, | ||
92 | set: function(list) { | ||
93 | if(!list) { | ||
94 | this._ruleList.length = 0; | ||
95 | return; | ||
96 | } | ||
97 | |||
98 | this._ruleList = list; | ||
99 | this.needsDraw = true; | ||
23 | } | 100 | } |
24 | }, | 101 | }, |
25 | prepareForDraw : { | 102 | prepareForDraw : { |
26 | value: function() { | 103 | value: function() { |
104 | debugger; | ||
27 | console.log("styles view container - prepare for draw"); | 105 | console.log("styles view container - prepare for draw"); |
28 | } | 106 | } |
29 | }, | 107 | }, |
30 | draw : { | 108 | draw : { |
31 | value: function() { | 109 | value: function() { |
32 | console.log("styles view container - draw"); | 110 | console.log("styles view container - draw"); |
111 | console.log("has style = " + this._hasStyles); | ||
112 | if(this.hasStyles) { | ||
113 | this.element.classList.remove('no-styles'); | ||
114 | } else { | ||
115 | this.element.classList.add('no-styles'); | ||
116 | } | ||
117 | |||
118 | if(this._lastDisplayedList) { | ||
119 | //this._lastDisplayedList.style.display = 'none'; | ||
120 | } | ||
121 | |||
122 | //this._displayedList.style.display = ''; | ||
123 | } | ||
124 | }, | ||
125 | _getRuleList : { | ||
126 | value: function(s) { | ||
127 | var ruleListsOfType, i, list, matchesAll; | ||
128 | |||
129 | ruleListsOfType = this.ruleLists.filter(function(list) { | ||
130 | return list.selectionType = s.selectionType; | ||
131 | }); | ||
132 | |||
133 | for(i = 0; i<this.ruleLists.length; i++) { | ||
134 | list = this.ruleLists[i]; | ||
135 | |||
136 | if(s.selectionType === 'elements') { | ||
137 | matchesAll = list.selection.every(function(element, index, array) { | ||
138 | return array.indexOf(element) !== 0; | ||
139 | }); | ||
140 | |||
141 | if(matchesAll) { | ||
142 | break; | ||
143 | } | ||
144 | } else { | ||
145 | ///// Selection (single element or stylesheet) is the same, | ||
146 | ///// Use the existing rule list | ||
147 | if(list.selection === s.selection) { | ||
148 | break; | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | |||
153 | return list; | ||
154 | |||
33 | } | 155 | } |
156 | }, | ||
157 | ruleLists : { | ||
158 | value: [] | ||
34 | } | 159 | } |
35 | }); \ No newline at end of file | 160 | }); \ No newline at end of file |