aboutsummaryrefslogtreecommitdiff
path: root/js/document/html-document.js
diff options
context:
space:
mode:
authorJose Antonio Marquez Russo2012-02-26 11:55:39 -0800
committerJose Antonio Marquez Russo2012-02-26 11:55:39 -0800
commitc65eb4b983e8020346cda4dc7bcb050cb1a410e1 (patch)
treee9ffbe4e14d687b38369817848d6dace50bda21f /js/document/html-document.js
parent97c0efb645b1e0488112c1b7bfd7fa4864eae3dc (diff)
parente67540d23a1bd5d2480ce47634c0cbe523dd5e4a (diff)
downloadninja-c65eb4b983e8020346cda4dc7bcb050cb1a410e1.tar.gz
Merge pull request #20 from joseeight/FileIO
File IO Updates
Diffstat (limited to 'js/document/html-document.js')
-rwxr-xr-xjs/document/html-document.js41
1 files changed, 37 insertions, 4 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 1901079d..76436732 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -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 //
@@ -449,9 +449,10 @@ exports.HTMLDocument = Montage.create(TextDocument, {
449 //Creating tag with file content 449 //Creating tag with file content
450 tag = this.iframe.contentWindow.document.createElement('style'); 450 tag = this.iframe.contentWindow.document.createElement('style');
451 tag.setAttribute('type', 'text/css'); 451 tag.setAttribute('type', 'text/css');
452 tag.setAttribute('ninjauri', fileUri); 452 tag.setAttribute('data-ninja-uri', fileUri);
453 tag.setAttribute('ninjafileurl', cssUrl); 453 tag.setAttribute('data-ninja-file-url', cssUrl);
454 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]);
455 tag.innerHTML = cssData.content; 456 tag.innerHTML = cssData.content;
456 //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
457 query = this._templateDocument.html.querySelectorAll(['link']); 458 query = this._templateDocument.html.querySelectorAll(['link']);
@@ -463,6 +464,38 @@ exports.HTMLDocument = Montage.create(TextDocument, {
463 this._templateDocument.head.insertBefore(tag, query[j]); 464 this._templateDocument.head.insertBefore(tag, query[j]);
464 } 465 }
465 } 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*/
466 } 499 }
467 } 500 }
468 } 501 }