aboutsummaryrefslogtreecommitdiff
path: root/js/document
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
parentb8c27edc106818ff84f93ebe30ce50359a03885b (diff)
downloadninja-d4976b9e129f690b3255d5c0347c410234f7cefa.tar.gz
Extracting CSS methods to parsing class.
Need to do the same with webGL.
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/document-html.js6
-rwxr-xr-xjs/document/helpers/url-parser.js57
-rwxr-xr-xjs/document/helpers/webgl-parser.js23
-rwxr-xr-xjs/document/views/design.js134
4 files changed, 125 insertions, 95 deletions
diff --git a/js/document/document-html.js b/js/document/document-html.js
index 79fe461b..567e4455 100755
--- a/js/document/document-html.js
+++ b/js/document/document-html.js
@@ -81,6 +81,10 @@ exports.HtmlDocument = Montage.create(Component, {
81 } 81 }
82 // 82 //
83 if (view === 'design') { 83 if (view === 'design') {
84 //TODO: Remove reference and use as part of model
85 this.currentView = 'design';
86 //Setting current view object to design
87 this.model.currentView = this.model.views.design;
84 //Showing design iFrame 88 //Showing design iFrame
85 this.model.views.design.show(); 89 this.model.views.design.show();
86 this.model.views.design.iframe.style.opacity = 0; 90 this.model.views.design.iframe.style.opacity = 0;
@@ -118,8 +122,6 @@ exports.HtmlDocument = Montage.create(Component, {
118 this.loaded.callback.call(this.loaded.context, this); 122 this.loaded.callback.call(this.loaded.context, this);
119 //Setting opacity to be viewable after load 123 //Setting opacity to be viewable after load
120 this.model.views.design.iframe.style.opacity = 1; 124 this.model.views.design.iframe.style.opacity = 1;
121 //TODO: Remove, this is a temp hard-coded hack
122 this.application.ninja.appModel.show3dGrid = true;
123 } 125 }
124 } 126 }
125 //////////////////////////////////////////////////////////////////// 127 ////////////////////////////////////////////////////////////////////
diff --git a/js/document/helpers/url-parser.js b/js/document/helpers/url-parser.js
index a1a7406a..5e71d148 100755
--- a/js/document/helpers/url-parser.js
+++ b/js/document/helpers/url-parser.js
@@ -18,24 +18,65 @@ exports.UrlParser = Montage.create(Component, {
18 }, 18 },
19 //////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////
20 // 20 //
21 parseStyles: { 21 parseStyleUrls: {
22 value: function (styles) { 22 value: function (css, href, local) {
23 // 23 //
24 if (local) {
25 var fileCouldDirUrl = href.split(href.split('/')[href.split('/').length-1])[0];
26 } else {
27 //TODO: Add logic for external URLs
28 }
29 //TODO: Clean up functions
30 css = css.replace(/url\(()(.+?)\1\)/g, parseToNinjaUrl.bind(this));
31 //
32 function parseToNinjaUrl (prop) {
33 //
34 return prop.replace(/[^()\\""\\'']+/g, prefixWithNinjaUrl.bind(this));
35 }
36 //
37 function prefixWithNinjaUrl (url) {
38 //
39 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)) {
40 url = fileCouldDirUrl+url;
41 }
42 //
43 return url;
44 }
45 //
46 return css;
24 } 47 }
25 }, 48 },
26 //////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////
27 // 50 //
28 loadLocalStyleSheet: { 51 loadLocalStyleSheet: {
29 value: function (path) { 52 value: function (href) {
30 // 53 //Getting file URI (not URL since we must load through I/O API)
54 var css = {}, file;
55 css.cssUrl = href.split(this.application.ninja.coreIoApi.rootUrl)[1];
56 css.fileUri = this.application.ninja.coreIoApi.cloudData.root + css.cssUrl;
57 //Loading data from CSS file
58 file = this.application.ninja.coreIoApi.readFile({uri: css.fileUri});
59 //Checking for file to be writable on disk
60 css.writable = JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: css.fileUri}).content).readOnly;
61 //Returning loaded file
62 if (file && file.content) {
63 //Getting file contents
64 css.content = this.parseStyleUrls(file.content, href, true);
65 //Returning CSS object
66 return css;
67 } else {
68 return false;
69 }
31 } 70 }
32 } 71 },
33 ,
34 //////////////////////////////////////////////////////////////////// 72 ////////////////////////////////////////////////////////////////////
35 // 73 //
36 loadExternalStyleSheet: { 74 loadExternalStyleSheet: {
37 value: function (path) { 75 value: function (href) {
38 // 76 //Loading external file
77 var file = this.application.ninja.coreIoApi.readExternalFile({url: href, binary: false});
78 //Returning file
79 return file;
39 } 80 }
40 } 81 }
41 //////////////////////////////////////////////////////////////////// 82 ////////////////////////////////////////////////////////////////////
diff --git a/js/document/helpers/webgl-parser.js b/js/document/helpers/webgl-parser.js
new file mode 100755
index 00000000..b52ea52b
--- /dev/null
+++ b/js/document/helpers/webgl-parser.js
@@ -0,0 +1,23 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No 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
7////////////////////////////////////////////////////////////////////////
8//
9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component;
11////////////////////////////////////////////////////////////////////////
12//
13exports.webGlDocumentParser = Montage.create(Component, {
14 ////////////////////////////////////////////////////////////////////
15 //
16 hasTemplate: {
17 value: false
18 }
19 ////////////////////////////////////////////////////////////////////
20 ////////////////////////////////////////////////////////////////////
21});
22////////////////////////////////////////////////////////////////////////
23//////////////////////////////////////////////////////////////////////// \ No newline at end of file
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.loadLocalStyleShee