aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-02-22 22:47:25 -0800
committerJose Antonio Marquez2012-02-22 22:47:25 -0800
commit593b2c954cf507bcb61d27f18d63b1406e7364c4 (patch)
tree67590154bd4ec92f4bca1c5c87a04cfffff23a09
parent3524a22fa0745bb223ab6bcc312ca970a001157f (diff)
downloadninja-593b2c954cf507bcb61d27f18d63b1406e7364c4.tar.gz
Cleaning up and commenting CSS IO
-rwxr-xr-xjs/controllers/document-controller.js11
-rwxr-xr-xjs/document/html-document.js24
-rw-r--r--js/mediators/io-mediator.js43
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,
59 this.eventManager.addEventListener("executeNewFile", this, false); 59 this.eventManager.addEventListener("executeNewFile", this, false);
60 this.eventManager.addEventListener("executeSave", this, false); 60 this.eventManager.addEventListener("executeSave", this, false);
61 this.eventManager.addEventListener("executeSaveAs", this, false); 61 this.eventManager.addEventListener("executeSaveAs", this, false);
62 this.eventManager.addEventListener("executeSaveAll", this, false);
62 63
63 this.eventManager.addEventListener("recordStyleChanged", this, false); 64 this.eventManager.addEventListener("recordStyleChanged", this, false);
64 65
@@ -130,6 +131,16 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
130 } 131 }
131 }, 132 },
132 //////////////////////////////////////////////////////////////////// 133 ////////////////////////////////////////////////////////////////////
134 //TODO: Check for appropiate structures
135 handleExecuteSaveAll: {
136 value: function(event) {
137 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
138 //Text and HTML document classes should return the same save object for fileSave
139 this.application.ninja.ioMediator.fileSave(this.activeDocument.saveAll(), this.fileSaveResult.bind(this));
140 }
141 }
142 },
143 ////////////////////////////////////////////////////////////////////
133 handleExecuteSaveAs: { 144 handleExecuteSaveAs: {
134 value: function(event) { 145 value: function(event) {
135 var saveAsSettings = event._event.settings || {}; 146 var saveAsSettings = event._event.settings || {};
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, {
389 this._window = this.iframe.contentWindow; 389 this._window = this.iframe.contentWindow;
390 // 390 //
391 for (var k in this._document.styleSheets) { 391 for (var k in this._document.styleSheets) {
392 this._document.styleSheets[k].ninjatemplate = true; 392 if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) {
393 //TODO: Add as attribute 393 this._document.styleSheets[k].ownerNode.setAttribute('ninjatemplate', 'true');
394 }
394 } 395 }
395 // 396 //
396 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; 397 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {};
@@ -449,11 +450,8 @@ exports.HTMLDocument = Montage.create(TextDocument, {
449 //////////////////////////////////////////////////////////////////////////// 450 ////////////////////////////////////////////////////////////////////////////
450 //////////////////////////////////////////////////////////////////////////// 451 ////////////////////////////////////////////////////////////////////////////
451 452
452 //TODO: Revisit this logic 453 //TODO: Check if this is needed
453 /* this._styles = this._document.styleSheets[1]; */ 454 this._stylesheets = this._document.styleSheets;
454 this._stylesheets = this._document.styleSheets; // Entire stlyesheets array
455
456 console.log(this._document.styleSheets);
457 455
458 //////////////////////////////////////////////////////////////////////////// 456 ////////////////////////////////////////////////////////////////////////////
459 //////////////////////////////////////////////////////////////////////////// 457 ////////////////////////////////////////////////////////////////////////////
@@ -574,8 +572,10 @@ exports.HTMLDocument = Montage.create(TextDocument, {
574 if (this.currentView === 'design') { 572 if (this.currentView === 'design') {
575 var styles = []; 573 var styles = [];
576 for (var k in this._document.styleSheets) { 574 for (var k in this._document.styleSheets) {
577 if (!this._document.styleSheets[k].ninjatemplate) { 575 if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.getAttribute) {
578 styles.push(this._document.styleSheets[k]); 576 if (this._document.styleSheets[k].ownerNode.getAttribute('ninjatemplate') === null) {
577 styles.push(this._document.styleSheets[k]);
578 }
579 } 579 }
580 } 580 }
581 return {mode: 'html', document: this._userDocument, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; 581 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, {
595 if (this.currentView === 'design') { 595 if (this.currentView === 'design') {
596 var css = []; 596 var css = [];
597 for (var k in this._document.styleSheets) { 597 for (var k in this._document.styleSheets) {
598 if (!this._document.styleSheets[k].ninjatemplate) { 598 if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.getAttribute) {
599 css.push(this._document.styleSheets[k]); 599 if (this._document.styleSheets[k].ownerNode.getAttribute('ninjatemplate') === null) {
600 css.push(this._document.styleSheets[k]);
601 }
600 } 602 }
601 } 603 }
602 return {mode: 'html', document: this._userDocument, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; 604 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, {
199 parseNinjaTemplateToHtml: { 199 parseNinjaTemplateToHtml: {
200 enumerable: false, 200 enumerable: false,
201 value: function (template) { 201 value: function (template) {
202 // 202 //TODO: Clean up variables
203 //Injecting head and body into old document
203 template.document.content.document.body.innerHTML = template.body; 204 template.document.content.document.body.innerHTML = template.body;
204 template.document.content.document.head.innerHTML = template.head; 205 template.document.content.document.head.innerHTML = template.head;
205 // 206 //Getting all CSS (style or link) tags
206 var styletags = template.document.content.document.getElementsByTagName('style'), 207 var styletags = template.document.content.document.getElementsByTagName('style'),
207 linktags = template.document.content.document.getElementsByTagName('link'); 208 linktags = template.document.content.document.getElementsByTagName('link');
208 // 209 //Looping through link tags and removing file recreated elements
209 for (var j in styletags) { 210 for (var j in styletags) {
210 if (styletags[j].getAttribute) { 211 if (styletags[j].getAttribute) {
211 if(styletags[j].getAttribute('ninjauri') !== null) { 212 if(styletags[j].getAttribute('ninjauri') !== null) {
212 try { 213 try {
214 //Checking head first
213 template.document.content.document.head.removeChild(styletags[j]); 215 template.document.content.document.head.removeChild(styletags[j]);
214 } catch (e) { 216 } catch (e) {
215 try { 217 try {
218 //Checking body if not in head
216 template.document.content.document.body.removeChild(styletags[j]); 219 template.document.content.document.body.removeChild(styletags[j]);
217 } catch (e) { 220 } catch (e) {
218 // 221 //Error, not found!
219 } 222 }
220 } 223 }
221 224
222 } 225 }
223 } 226 }
224 } 227 }
225 // 228 //TODO: Add logic to only enble tags we disabled
226 for (var l in linktags) { 229 for (var l in linktags) {
227 if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) { 230 if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) {
228 linktags[l].removeAttribute('disabled'); 231 linktags[l].removeAttribute('disabled');
229 } 232 }
230 } 233 }
231 // 234 //Checking for type of save: styles = <style> only | css = <style> and <link> (all CSS)
232 if (template.styles) { 235 if (template.styles) {
233 // 236 //Getting all style tags
234 var styleCounter = 0, 237 var styleCounter = 0,
235 docStyles = template.document.content.document.getElementsByTagName('style'); 238 docStyles = template.document.content.document.getElementsByTagName('style');
239 //Looping through all style tags
236 for(var i in template.styles) { 240 for(var i in template.styles) {
237 if (template.styles[i].ownerNode) { 241 if (template.styles[i].ownerNode) {
238 if (template.styles[i].ownerNode.getAttribute) { 242 if (template.styles[i].ownerNode.getAttribute) {
243 //Checking for node not to be loaded from file
239 if (template.styles[i].ownerNode.getAttribute('ninjauri') === null) { 244 if (template.styles[i].ownerNode.getAttribute('ninjauri') === null) {
240 //console.log(docStyles[styleCounter], template.styles[i].cssRules); 245 //Inseting data from rules array into tag as string
241 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.styles[i].cssRules); 246 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.styles[i].cssRules);
247 //Syncing <style> tags count since it might be mixed with <link>
242 styleCounter++; 248 styleCounter++;
243 } 249 }
244 } 250 }
245 } 251 }
246 } 252 }
247
248 //template.document.content.document.head.getElementsByTagName('style')[0].innerHTML = this.getCssFromRules(template.style.cssRules);
249 } else if (template.css) { 253 } else if (template.css) {
250 console.log('Save all css and style'); 254 //Getting all style and link tags
255 var styleCounter = 0,
256 docStyles = template.document.content.document.getElementsByTagName('style'),
257 docLinks = template.document.content.document.getElementsByTagName('link');
258 for(var i in template.css) {
259 if (template.css[i].ownerNode) {
260 if (template.css[i].ownerNode.getAttribute) {
261 if (template.css[i].ownerNode.getAttribute('ninjauri') === null) {
262 //Inseting data from rules array into <style> as string
263 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules);
264 styleCounter++;
265 } else {
266 //Saving data from rules array converted to string into <link> file
267 var save = this.fio.saveFile({uri: template.css[i].ownerNode.getAttribute('ninjauri'), contents: this.getCssFromRules(template.css[i].cssRules)});
268 }
269 }
270 }
271 }
251 } 272 }
252 // 273 //
253 return template.document.content.document.documentElement.outerHTML; 274 return template.document.content.document.documentElement.outerHTML;