From e17fb41feca768d746f89d90cef28192fa60c621 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 21 Feb 2012 23:30:01 -0800 Subject: Temp CSS fix (for file open) Implemented temporary work-around to the css-cross-origin issue on files loaded into Ninja. Fix is for open file, need to implement save functionality and integrate with CSS panel. --- js/document/html-document.js | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'js/document') diff --git a/js/document/html-document.js b/js/document/html-document.js index 9a7755e6..bd41bc46 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -382,24 +382,23 @@ exports.HTMLDocument = Montage.create(TextDocument, { //TODO: Remove, also for prototyping this.application.ninja.documentController._hackRootFlag = true; // - //this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent"); this.stageBG = this.iframe.contentWindow.document.getElementById("stageBG"); this.stageBG.onclick = null; this._document = this.iframe.contentWindow.document; this._window = this.iframe.contentWindow; // if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; - // + //Inserting user's document into template this._templateDocument.head.innerHTML = this._userDocument.content.head; - this._templateDocument.body.innerHTML = this._userDocument.content.body; - - // Adding a handler for the main user document reel to finish loading. + //this._templateDocument.body.innerHTML = this._userDocument.content.body; + + //Adding a handler for the main user document reel to finish loading this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); /* this.iframe.contentWindow.document.addEventListener('DOMSubtreeModified', function (e) { */ //TODO: Remove events upon loading once - //TODO: When written, the best way to initialize the document is to listen for the DOM tree being modified + //TODO: When re-written, the best way to initialize the document is to listen for the DOM tree being modified setTimeout(function () { @@ -408,9 +407,41 @@ exports.HTMLDocument = Montage.create(TextDocument, { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if(this._document.styleSheets.length > 1) { + //Checking all styleSheets in document + for (var i in this._document.styleSheets) { + //If rules are null, assuming cross-origin issue + if(this._document.styleSheets[i].rules === null) { + //Disabling style sheet to reload via inserting in style tag + this._document.styleSheets[i].disabled = 'true'; + //TODO: Revisit URLs and URI creation logic, very hack right now + var fileUri, cssUrl, cssData, tag; + if (this._document.styleSheets[i].href.indexOf('js/document/templates/montage-html') !== -1) { + //Getting the url of the CSS file + cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1]; + //Creating the URI of the file + fileUri = this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl.split('/')[1]; + //Loading the data from the file + cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); + //Creating tag with file content + tag = document.createElement('style'); + tag.ninjauri = fileUri; + tag.innerHTML = cssData.content; + this._templateDocument.head.appendChild(tag); + } + } + } + + //TODO: Revisit this logic this._styles = this._document.styleSheets[this._document.styleSheets.length - 1]; this._stylesheets = this._document.styleSheets; // Entire stlyesheets array + + this._templateDocument.body.innerHTML = this._userDocument.content.body; + + + + + //TODO Finish this implementation once we start caching Core Elements // Assign a model to the UserContent and add the ViewPort reference to it. NJUtils.makeElementModel(this.documentRoot, "Stage", "stage"); -- cgit v1.2.3 From 27589634d3e8ea52abe8623f8f2cc48ce0aa04c9 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 22 Feb 2012 12:05:13 -0800 Subject: Improving temp CSS loading fix Adding logic to parse the entire DOM and insert the style tag loading the link element content directly above. --- js/document/html-document.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'js/document') diff --git a/js/document/html-document.js b/js/document/html-document.js index bd41bc46..02e9918f 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -377,6 +377,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { value: function(event){ //TODO: Clean up, using for prototyping save this._templateDocument = {}; + this._templateDocument.html = this.iframe.contentWindow.document; this._templateDocument.head = this.iframe.contentWindow.document.getElementById("userHead"); this._templateDocument.body = this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent"); //TODO: Remove, also for prototyping @@ -390,7 +391,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; //Inserting user's document into template this._templateDocument.head.innerHTML = this._userDocument.content.head; - //this._templateDocument.body.innerHTML = this._userDocument.content.body; + this._templateDocument.body.innerHTML = this._userDocument.content.body; //Adding a handler for the main user document reel to finish loading this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); @@ -411,36 +412,42 @@ exports.HTMLDocument = Montage.create(TextDocument, { for (var i in this._document.styleSheets) { //If rules are null, assuming cross-origin issue if(this._document.styleSheets[i].rules === null) { - //Disabling style sheet to reload via inserting in style tag - this._document.styleSheets[i].disabled = 'true'; //TODO: Revisit URLs and URI creation logic, very hack right now - var fileUri, cssUrl, cssData, tag; + var fileUri, cssUrl, cssData, tag, query; if (this._document.styleSheets[i].href.indexOf('js/document/templates/montage-html') !== -1) { //Getting the url of the CSS file cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1]; - //Creating the URI of the file + //Creating the URI of the file (this is wrong should not be splitting cssUrl) fileUri = this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl.split('/')[1]; //Loading the data from the file cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); //Creating tag with file content - tag = document.createElement('style'); - tag.ninjauri = fileUri; + tag = this.iframe.contentWindow.document.createElement('style'); + tag.setAttribute('ninjauri', fileUri); + tag.setAttribute('ninjafileurl', cssUrl); tag.innerHTML = cssData.content; - this._templateDocument.head.appendChild(tag); + //Looping through DOM to insert style tag at location of link element + 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]); + } + } } } } //TODO: Revisit this logic - this._styles = this._document.styleSheets[this._document.styleSheets.length - 1]; + this._styles = this._document.styleSheets[1]; this._stylesheets = this._document.styleSheets; // Entire stlyesheets array + console.log(this._document.styleSheets); - this._templateDocument.body.innerHTML = this._userDocument.content.body; - - - - + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// //TODO Finish this implementation once we start caching Core Elements // Assign a model to the UserContent and add the ViewPort reference to it. -- cgit v1.2.3 From 5da4627fe899c03e885d10a77a5e33bb15875504 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 22 Feb 2012 13:38:09 -0800 Subject: Removed css not needed in Ninja Template --- js/document/html-document.js | 1 + js/document/templates/montage-html/index.html | 1 - js/document/templates/montage-html/styles.css | 5 ----- 3 files changed, 1 insertion(+), 6 deletions(-) delete mode 100755 js/document/templates/montage-html/styles.css (limited to 'js/document') diff --git a/js/document/html-document.js b/js/document/html-document.js index 02e9918f..ba5eea79 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -425,6 +425,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { tag = this.iframe.contentWindow.document.createElement('style'); tag.setAttribute('ninjauri', fileUri); tag.setAttribute('ninjafileurl', cssUrl); + tag.setAttribute('ninjafilename', 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']); diff --git a/js/document/templates/montage-html/index.html b/js/document/templates/montage-html/index.html index 8b3d73bb..edfab2b0 100755 --- a/js/document/templates/montage-html/index.html +++ b/js/document/templates/montage-html/index.html @@ -12,7 +12,6 @@ Ninja Prototype - diff --git a/js/document/templates/montage-html/styles.css b/js/document/templates/montage-html/styles.css deleted file mode 100755 index 0441c1cf..00000000 --- a/js/document/templates/montage-html/styles.css +++ /dev/null @@ -1,5 +0,0 @@ -/* - This file contains proprietary software owned by Motorola Mobility, Inc.
- No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
- (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. -
*/ \ No newline at end of file -- cgit v1.2.3 From 3524a22fa0745bb223ab6bcc312ca970a001157f Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 22 Feb 2012 16:45:19 -0800 Subject: Logic to save