diff options
author | Valerio Virgillito | 2012-02-23 01:55:14 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-23 01:55:14 -0800 |
commit | 64a971f63333d74ca89690892a52948b3bd4283a (patch) | |
tree | 61bac34de22852efd2b9b8880f62210685b16297 /js/mediators/io-mediator.js | |
parent | aaa8d05cc3cfd94322d356e265b94b0abb9f6305 (diff) | |
parent | d264092596ba697cd04738566184270dc608be63 (diff) | |
download | ninja-64a971f63333d74ca89690892a52948b3bd4283a.tar.gz |
Merge branch 'FileIO' of github.com:joseeight/ninja-internal into file-io
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r-- | js/mediators/io-mediator.js | 79 |
1 files changed, 73 insertions, 6 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 56869839..4dc29c3c 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -199,13 +199,78 @@ 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 | //TODO: Remove temp fix for styles | 206 | //Getting all CSS (style or link) tags |
206 | if (template.style) { | 207 | var styletags = template.document.content.document.getElementsByTagName('style'), |
207 | template.document.content.document.head.getElementsByTagName('style')[0].innerHTML = this.getCssFromRules(template.style.cssRules); | 208 | linktags = template.document.content.document.getElementsByTagName('link'); |
209 | //Looping through link tags and removing file recreated elements | ||
210 | for (var j in styletags) { | ||
211 | if (styletags[j].getAttribute) { | ||
212 | if(styletags[j].getAttribute('ninjauri') !== null) { | ||
213 | try { | ||
214 | //Checking head first | ||
215 | template.document.content.document.head.removeChild(styletags[j]); | ||
216 | } catch (e) { | ||
217 | try { | ||
218 | //Checking body if not in head | ||
219 | template.document.content.document.body.removeChild(styletags[j]); | ||
220 | } catch (e) { | ||
221 | //Error, not found! | ||
222 | } | ||
223 | } | ||
224 | |||
225 | } | ||
226 | } | ||
208 | } | 227 | } |
228 | //TODO: Add logic to only enble tags we disabled | ||
229 | for (var l in linktags) { | ||
230 | if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) { | ||
231 | linktags[l].removeAttribute('disabled'); | ||
232 | } | ||
233 | } | ||
234 | //Checking for type of save: styles = <style> only | css = <style> and <link> (all CSS) | ||
235 | if (template.styles) { | ||
236 | //Getting all style tags | ||
237 | var styleCounter = 0, | ||
238 | docStyles = template.document.content.document.getElementsByTagName('style'); | ||
239 | //Looping through all style tags | ||
240 | for(var i in template.styles) { | ||
241 | if (template.styles[i].ownerNode) { | ||
242 | if (template.styles[i].ownerNode.getAttribute) { | ||
243 | //Checking for node not to be loaded from file | ||
244 | if (template.styles[i].ownerNode.getAttribute('ninjauri') === null) { | ||
245 | //Inseting data from rules array into tag as string | ||
246 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.styles[i].cssRules); | ||
247 | //Syncing <style> tags count since it might be mixed with <link> | ||
248 | styleCounter++; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | } | ||
253 | } else if (template.css) { | ||
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 | } | ||
272 | } | ||
273 | // | ||
209 | return template.document.content.document.documentElement.outerHTML; | 274 | return template.document.content.document.documentElement.outerHTML; |
210 | } | 275 | } |
211 | }, | 276 | }, |
@@ -215,7 +280,7 @@ exports.IoMediator = Montage.create(Component, { | |||
215 | enumerable: false, | 280 | enumerable: false, |
216 | value: function (list) { | 281 | value: function (list) { |
217 | //Variable to store CSS definitions | 282 | //Variable to store CSS definitions |
218 | var i, str, css = ''; | 283 | var i, str, url, css = ''; |
219 | //Looping through list | 284 | //Looping through list |
220 | if (list && list.length > 0) { | 285 | if (list && list.length > 0) { |
221 | //Adding each list item to string and also adding breaks | 286 | //Adding each list item to string and also adding breaks |
@@ -227,8 +292,10 @@ exports.IoMediator = Montage.create(Component, { | |||
227 | css += '\n'+str; | 292 | css += '\n'+str; |
228 | } | 293 | } |
229 | } | 294 | } |
295 | //TODO: Add better logic for creating this string | ||
296 | url = new RegExp(window.location.protocol+'//'+window.location.host+'/js/document/templates/montage-html/', 'gi'); | ||
230 | //Returning the CSS string | 297 | //Returning the CSS string |
231 | return css; | 298 | return css.replace(url, ''); |
232 | } | 299 | } |
233 | } | 300 | } |
234 | //////////////////////////////////////////////////////////////////// | 301 | //////////////////////////////////////////////////////////////////// |