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.js250
1 files changed, 250 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..3ddd8454
--- /dev/null
+++ b/js/panels/css-panel/style-sheet.reel/style-sheet.js
@@ -0,0 +1,250 @@
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 }
61 },
62
63 /* ------ Events------ */
64
65 handleMousedown : {
66 value: function(e) {
67 var nonBlurringElements = [
68 this.editView,
69 this.deleteButton.element,
70 this.disableButton.element,
71 this.importButton.element];
72
73 console.log("handle mousedown");
74
75 if(nonBlurringElements.indexOf(e.target) === -1) {
76 this.editing = false;
77 }
78 }
79 },
80
81 handleClick : {
82 value: function(e) {
83 this.parentComponent.parentComponent.defaultStyleSheet = this.source;
84 }
85 },
86
87 handleEditButtonAction: {
88 value: function(e) {
89 this.editing = true;
90 }
91 },
92
93 handleImportButtonAction: {
94 value: function(e) {
95 e.stopPropagation();
96 }
97 },
98
99 handleDisableButtonAction: {
100 value: function(e) {
101 e.stopPropagation();
102 this.disabled = !this.disabled;
103 }
104 },
105
106 handleDeleteButtonAction : {
107 value: function(e) {
108 e.stopPropagation();
109 debugger;
110 }
111 },
112
113 /* ------ State properties ------ */
114
115 _editing : {
116 value: null
117 },
118 editing : {
119 get: function() {
120 return this._editing;
121 },
122 set: function(enterEditingMode) {
123 this._editing = enterEditingMode;
124 this.needsDraw = true;
125 }
126 },
127
128 _name: {
129 value: "Style Tag",
130 distinct: true
131 },
132 name : {
133 get: function() {
134 return this._name;
135 },
136 set: function(text) {
137 this._name = text;
138 }
139 },
140 _readOnly : { value: null },
141 readOnly : {
142 get: function() {
143 return this._readOnly;
144 },
145 set: function(isReadOnly) {
146 this._readOnly = isReadOnly;
147 this.needsDraw = true;
148 }
149 },
150
151 _default : { value: null },
152 default : {
153 get: function() {
154 return this._default;
155 },
156 set: function(value) {
157 this._default = value;
158 this.needsDraw = true;
159 }
160 },
161
162 _disabled : {
163 value: null
164 },
165 disabled: {
166 get: function() {
167 return this._disabled;
168 },
169 set: function(disable) {
170 var label = (disable) ? "Enable" : "Disable";
171 this._source.ownerNode.disabled = disable;
172 this.disableButton.label = label;
173
174 this._disabled = disable;
175 }
176 },
177
178 external : {
179 value: null
180 },
181
182 _source : {
183 value: null
184 },
185 source : {
186 get: function() {
187 return this._source;
188 },
189 set: function(sheet) {
190 console.log('sheet being set: ', this);
191
192 this._extractData(sheet.ownerNode);
193 this._source = sheet;
194 }
195 },
196
197 _extractData : {
198 value: function(sheetNode) {
199 var data = sheetNode.dataset, key;
200
201 for(key in data) {
202 this[key] = data[key];
203 }
204 }
205 },
206
207 /* ------ Data Attribute Properties ------ */
208
209 _ninjaExternalUrl: { value: null },
210 ninjaExternalUrl : {
211 get: function() { return this._ninjaExternalUrl; },
212 set: function(url) {
213 this.external = true;
214 this._ninjaExternalUrl = url;
215 }
216 },
217
218 _ninjaFileName: { value: null },
219 ninjaFileName : {
220 get: function() { return this._ninjaFileName; },
221 set: function(fileName) {
222 this.name = fileName;
223 this._ninjaFileName = fileName;
224 }
225 },