aboutsummaryrefslogtreecommitdiff
path: root/js/panels/css-panel/style-sheets-view.reel/style-sheets-view.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/panels/css-panel/style-sheets-view.reel/style-sheets-view.js')
-rw-r--r--js/panels/css-panel/style-sheets-view.reel/style-sheets-view.js215
1 files changed, 215 insertions, 0 deletions
diff --git a/js/panels/css-panel/style-sheets-view.reel/style-sheets-view.js b/js/panels/css-panel/style-sheets-view.reel/style-sheets-view.js
new file mode 100644
index 00000000..7902f80a
--- /dev/null
+++ b/js/panels/css-panel/style-sheets-view.reel/style-sheets-view.js
@@ -0,0 +1,215 @@
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.StyleSheetsView = Montage.create(Component, {
11 noDocumentCondition : { value: true },
12 showToolbar : { value: false },
13 stylesController : { value: null },
14 styleSheets : { value: [] },
15 _initView : { value: false },
16 _needsScroll : { value: false },
17 documentNameLabel : { value: null },
18 noDocumentLabelClass : { value: "no-document" },
19
20 _documentName : { value: null },
21 documentName : {
22 get: function() {
23 return this._documentName;
24 },
25 set: function(label) {
26 if(label === this._documentName) { return false; }
27
28 this._documentName = label;
29 this.needsDraw = true;
30 }
31 },
32 _defaultStyleSheet: { value: null },
33 defaultStyleSheet: {
34 get: function() {
35 return this._defaultStyleSheet;
36 },
37 set: function(sheet) {
38 if(sheet === this._defaultStyleSheet) { return false; }
39
40 var sheetComponent, oldDefaultSheet;
41
42 if(this.styleSheetList) {
43 sheetComponent = this.styleSheetList.childComponents[this.styleSheets.indexOf(sheet)];
44 sheetComponent.default = true;
45 if(this._defaultStyleSheet) {
46 oldDefaultSheet = this.styleSheetList.childComponents[this.styleSheets.indexOf(this._defaultStyleSheet)];
47 oldDefaultSheet.default = false;
48 }
49 }
50
51 this._defaultStyleSheet = sheet;
52 this.needsDraw = true;
53 }
54 },
55
56 _dirtyStyleSheets : { value: null },
57 dirtyStyleSheets : {
58 get: function() {
59 return this._dirtyStyleSheets;
60 },
61 set: function(value) {
62 if(value === this._dirtyStyleSheets) { return false; }
63
64 this._dirtyStyleSheets = value;
65
66 this.needsDraw = true;
67 }
68 },
69
70 /// Toolbar Button Actions
71 /// --------------------------------
72
73 ///// Add rule button action
74 handleAddAction : {
75 value: function(e) {
76 this.stylesController.createStylesheet();
77 this.needsDraw = this._needsScroll = true;
78
79 }
80 },
81
82 /// App event handlers
83 /// --------------------------------
84
85 handleStyleSheetsReady : {
86 value: function(e) {
87 this.documentName = this.stylesController.activeDocument.name;
88 this.styleSheets = this.stylesController.userStyleSheets;
89
90 Object.defineBinding(this, 'defaultStyleSheet', {
91 'boundObject': this.stylesController,
92 'boundObjectPropertyPath': 'defaultStylesheet',
93 'oneway': false
94 });
95
96 Object.defineBinding(this, 'dirtyStyleSheets', {
97 'boundObject': this.stylesController,
98 'boundObjectPropertyPath': 'dirtyStyleSheets',
99 'oneway': true
100 });
101
102 this._initView = this.needsDraw = true;
103 }
104 },
105
106 handleStyleSheetModified : {
107 value: function(e) {
108 this.needsDraw = true;
109 }
110 },
111
112 /// Draw cycle
113 /// --------------------------------
114
115 templateDidLoad : {
116 value: function() {
117 this.stylesController = this.application.ninja.stylesController;
118 }
119 },
120 prepareForDraw : {
121 value: function() {
122 this.eventManager.addEventListener("styleSheetsReady", this, false);
123 this.eventManager.addEventListener("styleSheetModified", this, false);
124 }
125 },
126 draw : {
127 value: function() {
128 if(this._initView) {
129 this.noDocumentCondition = false;
130 this.showToolbar = true;
131 this._initView = false;
132 }
133
134 if(this.height) {
135 this.styleSheetList.element.style.height = (this.height + this._resizedHeight) + "px";
136 }
137
138 if(this.documentName && this.documentNameLabel) {
139 this.documentNameLabel.innerHTML = this.documentName;
140 this.documentNameLabel.classList.remove(this.noDocumentLabelClass);
141 } else {
142 this.documentNameLabel.classList.add(this.noDocumentLabelClass);
143 }
144
145 if(this.dirtyStyleSheets) {
146 var dirtySheets = this.dirtyStyleSheets.map(function(sheetDescriptor) {
147 return sheetDescriptor.stylesheet;
148 });
149
150 this.styleSheetList.childComponents.forEach(function(sheetComponent) {
151 sheetComponent.dirty = dirtySheets.indexOf(sheetComponent.source) !== -1;
152 }, this);
153 }
154
155 if(this._needsScroll) {
156
157 setTimeout(function() {
158 console.log('setting scroll top to:', this.styleSheetList.element.scrollHeight);
159 //debugger;
160 this.styleSheetList.element.scrollTop = this.styleSheetList.element.scrollHeight;
161 }.bind(this), 50);
162
163 this._needsScroll = false;
164 }
165 }
166 },
167 didDraw: {
168 value: function() {
169 if(!this.isResizing) {
170 this.height = this.styleSheetList.element.offsetHeight;
171 }
172 }
173 },
174
175
176 /// Resize properties
177 /// --------------------------------
178
179 _resizedHeight : { value: null },
180 isResizing : { value: null },
181 _height : { value: null },
182 height: {
183 get: function() {
184 return this._height;
185 },
186 set: function(val) {
187 if(this._height !== val) {
188 this._height = val;
189 this.needsDraw = true;
190 }
191 }
192 },
193 handleResizeStart: {
194 value:function(e) {
195 this.isResizing = true;
196 this.needsDraw = true;
197 }
198 },
199
200 handleResizeMove: {
201 value:function(e) {
202 this._resizedHeight = e._event.dY;
203 this.needsDraw = true;
204 }
205 },
206
207 handleResizeEnd: {
208 value: function(e) {
209 this.height += this._resizedHeight;
210 this._resizedHeight = 0;