aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/html-document.js46
1 files changed, 42 insertions, 4 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 1901079d..4059c2a5 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,43 @@ 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 //None local stylesheet, probably on a CDN (locked)
469 //this._document.styleSheets[i].href;
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
477
478 //TODO: Figure out cross-domain XHR issue, might need cloud to handle
479 /*
480var xhr = new XMLHttpRequest();
481 xhr.open("GET", this._document.styleSheets[i].href, true);
482 xhr.send();
483 //
484 if (xhr.readyState === 4) {
485 console.log(xhr);
486 }
487*/
488
489 //TODO: Add rules content
490 //tag.innerHTML = xhr.responseText //xhr.response;
491
492
493 query = this._templateDocument.html.querySelectorAll(['link']);
494 for (var j in query) {
495 if (query[j].href === this._document.styleSheets[i].href) {
496 //Disabling style sheet to reload via inserting in style tag
497 query[j].setAttribute('disabled', 'true');
498 //Inserting tag
499 this._templateDocument.head.insertBefore(tag, query[j]);
500 }
501 }
502
503
466 } 504 }
467 } 505 }
468 } 506 }