From 593b2c954cf507bcb61d27f18d63b1406e7364c4 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 22 Feb 2012 22:47:25 -0800 Subject: Cleaning up and commenting CSS IO --- js/controllers/document-controller.js | 11 +++++++++ js/document/html-document.js | 24 ++++++++++--------- js/mediators/io-mediator.js | 43 ++++++++++++++++++++++++++--------- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 48e33267..a6f600cc 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -59,6 +59,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("executeNewFile", this, false); this.eventManager.addEventListener("executeSave", this, false); this.eventManager.addEventListener("executeSaveAs", this, false); + this.eventManager.addEventListener("executeSaveAll", this, false); this.eventManager.addEventListener("recordStyleChanged", this, false); @@ -129,6 +130,16 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } } }, + //////////////////////////////////////////////////////////////////// + //TODO: Check for appropiate structures + handleExecuteSaveAll: { + value: function(event) { + if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ + //Text and HTML document classes should return the same save object for fileSave + this.application.ninja.ioMediator.fileSave(this.activeDocument.saveAll(), this.fileSaveResult.bind(this)); + } + } + }, //////////////////////////////////////////////////////////////////// handleExecuteSaveAs: { value: function(event) { diff --git a/js/document/html-document.js b/js/document/html-document.js index 564daef3..3f417ffc 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -389,8 +389,9 @@ exports.HTMLDocument = Montage.create(TextDocument, { this._window = this.iframe.contentWindow; // for (var k in this._document.styleSheets) { - this._document.styleSheets[k].ninjatemplate = true; - //TODO: Add as attribute + if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) { + this._document.styleSheets[k].ownerNode.setAttribute('ninjatemplate', 'true'); + } } // if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; @@ -449,11 +450,8 @@ exports.HTMLDocument = Montage.create(TextDocument, { //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// - //TODO: Revisit this logic - /* this._styles = this._document.styleSheets[1]; */ - this._stylesheets = this._document.styleSheets; // Entire stlyesheets array - - console.log(this._document.styleSheets); + //TODO: Check if this is needed + this._stylesheets = this._document.styleSheets; //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// @@ -574,8 +572,10 @@ exports.HTMLDocument = Montage.create(TextDocument, { if (this.currentView === 'design') { var styles = []; for (var k in this._document.styleSheets) { - if (!this._document.styleSheets[k].ninjatemplate) { - styles.push(this._document.styleSheets[k]); + if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.getAttribute) { + if (this._document.styleSheets[k].ownerNode.getAttribute('ninjatemplate') === null) { + styles.push(this._document.styleSheets[k]); + } } } return {mode: 'html', document: this._userDocument, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; @@ -595,8 +595,10 @@ exports.HTMLDocument = Montage.create(TextDocument, { if (this.currentView === 'design') { var css = []; for (var k in this._document.styleSheets) { - if (!this._document.styleSheets[k].ninjatemplate) { - css.push(this._document.styleSheets[k]); + if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.getAttribute) { + if (this._document.styleSheets[k].ownerNode.getAttribute('ninjatemplate') === null) { + css.push(this._document.styleSheets[k]); + } } } return {mode: 'html', document: this._userDocument, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index de50f387..7606b168 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -199,55 +199,76 @@ exports.IoMediator = Montage.create(Component, { parseNinjaTemplateToHtml: { enumerable: false, value: function (template) { - // + //TODO: Clean up variables + //Injecting head and body into old document template.document.content.document.body.innerHTML = template.body; template.document.content.document.head.innerHTML = template.head; - // + //Getting all CSS (style or link) tags var styletags = template.document.content.document.getElementsByTagName('style'), linktags = template.document.content.document.getElementsByTagName('link'); - // + //Looping through link tags and removing file recreated elements for (var j in styletags) { if (styletags[j].getAttribute) { if(styletags[j].getAttribute('ninjauri') !== null) { try { + //Checking head first template.document.content.document.head.removeChild(styletags[j]); } catch (e) { try { + //Checking body if not in head template.document.content.document.body.removeChild(styletags[j]); } catch (e) { - // + //Error, not found! } } } } } - // + //TODO: Add logic to only enble tags we disabled for (var l in linktags) { if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) { linktags[l].removeAttribute('disabled'); } } - // + //Checking for type of save: styles =