aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators')
-rw-r--r--js/mediators/io-mediator.js43
1 files changed, 32 insertions, 11 deletions
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;