diff options
author | Ananya Sen | 2012-02-27 14:24:49 -0800 |
---|---|---|
committer | Ananya Sen | 2012-02-27 14:24:49 -0800 |
commit | 15d00c49b522aa471d1ccfbbd33f5c0e721eb89e (patch) | |
tree | 5c352c198ed7404f3fe0a9c5915e1727d3003f9f /js/document | |
parent | 604ace9cfc9fae6b6c121259523a9060c5306161 (diff) | |
parent | 7e63b5d0b6990b6c0ec0385d35534b91982ac672 (diff) | |
download | ninja-15d00c49b522aa471d1ccfbbd33f5c0e721eb89e.tar.gz |
Merge branch 'refs/heads/FileIO-jose' into FileIO
Diffstat (limited to 'js/document')
-rwxr-xr-x | js/document/html-document.js | 70 |
1 files changed, 63 insertions, 7 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js index c36e61d5..75628731 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js | |||
@@ -177,15 +177,15 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
177 | cdm.collectGLData( elt, this._glData ); | 177 | cdm.collectGLData( elt, this._glData ); |
178 | } | 178 | } |
179 | 179 | ||
180 | return this._glData | 180 | return this._glData; |
181 | }, | 181 | }, |
182 | 182 | ||
183 | set: function(value) | 183 | set: function(value) |
184 | { | 184 | { |
185 | var elt = this.iframe.contentWindow.document.getElementById("UserContent"); | 185 | var elt = this.documentRoot; |
186 | if (elt) | 186 | if (elt) |
187 | { | 187 | { |
188 | console.log( "load canvas data: " + value ); | 188 | console.log( "load canvas data: " , value ); |
189 | var cdm = new CanvasDataManager(); | 189 | var cdm = new CanvasDataManager(); |
190 | cdm.loadGLData(elt, value); | 190 | cdm.loadGLData(elt, value); |
191 | } | 191 | } |
@@ -381,7 +381,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
381 | // | 381 | // |
382 | for (var k in this._document.styleSheets) { | 382 | for (var k in this._document.styleSheets) { |
383 | if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) { | 383 | if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) { |
384 | this._document.styleSheets[k].ownerNode.setAttribute('ninjatemplate', 'true'); | 384 | this._document.styleSheets[k].ownerNode.setAttribute('data-ninja-template', 'true'); |
385 | } | 385 | } |
386 | } | 386 | } |
387 | // | 387 | // |
@@ -389,6 +389,25 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
389 | //Inserting user's document into template | 389 | //Inserting user's document into template |
390 | this._templateDocument.head.innerHTML = this._userDocument.content.head; | 390 | this._templateDocument.head.innerHTML = this._userDocument.content.head; |
391 | this._templateDocument.body.innerHTML = this._userDocument.content.body; | 391 | this._templateDocument.body.innerHTML = this._userDocument.content.body; |
392 | //TODO: Use querySelectorAll | ||
393 | var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; | ||
394 | // | ||
395 | for (var w in scripttags) { | ||
396 | if (scripttags[w].getAttribute) { | ||
397 | if (scripttags[w].getAttribute('data-ninja-webgl') !== null) { | ||
398 | //TODO: Add logic to handle more than one data tag | ||
399 | webgldata = JSON.parse((scripttags[w].innerHTML.replace("(", "")).replace(")", "")); | ||
400 | } | ||
401 | } | ||
402 | } | ||
403 | // | ||
404 | if (webgldata) { | ||
405 | for (var n=0; webgldata.data[n]; n++) { | ||
406 | webgldata.data[n] = unescape(webgldata.data[n]); | ||
407 | } | ||
408 | this._templateDocument.webgl = webgldata.data; | ||
409 | } | ||
410 | |||
392 | 411 | ||
393 | //Adding a handler for the main user document reel to finish loading | 412 | //Adding a handler for the main user document reel to finish loading |
394 | this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); | 413 | this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); |
@@ -430,9 +449,10 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
430 | //Creating tag with file content | 449 | //Creating tag with file content |
431 | tag = this.iframe.contentWindow.document.createElement('style'); | 450 | tag = this.iframe.contentWindow.document.createElement('style'); |
432 | tag.setAttribute('type', 'text/css'); | 451 | tag.setAttribute('type', 'text/css'); |
433 | tag.setAttribute('ninjauri', fileUri); | 452 | tag.setAttribute('data-ninja-uri', fileUri); |
434 | tag.setAttribute('ninjafileurl', cssUrl); | 453 | tag.setAttribute('data-ninja-file-url', cssUrl); |
435 | tag.setAttribute('ninjafilename', cssUrl.split('/')[cssUrl.split('/').length-1]); | 454 | tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly); |
455 | tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); | ||
436 | tag.innerHTML = cssData.content; | 456 | tag.innerHTML = cssData.content; |
437 | //Looping through DOM to insert style tag at location of link element | 457 | //Looping through DOM to insert style tag at location of link element |
438 | query = this._templateDocument.html.querySelectorAll(['link']); | 458 | query = this._templateDocument.html.querySelectorAll(['link']); |
@@ -444,6 +464,38 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
444 | this._templateDocument.head.insertBefore(tag, query[j]); | 464 | this._templateDocument.head.insertBefore(tag, query[j]); |
445 | } | 465 | } |
446 | } | 466 | } |
467 | } else { | ||
468 | /* | ||
469 | //None local stylesheet, probably on a CDN (locked) | ||
470 | tag = this.iframe.contentWindow.document.createElement('style'); | ||
471 | tag.setAttribute('type', 'text/css'); | ||
472 | tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); | ||
473 | tag.setAttribute('data-ninja-file-read-only', "true"); | ||
474 | tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]); | ||
475 | |||
476 | //TODO: Figure out cross-domain XHR issue, might need cloud to handle | ||
477 | var xhr = new XMLHttpRequest(); | ||
478 | xhr.open("GET", this._document.styleSheets[i].href, true); | ||
479 | xhr.send(); | ||
480 | // | ||
481 | if (xhr.readyState === 4) { | ||
482 | console.log(xhr); | ||
483 | } | ||
484 | //tag.innerHTML = xhr.responseText //xhr.response; | ||
485 | |||
486 | //Currently no external styles will load if unable to load via XHR request | ||
487 | |||
488 | //Disabling external style sheets | ||
489 | query = this._templateDocument.html.querySelectorAll(['link']); | ||
490 | for (var j in query) { | ||
491 | if (query[j].href === this._document.styleSheets[i].href) { | ||
492 | //Disabling style sheet to reload via inserting in style tag | ||
493 | query[j].setAttribute('disabled', 'true'); | ||
494 | //Inserting tag | ||
495 | this._templateDocument.head.insertBefore(tag, query[j]); | ||
496 | } | ||
497 | } | ||
498 | */ | ||
447 | } | 499 | } |
448 | } | 500 | } |
449 | } | 501 | } |
@@ -502,6 +554,10 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
502 | 554 | ||
503 | this.callback(this); | 555 | this.callback(this); |
504 | 556 | ||
557 | //Setting webGL data | ||
558 | if (this._templateDocument.webgl) { | ||
559 | this.glData = this._templateDocument.webgl; | ||
560 | } | ||
505 | } | 561 | } |
506 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 562 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
507 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 563 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |