aboutsummaryrefslogtreecommitdiff
path: root/js/document/views/design.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-05-07 16:15:35 -0700
committerJose Antonio Marquez2012-05-07 16:15:35 -0700
commitd4976b9e129f690b3255d5c0347c410234f7cefa (patch)
tree10f157d2688a4642e79e34301bdc4871fb64bca9 /js/document/views/design.js
parentb8c27edc106818ff84f93ebe30ce50359a03885b (diff)
downloadninja-d4976b9e129f690b3255d5c0347c410234f7cefa.tar.gz
Extracting CSS methods to parsing class.
Need to do the same with webGL.
Diffstat (limited to 'js/document/views/design.js')
-rwxr-xr-xjs/document/views/design.js134
1 files changed, 49 insertions, 85 deletions
diff --git a/js/document/views/design.js b/js/document/views/design.js
index 8c6ace8e..2b8ccb26 100755
--- a/js/document/views/design.js
+++ b/js/document/views/design.js
@@ -131,9 +131,8 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
131 this.document.body.removeChild(this.document.getElementsByTagName('ninjaloadinghack')[0]); 131 this.document.body.removeChild(this.document.getElementsByTagName('ninjaloadinghack')[0]);
132 //Getting style and link tags in document 132 //Getting style and link tags in document
133 var stags = this.document.getElementsByTagName('style'), 133 var stags = this.document.getElementsByTagName('style'),
134 ltags = this.document.getElementsByTagName('link'), 134 ltags = this.document.getElementsByTagName('link'), i,
135 scripttags = this.document.getElementsByTagName('script'), 135 scripttags = this.document.getElementsByTagName('script');
136 i, n, webgldata;
137 //Temporarily checking for disabled special case (we must enabled for Ninja to access styles) 136 //Temporarily checking for disabled special case (we must enabled for Ninja to access styles)
138 this.ninjaDisableAttribute(stags); 137 this.ninjaDisableAttribute(stags);
139 this.ninjaDisableAttribute(ltags); 138 this.ninjaDisableAttribute(ltags);
@@ -152,28 +151,16 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
152 } 151 }
153 } 152 }
154 } 153 }
155 //Checking for webGL Data 154 //Checking and initializing webGL
156 for (var w in scripttags) { 155 if (scripttags.length > 0) {
157 // 156 this.initWebGl(scripttags);
158 webgldata = null; 157 } //Else there is not data to parse
159 // 158
160 if (scripttags[w].getAttribute) { 159
161 if (scripttags[w].getAttribute('data-ninja-webgl') !== null) {
162 //TODO: Add logic to handle more than one data tag
163 webgldata = JSON.parse((scripttags[w].innerHTML.replace("(", "")).replace(")", ""));
164 }
165 //
166 if (webgldata) {
167 for (n = 0; webgldata.data[n]; n++) {
168 webgldata.data[n] = unescape(webgldata.data[n]);
169 }
170 //this._templateDocument.webgl = webgldata.data;
171 this.model.glData = webgldata.data;
172 }
173 }
174 }
175 160
176 //TODO: Load Montage Components (blocking) 161 //TODO: Load Montage Components (blocking)
162 //this.initMontage();
163
177 164
178 //Makign callback if specified 165 //Makign callback if specified
179 if (this._callback) this._callback(); 166 if (this._callback) this._callback();
@@ -195,31 +182,28 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
195 } 182 }
196 }, 183 },
197 //////////////////////////////////////////////////////////////////// 184 ////////////////////////////////////////////////////////////////////
198 // 185 //TODO: Move to url-parser helper class
199 getStyleTagFromCssFile: { 186 getStyleTagFromCssFile: {
200 value: function (linktag) { 187 value: function (linktag) {
201 // 188 //
202 var tag, cssUrl, fileUri, cssData, docRootUrl; 189 var tag, cssData,
190 //TODO: Remove usage of hack reference of URL
191 docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
203 //Creating style tag to load CSS content into 192 //Creating style tag to load CSS content into
204 tag = this.document.createElement('style'); 193 tag = this.document.createElement('style');
205 tag.setAttribute('type', 'text/css'); 194 tag.setAttribute('type', 'text/css');
206 //TODO: Remove usage of hack reference of URL
207 docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
208 //Checking for location of href to load (special case for cross-domain) 195 //Checking for location of href to load (special case for cross-domain)
209 if (linktag.href.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { 196 if (linktag.href.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) {
210 //Getting file URI (not URL since we must load through I/O API) 197 //Loading data from file
211 cssUrl = linktag.href.split(this.application.ninja.coreIoApi.rootUrl)[1]; 198 cssData = this.urlParser.loadLocalStyleSheet(linktag.href);
212 fileUri = this.application.ninja.coreIoApi.cloudData.root+cssUrl;
213 //Loading data from CSS file
214 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri});
215 //Setting properties of locally loaded styles 199 //Setting properties of locally loaded styles
216 tag.setAttribute('data-ninja-uri', fileUri); 200 tag.setAttribute('data-ninja-uri', cssData.fileUri);
217 tag.setAttribute('data-ninja-file-url', cssUrl); 201 tag.setAttribute('data-ninja-file-url', cssData.cssUrl);
218 tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly); 202 tag.setAttribute('data-ninja-file-read-only', cssData.writable);
219 tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); 203 tag.setAttribute('data-ninja-file-name', cssData.cssUrl.split('/')[cssData.cssUrl.split('/').length-1]);
220 } else { 204 } else {
221 //Cross-domain content 205 //Cross-domain content
222 cssData = this.application.ninja.coreIoApi.readExternalFile({url: linktag.href, binary: false}); 206 cssData = this.urlParser.loadExternalStyleSheet(linktag.href);
223 //Setting properties of externally loaded styles 207 //Setting properties of externally loaded styles
224 tag.setAttribute('data-ninja-external-url', linktag.href); 208 tag.setAttribute('data-ninja-external-url', linktag.href);
225 tag.setAttribute('data-ninja-file-read-only', "true"); 209 tag.setAttribute('data-ninja-file-read-only', "true");
@@ -235,58 +219,38 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
235 } 219 }
236 } 220 }
237 } 221 }
238 222 //Setting content from loaded data
239 223 if (cssData.content) tag.innerHTML = cssData.content;
240 224 //Returning <style> with loaded contents
241
242
243
244
245
246
247
248
249 ////////////////////////////////////////////////////////
250 ////////////////////////////////////////////////////////
251 //TODO: Clean up and make proper method
252 fileCouldDirUrl = linktag.href.split(linktag.href.split('/')[linktag.href.split('/').length-1])[0];
253 //
254 if (cssData && cssData.content) {
255 tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, parseToNinjaUrl.bind(this));
256 } else {
257 //Error: no data was loaded
258 }
259 //
260 function parseToNinjaUrl (prop) {
261 //
262 return prop.replace(/[^()\\""\\'']+/g, prefixWithNinjaUrl.bind(this));
263 }
264 //
265 function prefixWithNinjaUrl (url) {
266 //
267 if (url !== 'url' && !url.match(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi)) {
268 url = fileCouldDirUrl+url;
269 }
270 //
271 return url;
272 }
273 ////////////////////////////////////////////////////////
274 ////////////////////////////////////////////////////////
275
276
277
278
279
280
281 //
282 return tag; 225 return tag;
283 } 226 }
284 }, 227 },
285 //////////////////////////////////////////////////////////////////// 228 ////////////////////////////////////////////////////////////////////
286 // 229 //Method to parse and initialize all webGL data read from file
287 initWebGl: { 230 initWebGl: {
288 value: function () { 231 value: function (scripttags) {
289 // 232 //
233 var i, n, webgldata;
234 //Checking for webGL Data
235 for (var w in scripttags) {
236 //
237 webgldata = null;
238 //Checking for tags with webGL data
239 if (scripttags[w].getAttribute) {
240 if (scripttags[w].getAttribute('data-ninja-webgl') !== null) {
241 //TODO: Add logic to handle more than one data tag
242 webgldata = JSON.parse((scripttags[w].innerHTML.replace("(", "")).replace(")", ""));
243 }
244 //Checking for webGL data and building data array
245 if (webgldata && webgldata.data) {
246 for (n = 0; webgldata.data[n]; n++) {
247 webgldata.data[n] = unescape(webgldata.data[n]);
248 }
249 //TODO: Improve setter of webGL and reference
250 this.model.glData = webgldata.data;
251 }
252 }
253 }
290 } 254 }
291 }, 255 },
292 //////////////////////////////////////////////////////////////////// 256 ////////////////////////////////////////////////////////////////////
@@ -297,12 +261,12 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
297 } 261 }
298 }, 262 },
299 //////////////////////////////////////////////////////////////////// 263 ////////////////////////////////////////////////////////////////////
300 // 264 //Method to get element from point, used by Ninja
301 getElementFromPoint: { 265 getElementFromPoint: {
302 value: function(x, y) { 266 value: function(x, y) {
303 return this.iframe.contentWindow.getElement(x,y); 267 return this.iframe.contentWindow.getElement(x,y);
304 } 268 }
305 }, 269 }
306 //////////////////////////////////////////////////////////////////// 270 ////////////////////////////////////////////////////////////////////
307 //////////////////////////////////////////////////////////////////// 271 ////////////////////////////////////////////////////////////////////
308}); 272});