aboutsummaryrefslogtreecommitdiff
path: root/js/document/html-document.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-02-22 12:05:13 -0800
committerJose Antonio Marquez2012-02-22 12:05:13 -0800
commit27589634d3e8ea52abe8623f8f2cc48ce0aa04c9 (patch)
tree009a7d314f1ddd3211ce36a6b05a8ec19f6b4f3c /js/document/html-document.js
parent9f87a6bb4d37a1e7201dd9452bcb91940733f07d (diff)
downloadninja-27589634d3e8ea52abe8623f8f2cc48ce0aa04c9.tar.gz
Improving temp CSS loading fix
Adding logic to parse the entire DOM and insert the style tag loading the link element content directly above.
Diffstat (limited to 'js/document/html-document.js')
-rwxr-xr-xjs/document/html-document.js35
1 files changed, 21 insertions, 14 deletions
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, {
377 value: function(event){ 377 value: function(event){
378 //TODO: Clean up, using for prototyping save 378 //TODO: Clean up, using for prototyping save
379 this._templateDocument = {}; 379 this._templateDocument = {};
380 this._templateDocument.html = this.iframe.contentWindow.document;
380 this._templateDocument.head = this.iframe.contentWindow.document.getElementById("userHead"); 381 this._templateDocument.head = this.iframe.contentWindow.document.getElementById("userHead");
381 this._templateDocument.body = this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent"); 382 this._templateDocument.body = this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent");
382 //TODO: Remove, also for prototyping 383 //TODO: Remove, also for prototyping
@@ -390,7 +391,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
390 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; 391 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {};
391 //Inserting user's document into template 392 //Inserting user's document into template
392 this._templateDocument.head.innerHTML = this._userDocument.content.head; 393 this._templateDocument.head.innerHTML = this._userDocument.content.head;
393 //this._templateDocument.body.innerHTML = this._userDocument.content.body; 394 this._templateDocument.body.innerHTML = this._userDocument.content.body;
394 395
395 //Adding a handler for the main user document reel to finish loading 396 //Adding a handler for the main user document reel to finish loading
396 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); 397 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false);
@@ -411,36 +412,42 @@ exports.HTMLDocument = Montage.create(TextDocument, {
411 for (var i in this._document.styleSheets) { 412 for (var i in this._document.styleSheets) {
412 //If rules are null, assuming cross-origin issue 413 //If rules are null, assuming cross-origin issue
413 if(this._document.styleSheets[i].rules === null) { 414 if(this._document.styleSheets[i].rules === null) {
414 //Disabling style sheet to reload via inserting in style tag
415 this._document.styleSheets[i].disabled = 'true';
416 //TODO: Revisit URLs and URI creation logic, very hack right now 415 //TODO: Revisit URLs and URI creation logic, very hack right now
417 var fileUri, cssUrl, cssData, tag; 416 var fileUri, cssUrl, cssData, tag, query;
418 if (this._document.styleSheets[i].href.indexOf('js/document/templates/montage-html') !== -1) { 417 if (this._document.styleSheets[i].href.indexOf('js/document/templates/montage-html') !== -1) {
419 //Getting the url of the CSS file 418 //Getting the url of the CSS file
420 cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1]; 419 cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1];
421 //Creating the URI of the file 420 //Creating the URI of the file (this is wrong should not be splitting cssUrl)
422 fileUri = this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl.split('/')[1]; 421 fileUri = this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl.split('/')[1];
423 //Loading the data from the file 422 //Loading the data from the file
424 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); 423 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri});
425 //Creating tag with file content 424 //Creating tag with file content
426 tag = document.createElement('style'); 425 tag = this.iframe.contentWindow.document.createElement('style');
427 tag.ninjauri = fileUri; 426 tag.setAttribute('ninjauri', fileUri);
427 tag.setAttribute('ninjafileurl', cssUrl);
428 tag.innerHTML = cssData.content; 428 tag.innerHTML = cssData.content;
429 this._templateDocument.head.appendChild(tag); 429 //Looping through DOM to insert style tag at location of link element
430 query = this._templateDocument.html.querySelectorAll(['link']);
431 for (var j in query) {
432 if (query[j].href === this._document.styleSheets[i].href) {
433 //Disabling style sheet to reload via inserting in style tag
434 query[j].setAttribute('disabled', 'true');
435 //Inserting tag
436 this._templateDocument.head.insertBefore(tag, query[j]);
437 }
438 }
430 } 439 }
431 } 440 }
432 } 441 }
433 442
434 //TODO: Revisit this logic 443 //TODO: Revisit this logic
435 this._styles = this._document.styleSheets[this._document.styleSheets.length - 1]; 444 this._styles = this._document.styleSheets[1];
436 this._stylesheets = this._document.styleSheets; // Entire stlyesheets array 445 this._stylesheets = this._document.styleSheets; // Entire stlyesheets array
437 446
447 console.log(this._document.styleSheets);
438 448
439 this._templateDocument.body.innerHTML = this._userDocument.content.body; 449 ////////////////////////////////////////////////////////////////////////////
440 450 ////////////////////////////////////////////////////////////////////////////
441
442
443
444 451
445 //TODO Finish this implementation once we start caching Core Elements 452 //TODO Finish this implementation once we start caching Core Elements
446 // Assign a model to the UserContent and add the ViewPort reference to it. 453 // Assign a model to the UserContent and add the ViewPort reference to it.