aboutsummaryrefslogtreecommitdiff
path: root/js/panels/css-panel/styles-view-container.reel/styles-view-container.js
diff options
context:
space:
mode:
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.js185
1 files changed, 185 insertions, 0 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
new file mode 100644
index 00000000..e63e3c74
--- /dev/null
+++ b/js/panels/css-panel/styles-view-container.reel/styles-view-container.js
@@ -0,0 +1,185 @@
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
10exports.StylesViewContainer = Montage.create(Component, {
11 contentController : {
12 value: null
13 },
14 contentPanel : {
15 value: 'rules'
16 },
17 _selectionNameLabelText : {
18 value: null
19 },
20 selectionNameLabelText : {
21 get: function() {
22 return this._selectionNameLabelText;
23 },
24 set: function(value) {
25 if(value === this._selectionNameLabelText) { return false; }
26
27 this._selectionNameLabelText = value;
28
29 this.needsDraw = true;
30 }
31 },
32 _lastSelection : {
33 value: null
34 },
35 _hasStyles : {
36 value: false
37 },
38 hasStyles : {
39 get: function() {
40 return this._hasStyles;
41 },
42 set: function(hasThem) {
43 this._hasStyles = hasThem;
44 //caller needs to set ndt
45 //this.needsDraw = true;
46 }
47 },
48
49 _getElementLabel : {
50 value: function(el) {
51 var id = '#'+el.id,
52 className = '.'+Array.prototype.slice.call(el.classList).join('.'),
53 nodeName = el.nodeName;
54
55 if(id.length > 1) {
56 return nodeName + id;
57 } else if(className.length > 1) {
58 return nodeName + className;
59 }
60
61 return nodeName;
62 }
63 },
64
65 templateDidLoad : {
66 value: function() {
67 this.eventManager.addEventListener('styleSheetsReady', this, false);
68 //this.eventManager.addEventListener('elementChanging', this, false);
69 this.eventManager.addEventListener('elementChange', this, false);
70 this.eventManager.addEventListener("closeDocument", this, false);
71 }
72 },
73 handleStyleSheetsReady: {
74 value: function(e) {
75 this.eventManager.addEventListener( "selectionChange", this, false);
76 }
77 },
78 handleSelectionChange: {
79 value: function() {
80 var elements = this.application.ninja.selectedElements;
81
82 if(this._isSameArray(elements, this._lastSelection) && this.contentPanel === "rules") {
83 console.log('new selection is identical');
84 return false;
85 }
86
87 this._lastSelection = elements;
88
89 if(elements.length === 0) {
90 this.hasStyles = false;
91 return false;
92 } else if(elements.length === 1) {
93
94 ///// update the selection status label with the label of the element
95 this.selectionNameLabelText = this._getElementLabel(elements[0]);
96
97 if(this.contentPanel === "rules") {
98 this.ruleListContainer.displayListForSelection(elements);
99 } else {
100 this.computedStyleView.declaration = elements[0];
101 }
102 this.toolbar.showButton('computed');
103 } else {
104 this.toolbar.hideButton('computed');
105 this.contentPanel = "rules";
106 this.selectionNameLabelText = elements.length + " elements selected.";
107 ///// find common rules
108 this.ruleListContainer.displayListForSelection(elements);
109
110 }
111
112 this.hasStyles = true;
113 }
114 },
115 handleElementChange : {
116 value: function(e) {
117 var elements = this.application.ninja.selectedElements;
118
119 if(elements.length === 0) {
120 return false;
121 } else if(elements.length === 1) {
122 if(this.contentPanel === "rules") {
123 if(e._event.detail.type !== 'cssChange') {
124 this.ruleListContainer.update();
125 }
126 } else {
127 this.computedStyleView.declaration = elements[0];
128 }
129 } else {
130 return false;
131 }
132
133 }
134 },
135
136 handleElementChanging : {
137 value: function(e) {
138 var elements = this.application.ninja.selectedElements;
139
140 if(elements.length === 1) {
141 if(this.contentPanel === "rules") {
142// if(e._event.detail.type !== 'cssChange') {
143// this.ruleListContainer.displayedList.component.update();
144// }
145 } else {
146 this.computedStyleView.declaration = elements[0];
147 }
148 }
149
150 return false;
151
152 }
153 },
154 handleCloseDocument: {
155 value: function(e) {
156 this.hasStyles = false;
157 this.needsDraw = true;
158 }
159 },
160
161 draw : {
162 value: function() {
163 if(this.hasStyles) {
164 this.element.classList.remove('no-styles');
165 //this.selectionNameLabel.classList.remove('no-styles');
166 this.selectionName.element.classList.remove('no-styles');
167 } else {
168 this.element.classList.add('no-styles');
169 //this.selectionNameLabel.classList.add('no-styles');
170 this.selectionName.element.classList.add('no-styles');
171 }
172 }
173 },
174
175 _isSameArray : {
176 value: function(left, right) {
177 if(!left || !right) { return false; }
178 if(left.length !== right.length) { return false; }
179
180 return left.every(function(item, i) {
181 return item === right[i];
182 });
183 }
184 }
185}); \ No newline at end of file