From c6b44313ff8bcc17835ca77793bf425c451a4e75 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sat, 25 Feb 2012 16:18:27 -0800 Subject: Cleaning up ninja-data attributes Added logic to load cross-domain CSS from CDN, but need to explore how to load without impacting permissions. --- js/document/html-document.js | 46 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'js/document') 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, { // for (var k in this._document.styleSheets) { if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) { - this._document.styleSheets[k].ownerNode.setAttribute('ninjatemplate', 'true'); + this._document.styleSheets[k].ownerNode.setAttribute('data-ninja-template', 'true'); } } // @@ -449,9 +449,10 @@ exports.HTMLDocument = Montage.create(TextDocument, { //Creating tag with file content tag = this.iframe.contentWindow.document.createElement('style'); tag.setAttribute('type', 'text/css'); - tag.setAttribute('ninjauri', fileUri); - tag.setAttribute('ninjafileurl', cssUrl); - tag.setAttribute('ninjafilename', cssUrl.split('/')[cssUrl.split('/').length-1]); + tag.setAttribute('data-ninja-uri', fileUri); + tag.setAttribute('data-ninja-file-url', cssUrl); + tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly); + tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); tag.innerHTML = cssData.content; //Looping through DOM to insert style tag at location of link element query = this._templateDocument.html.querySelectorAll(['link']); @@ -463,6 +464,43 @@ exports.HTMLDocument = Montage.create(TextDocument, { this._templateDocument.head.insertBefore(tag, query[j]); } } + } else { + //None local stylesheet, probably on a CDN (locked) + //this._document.styleSheets[i].href; + tag = this.iframe.contentWindow.document.createElement('style'); + tag.setAttribute('type', 'text/css'); + tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); + tag.setAttribute('data-ninja-file-read-only', "true"); + tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]); + + + + //TODO: Figure out cross-domain XHR issue, might need cloud to handle + /* +var xhr = new XMLHttpRequest(); + xhr.open("GET", this._document.styleSheets[i].href, true); + xhr.send(); + // + if (xhr.readyState === 4) { + console.log(xhr); + } +*/ + + //TODO: Add rules content + //tag.innerHTML = xhr.responseText //xhr.response; + + + query = this._templateDocument.html.querySelectorAll(['link']); + for (var j in query) { + if (query[j].href === this._document.styleSheets[i].href) { + //Disabling style sheet to reload via inserting in style tag + query[j].setAttribute('disabled', 'true'); + //Inserting tag + this._templateDocument.head.insertBefore(tag, query[j]); + } + } + + } } } -- cgit v1.2.3