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 From d4ac479796f0341163e02ba50fa892773212a445 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sat, 25 Feb 2012 16:21:18 -0800 Subject: Cleaning up comments for external styles loading --- js/document/html-document.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'js/document') diff --git a/js/document/html-document.js b/js/document/html-document.js index 4059c2a5..472d15de 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -466,15 +466,12 @@ exports.HTMLDocument = Montage.create(TextDocument, { } } 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(); @@ -484,12 +481,12 @@ var xhr = new XMLHttpRequest(); if (xhr.readyState === 4) { console.log(xhr); } + //tag.innerHTML = xhr.responseText //xhr.response; */ - //TODO: Add rules content - //tag.innerHTML = xhr.responseText //xhr.response; - + //Currently no external styles will load if unable to load via XHR request + //Disabling external style sheets query = this._templateDocument.html.querySelectorAll(['link']); for (var j in query) { if (query[j].href === this._document.styleSheets[i].href) { @@ -499,8 +496,6 @@ var xhr = new XMLHttpRequest(); this._templateDocument.head.insertBefore(tag, query[j]); } } - - } } } -- cgit v1.2.3 From 3638492098a21aef63842366fbfc035fc6414fb0 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sun, 26 Feb 2012 11:32:10 -0800 Subject: Fixed issue with losing track of Ninja template css Also cleaned up URL getter for app in cleaning string code. --- js/document/html-document.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/document') diff --git a/js/document/html-document.js b/js/document/html-document.js index 472d15de..76436732 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -465,7 +465,8 @@ exports.HTMLDocument = Montage.create(TextDocument, { } } } else { - //None local stylesheet, probably on a CDN (locked) + /* +//None local stylesheet, probably on a CDN (locked) tag = this.iframe.contentWindow.document.createElement('style'); tag.setAttribute('type', 'text/css'); tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); @@ -473,8 +474,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { 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(); + var xhr = new XMLHttpRequest(); xhr.open("GET", this._document.styleSheets[i].href, true); xhr.send(); // @@ -482,7 +482,6 @@ var xhr = new XMLHttpRequest(); console.log(xhr); } //tag.innerHTML = xhr.responseText //xhr.response; -*/ //Currently no external styles will load if unable to load via XHR request @@ -496,6 +495,7 @@ var xhr = new XMLHttpRequest(); this._templateDocument.head.insertBefore(tag, query[j]); } } +*/ } } } -- cgit v1.2.3