aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
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
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')
-rwxr-xr-xjs/mediators/element-mediator.js12
-rw-r--r--js/mediators/io-mediator.js82
2 files changed, 81 insertions, 13 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index 51923f08..127f73e1 100755
--- a/js/mediators/element-mediator.js
+++ b/js/mediators/element-mediator.js
@@ -463,7 +463,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
463 getColor: { 463 getColor: {
464 value: function(el, isFill) { 464 value: function(el, isFill) {
465 if(!el.elementModel) { 465 if(!el.elementModel) {
466 NJUtils.makeElementModel2(el); 466 NJUtils.makeModelFromElement(el);
467 } 467 }
468 return el.elementModel.controller["getColor"](el, isFill); 468 return el.elementModel.controller["getColor"](el, isFill);
469 } 469 }
@@ -624,7 +624,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
624 getColor2: { 624 getColor2: {
625 value: function(el, prop, mutator) { 625 value: function(el, prop, mutator) {
626 if(!el.elementModel) { 626 if(!el.elementModel) {
627 NJUtils.makeElementModel2(el); 627 NJUtils.makeModelFromElement(el);
628 } 628 }
629 629
630 return this.getColor(el, (prop === "background")); 630 return this.getColor(el, (prop === "background"));
@@ -636,7 +636,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
636 get3DProperty: { 636 get3DProperty: {
637 value: function(el, prop) { 637 value: function(el, prop) {
638 if(!el.elementModel) { 638 if(!el.elementModel) {
639 NJUtils.makeElementModel2(el); 639 NJUtils.makeModelFromElement(el);
640 } 640 }
641 return el.elementModel.controller["get3DProperty"](el, prop); 641 return el.elementModel.controller["get3DProperty"](el, prop);
642 } 642 }
@@ -645,7 +645,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
645 get3DProperties: { 645 get3DProperties: {
646 value: function(el) { 646 value: function(el) {
647 if(!el.elementModel) { 647 if(!el.elementModel) {
648 NJUtils.makeElementModel2(el); 648 NJUtils.makeModelFromElement(el);
649 } 649 }
650// var mat = this.getMatrix(el); 650// var mat = this.getMatrix(el);
651// var dist = this.getPerspectiveDist(el); 651// var dist = this.getPerspectiveDist(el);
@@ -658,7 +658,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
658 getMatrix: { 658 getMatrix: {
659 value: function(el) { 659 value: function(el) {
660 if(!el.elementModel) { 660 if(!el.elementModel) {
661 NJUtils.makeElementModel2(el); 661 NJUtils.makeModelFromElement(el);
662 } 662 }
663 return el.elementModel.controller["getMatrix"](el); 663 return el.elementModel.controller["getMatrix"](el);
664 } 664 }
@@ -667,7 +667,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
667 getPerspectiveDist: { 667 getPerspectiveDist: {
668 value: function(el) { 668 value: function(el) {
669 if(!el.elementModel) { 669 if(!el.elementModel) {
670 NJUtils.makeElementModel2(el); 670 NJUtils.makeModelFromElement(el);
671 } 671 }
672 return el.elementModel.controller["getPerspectiveDist"](el); 672 return el.elementModel.controller["getPerspectiveDist"](el);
673 } 673 }
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 ////////////////////////////////////////////////////////////////////