aboutsummaryrefslogtreecommitdiff
path: root/js/document/views/design.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-05-07 17:19:16 -0700
committerNivesh Rajbhandari2012-05-07 17:19:16 -0700
commit377c57c7debc98071593056be033978bd337c37e (patch)
treebade422fe2471a18944e846cfec1dd188a6cdae3 /js/document/views/design.js
parentaa8cfcfe0091651708f77300f48a7e703f92f341 (diff)
parent4d949f141247215b5f2a6ec0cfc7d2d31cf2bb1f (diff)
downloadninja-377c57c7debc98071593056be033978bd337c37e.tar.gz
Merge branch 'refs/heads/dom-architecture-master' into Dom-Architecture
Conflicts: js/document/document-html.js Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/document/views/design.js')
-rwxr-xr-xjs/document/views/design.js136
1 files changed, 51 insertions, 85 deletions
diff --git a/js/document/views/design.js b/js/document/views/design.js
index 8c6ace8e..b23ebe78 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,40 @@ 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 //Setting the iFrame property for reference in helper class
235 this.model.webGlHelper.iframe = this.model.views.design.iframe;
236 //Checking for webGL Data
237 for (var w in scripttags) {
238 //
239 webgldata = null;
240 //Checking for tags with webGL data
241 if (scripttags[w].getAttribute) {
242 if (scripttags[w].getAttribute('data-ninja-webgl') !== null) {
243 //TODO: Add logic to handle more than one data tag
244 webgldata = JSON.parse((scripttags[w].innerHTML.replace("(", "")).replace(")", ""));
245 }
246 //Checking for webGL data and building data array
247 if (webgldata && webgldata.data) {
248 for (n = 0; webgldata.data[n]; n++) {
249 webgldata.data[n] = unescape(webgldata.data[n]);
250 }
251 //TODO: Improve setter of webGL and reference
252 this.model.webGlHelper.glData = webgldata.data;
253 }
254 }
255 }
290 } 256 }
291 }, 257 },
292 //////////////////////////////////////////////////////////////////// 258 ////////////////////////////////////////////////////////////////////
@@ -297,12 +263,12 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
297 } 263 }
298 }, 264 },
299 //////////////////////////////////////////////////////////////////// 265 ////////////////////////////////////////////////////////////////////
300 // 266 //Method to get element from point, used by Ninja
301 getElementFromPoint: { 267 getElementFromPoint: {
302 value: function(x, y) { 268 value: function(x, y) {
303 return this.iframe.contentWindow.getElement(x,y); 269 return this.iframe.contentWindow.getElement(x,y);
304 } 270 }
305 }, 271 }
306 //////////////////////////////////////////////////////////////////// 272 ////////////////////////////////////////////////////////////////////
307 //////////////////////////////////////////////////////////////////// 273 ////////////////////////////////////////////////////////////////////
308}); 274});