aboutsummaryrefslogtreecommitdiff
path: root/js/panels/css-panel/style-sheet.reel/style-sheet.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/panels/css-panel/style-sheet.reel/style-sheet.js')
-rw-r--r--js/panels/css-panel/style-sheet.reel/style-sheet.js271
1 files changed, 271 insertions, 0 deletions
diff --git a/js/panels/css-panel/style-sheet.reel/style-sheet.js b/js/panels/css-panel/style-sheet.reel/style-sheet.js
new file mode 100644
index 00000000..0ff195d5
--- /dev/null
+++ b/js/panels/css-panel/style-sheet.reel/style-sheet.js
@@ -0,0 +1,271 @@
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.StyleSheet = Montage.create(Component, {
11 _translateDistance: {
12 value: null
13 },
14
15 prepareForDraw : {
16 value: function() {
17 this.nameText.element.addEventListener('click', this, false);
18 }
19 },
20
21 willDraw : {
22 value: function() {
23 if(this.editing) {
24 document.body.addEventListener('mousedown', this, false);
25 this._translateDistance = this._element.offsetWidth - this.editButton._element.offsetWidth;
26
27 } else {
28 document.body.removeEventListener('mousedown', this, false);
29 }
30 }
31 },
32 draw : {
33 value: function() {
34 var transStr = '-webkit-transform';
35
36 this.mediaInput.value = this._source.media.mediaText;
37
38 if(this.editing) {
39 this.editView.classList.add('expanded');
40 this.editView.style.setProperty(transStr, 'translate3d(-'+ this._translateDistance + 'px,0,0)');
41 } else {
42 this.editView.classList.remove('expanded');
43 this.editView.style.removeProperty(transStr);
44 }
45
46 if(this._readOnly) {
47 this._element.classList.add('ss-locked');
48 this.importButton.element.classList.remove('ss-invisible');
49 } else {
50 this._element.classList.remove('ss-locked');
51 this.importButton.element.classList.add('ss-invisible');
52 }
53
54 if(this.default) {
55 this._element.classList.add('default-style-sheet');
56 } else {
57 this._element.classList.remove('default-style-sheet');
58 }
59
60 if(this.dirty) {
61 this.nameText.element.classList.add('ss-dirty');
62 } else {
63 this.nameText.element.classList.remove('ss-dirty');
64 }
65
66 }
67 },
68
69 /* ------ Events------ */
70
71 handleMousedown : {
72 value: function(e) {
73 var nonBlurringElements = [
74 this.editView,
75 this.deleteButton.element,
76 this.disableButton.element,
77 this.importButton.element];
78
79 console.log("handle mousedown");
80
81 if(nonBlurringElements.indexOf(e.target) === -1) {
82 this.editing = false;
83 }
84 }
85 },
86
87 handleClick : {
88 value: function(e) {
89 this.parentComponent.parentComponent.defaultStyleSheet = this.source;
90 }
91 },
92
93 handleEditButtonAction: {
94 value: function(e) {
95 this.editing = true;
96 }
97 },
98
99 handleImportButtonAction: {
100 value: function(e) {
101 e.stopPropagation();
102 }
103 },
104
105 handleDisableButtonAction: {
106 value: function(e) {
107 e.stopPropagation();
108 this.disabled = !this.disabled;
109 }
110 },
111
112 handleDeleteButtonAction : {
113 value: function(e) {
114 e.stopPropagation();
115 debugger;
116 }
117 },
118
119 /* ------ State properties ------ */
120
121 _editing : {
122 value: null
123 },
124 editing : {
125 get: function() {
126 return this._editing;
127 },
128 set: function(enterEditingMode) {
129 this._editing = enterEditingMode;
130 this.needsDraw = true;
131 }
132 },
133
134 _name: {
135 value: "Style Tag",
136 distinct: true
137 },
138 name : {
139 get: function() {
140 return this._name;
141 },
142 set: function(text) {
143 this._name = text;
144 }
145 },
146 _dirty : {
147 value: null
148 },
149 dirty : {
150 get: function() {
151 return this._dirty;
152 },
153 set: function(value) {
154 if(value === this._dirty) { return false; }
155
156 this._dirty = value;
157 this.needsDraw = true;
158 }
159 },
160
161 _readOnly : { value: null },
162 readOnly : {
163 get: function() {
164 return this._readOnly;
165 },
166 set: function(isReadOnly) {
167 this._readOnly = isReadOnly;
168 this.needsDraw = true;
169 }
170 },
171
172 _default : { value: null },
173 default : {
174 get: function() {
175 return this._default;
176 },
177 set: function(value) {
178 this._default = value;
179 this.needsDraw = true;
180 }
181 },
182
183 _disabled : {
184 value: null
185 },
186 disabled: {
187 get: function() {
188 return this._disabled;
189 },
190 set: function(disable) {
191 var label = (disable) ? "Enable" : "Disable";
192 this._source.ownerNode.disabled = disable;
193 this.disableButton.label = label;
194
195 this._disabled = disable;
196 }
197 },
198
199 external : {
200 value: null
201 },
202
203 _source : {
204 value: null
205 },
206 source : {
207 get: function() {
208 return this._source;
209 },
210 set: function(sheet) {
211 console.log('sheet being set: ', this);
212
213 this._extractData(sheet.ownerNode);
214 this._source = sheet;
215 }
216 },
217
218 _extractData : {
219 value: function(sheetNode) {
220 var data = sheetNode.dataset, key;
221
222 for(key in data) {
223 this[key] = data[key];
224 }
225 }