aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-02-21 23:30:01 -0800
committerJose Antonio Marquez2012-02-21 23:30:01 -0800
commite17fb41feca768d746f89d90cef28192fa60c621 (patch)
treefee4c7867a1b6bc87c716998ba6b9890c1662446 /js/document
parent2f24dafec79583547fe663d5a387d8ef15aae3bf (diff)
downloadninja-e17fb41feca768d746f89d90cef28192fa60c621.tar.gz
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.
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/html-document.js43
1 files changed, 37 insertions, 6 deletions
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, {
382 //TODO: Remove, also for prototyping 382 //TODO: Remove, also for prototyping
383 this.application.ninja.documentController._hackRootFlag = true; 383 this.application.ninja.documentController._hackRootFlag = true;
384 // 384 //
385 //this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent");
386 this.stageBG = this.iframe.contentWindow.document.getElementById("stageBG"); 385 this.stageBG = this.iframe.contentWindow.document.getElementById("stageBG");
387 this.stageBG.onclick = null; 386 this.stageBG.onclick = null;
388 this._document = this.iframe.contentWindow.document; 387 this._document = this.iframe.contentWindow.document;
389 this._window = this.iframe.contentWindow; 388 this._window = this.iframe.contentWindow;
390 // 389 //
391 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; 390 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {};
392 // 391 //Inserting user's document into template
393 this._templateDocument.head.innerHTML = this._userDocument.content.head; 392 this._templateDocument.head.innerHTML = this._userDocument.content.head;
394 this._templateDocument.body.innerHTML = this._userDocument.content.body; 393 //this._templateDocument.body.innerHTML = this._userDocument.content.body;
395 394
396 // Adding a handler for the main user document reel to finish loading. 395 //Adding a handler for the main user document reel to finish loading
397 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); 396 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false);
398 397
399 398
400 /* this.iframe.contentWindow.document.addEventListener('DOMSubtreeModified', function (e) { */ //TODO: Remove events upon loading once 399 /* this.iframe.contentWindow.document.addEventListener('DOMSubtreeModified', function (e) { */ //TODO: Remove events upon loading once
401 400
402 //TODO: When written, the best way to initialize the document is to listen for the DOM tree being modified 401 //TODO: When re-written, the best way to initialize the document is to listen for the DOM tree being modified
403 setTimeout(function () { 402 setTimeout(function () {
404 403
405 404
@@ -408,9 +407,41 @@ exports.HTMLDocument = Montage.create(TextDocument, {
408 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 407 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
409 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 408 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
410 if(this._document.styleSheets.length > 1) { 409 if(this._document.styleSheets.length > 1) {
410 //Checking all styleSheets in document
411 for (var i in this._document.styleSheets) {
412 //If rules are null, assuming cross-origin issue
413 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
417 var fileUri, cssUrl, cssData, tag;
418 if (this._document.styleSheets[i].href.indexOf('js/document/templates/montage-html') !== -1) {
419 //Getting the url of the CSS file
420 cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1];
421 //Creating the URI of the file
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];
423 //Loading the data from the file
424 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri});
425 //Creating tag with file content
426 tag = document.createElement('style');
427 tag.ninjauri = fileUri;
428 tag.innerHTML = cssData.content;
429 this._templateDocument.head.appendChild(tag);
430 }
431 }
432 }
433
434 //TODO: Revisit this logic
411 this._styles = this._document.styleSheets[this._document.styleSheets.length - 1]; 435 this._styles = this._document.styleSheets[this._document.styleSheets.length - 1];
412 this._stylesheets = this._document.styleSheets; // Entire stlyesheets array 436 this._stylesheets = this._document.styleSheets; // Entire stlyesheets array
413 437
438
439 this._templateDocument.body.innerHTML = this._userDocument.content.body;
440
441
442
443
444
414 //TODO Finish this implementation once we start caching Core Elements 445 //TODO Finish this implementation once we start caching Core Elements
415 // Assign a model to the UserContent and add the ViewPort reference to it. 446 // Assign a model to the UserContent and add the ViewPort reference to it.
416 NJUtils.makeElementModel(this.documentRoot, "Stage", "stage"); 447 NJUtils.makeElementModel(this.documentRoot, "Stage", "stage");