aboutsummaryrefslogtreecommitdiff
path: root/js/mediators/io-mediator.js
diff options
context:
space:
mode:
authorAnanya Sen2012-02-23 13:52:32 -0800
committerAnanya Sen2012-02-23 13:52:32 -0800
commitec3d07c2fea4e79c68606234074f43d694982e5b (patch)
treedc7c830c361d35c04a4d9b6d55c6c36d7a5d61cd /js/mediators/io-mediator.js
parent7283884c39df537694b21419a3ea9e3ca7793b4b (diff)
parent287a0bad5b774a380ec6c8b3ddf24dc03234e248 (diff)
downloadninja-ec3d07c2fea4e79c68606234074f43d694982e5b.tar.gz
Merge branch 'refs/heads/FileIO-jose' into FileIO
Conflicts: js/document/html-document.js js/helper-classes/3D/snap-manager.js Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r--js/mediators/io-mediator.js82
1 files changed, 75 insertions, 7 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 56869839..c4f3b361 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -199,14 +199,80 @@ 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 url = new RegExp(window.location.protocol+'//'+window.location.host+'/js/document/templates/montage-html/', 'gi');
210 //Looping through link tags and removing file recreated elements
211 for (var j in styletags) {
212 if (styletags[j].getAttribute) {
213 if(styletags[j].getAttribute('ninjauri') !== null) {
214 try {
215 //Checking head first
216 template.document.content.document.head.removeChild(styletags[j]);
217 } catch (e) {
218 try {
219 //Checking body if not in head
220 template.document.content.document.body.removeChild(styletags[j]);
221 } catch (e) {
222 //Error, not found!
223 }
224 }
225
226 }
227 }
208 } 228 }
209 return template.document.content.document.documentElement.outerHTML; 229 //TODO: Add logic to only enble tags we disabled
230 for (var l in linktags) {
231 if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) {
232 linktags[l].removeAttribute('disabled');
233 }
234 }
235 //Checking for type of save: styles = <style> only | css = <style> and <link> (all CSS)
236 if (template.styles) {
237 //Getting all style tags
238 var styleCounter = 0,
239 docStyles = template.document.content.document.getElementsByTagName('style');
240 //Looping through all style tags
241 for(var i in template.styles) {
242 if (template.styles[i].ownerNode) {
243 if (template.styles[i].ownerNode.getAttribute) {
244 //Checking for node not to be loaded from file
245 if (template.styles[i].ownerNode.getAttribute('ninjauri') === null) {
246 //Inseting data from rules array into tag as string
247 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.styles[i].cssRules);
248 //Syncing <style> tags count since it might be mixed with <link>
249 styleCounter++;
250 }
251 }
252 }
253 }
254 } else if (template.css) {
255 //Getting all style and link tags
256 var styleCounter = 0,
257 docStyles = template.document.content.document.getElementsByTagName('style'),
258 docLinks = template.document.content.document.getElementsByTagName('link');
259 for(var i in template.css) {
260 if (template.css[i].ownerNode) {
261 if (template.css[i].ownerNode.getAttribute) {
262 if (template.css[i].ownerNode.getAttribute('ninjauri') === null) {
263 //Inseting data from rules array into <style> as string
264 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules);
265 styleCounter++;
266 } else {
267 //Saving data from rules array converted to string into <link> file
268 var save = this.fio.saveFile({uri: template.css[i].ownerNode.getAttribute('ninjauri'), contents: this.getCssFromRules(template.css[i].cssRules)});
269 }
270 }
271 }
272 }
273 }
274 //
275 return template.document.content.document.documentElement.outerHTML.replace(url, '');
210 } 276 }
211 }, 277 },
212 //////////////////////////////////////////////////////////////////// 278 ////////////////////////////////////////////////////////////////////
@@ -215,7 +281,7 @@ exports.IoMediator = Montage.create(Component, {
215 enumerable: false, 281 enumerable: false,
216 value: function (list) { 282 value: function (list) {
217 //Variable to store CSS definitions 283 //Variable to store CSS definitions
218 var i, str, css = ''; 284 var i, str, url, css = '';
219 //Looping through list 285 //Looping through list
220 if (list && list.length > 0) { 286 if (list && list.length > 0) {
221 //Adding each list item to string and also adding breaks 287 //Adding each list item to string and also adding breaks
@@ -227,8 +293,10 @@ exports.IoMediator = Montage.create(Component, {
227 css += '\n'+str; 293 css += '\n'+str;
228 } 294 }
229 } 295 }
296 //TODO: Add better logic for creating this string
297 url = new RegExp(window.location.protocol+'//'+window.location.host+'/js/document/templates/montage-html/', 'gi');
230 //Returning the CSS string 298 //Returning the CSS string
231 return css; 299 return css.replace(url, '');
232 } 300 }
233 } 301 }
234 //////////////////////////////////////////////////////////////////// 302 ////////////////////////////////////////////////////////////////////