aboutsummaryrefslogtreecommitdiff
path: root/js/mediators/io-mediator.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-05-15 16:05:41 -0700
committerValerio Virgillito2012-05-15 16:05:41 -0700
commit17bbf73c73eadf018b03bb21a7da571901b5a389 (patch)
treebd478adcc531685d874ec186cbb20ea277f55c61 /js/mediators/io-mediator.js
parent3be58f9391cc2ef7f1d27ec69c98ea600cb93a22 (diff)
parent1c91748d8517656c0982c6fc194cd0010d02fb63 (diff)
downloadninja-17bbf73c73eadf018b03bb21a7da571901b5a389.tar.gz
Merge branch 'dom-architecture' of github.com:Motorola-Mobility/ninja-internal into dom-architecture
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r--js/mediators/io-mediator.js59
1 files changed, 48 insertions, 11 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 7a905fc6..8346c75e 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -77,7 +77,7 @@ exports.IoMediator = Montage.create(Component, {
77 //TODO: Improve template data injection 77 //TODO: Improve template data injection
78 function parseTemplate (content, template) { 78 function parseTemplate (content, template) {
79 // 79 //
80 if (template.name.toLowerCase() === 'banner') { 80 if (template.name.toLowerCase() === 'banner' || template.name.toLowerCase() === 'animation') {
81 //Getting dimensions of banner 81 //Getting dimensions of banner
82 var dimensions = template.id.split('x'); 82 var dimensions = template.id.split('x');
83 dimensions = {width: String(dimensions[0])+'px', height: String(dimensions[1])+'px'}; 83 dimensions = {width: String(dimensions[0])+'px', height: String(dimensions[1])+'px'};
@@ -169,7 +169,11 @@ exports.IoMediator = Montage.create(Component, {
169 switch (doc.mode) { 169 switch (doc.mode) {
170 case 'html': 170 case 'html':
171 //Getting content from function to properly handle saving assets (as in external if flagged) 171 //Getting content from function to properly handle saving assets (as in external if flagged)
172 contents = this.parseNinjaTemplateToHtml(doc); 172 if (doc.template && (doc.template.type === 'banner' || doc.template.type === 'animation')) {
173 contents = this.parseNinjaTemplateToHtml(doc, true);
174 } else {
175 contents = this.parseNinjaTemplateToHtml(doc);
176 }
173 break; 177 break;
174 default: 178 default:
175 contents = doc.content; 179 contents = doc.content;
@@ -214,14 +218,20 @@ exports.IoMediator = Montage.create(Component, {
214 //TODO: Expand to allow more templates, clean up variables 218 //TODO: Expand to allow more templates, clean up variables
215 parseNinjaTemplateToHtml: { 219 parseNinjaTemplateToHtml: {
216 enumerable: false, 220 enumerable: false,
217 value: function (template) { 221 value: function (template, ninjaWrapper) {
218 var regexRootUrl, rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])); 222 var regexRootUrl, rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]));
219 regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); 223 regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi');
220 //Injecting head and body into old document 224 //Injecting head and body into old document
221 template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); 225 template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, '');
222 template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); 226 template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, '');
223 227 //Copying attributes to maintain same properties as the <body>
224 228 for (var n in template.body.attributes) {
229 if (template.body.attributes[n].value) {
230 //
231 template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value);
232 }
233 }
234 //TODO: Add attribute copying for <HEAD> and <HTML>
225 235
226 /* 236 /*
227//Testing using montage clean up method 237//Testing using montage clean up method
@@ -446,7 +456,11 @@ exports.IoMediator = Montage.create(Component, {
446 webglrdgetag.setAttribute('type', 'text/javascript'); 456 webglrdgetag.setAttribute('type', 'text/javascript');
447 webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js'); 457 webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js');
448 webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true'); 458 webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true');
449 template.file.content.document.head.appendChild(webglrdgetag); 459 if (ninjaWrapper) {
460 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webglrdgetag);
461 } else {
462 template.file.content.document.head.appendChild(webglrdgetag);
463 }
450 } 464 }
451 // 465 //
452 if (!webgllibtag) { 466 if (!webgllibtag) {
@@ -454,20 +468,32 @@ exports.IoMediator = Montage.create(Component, {
454 webgllibtag.setAttribute('type', 'text/javascript'); 468 webgllibtag.setAttribute('type', 'text/javascript');
455 webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js'); 469 webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js');
456 webgllibtag.setAttribute('data-ninja-webgl-lib', 'true'); 470 webgllibtag.setAttribute('data-ninja-webgl-lib', 'true');
457 template.file.content.document.head.appendChild(webgllibtag); 471 if (ninjaWrapper) {
472 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgllibtag);
473 } else {
474 template.file.content.document.head.appendChild(webgllibtag);
475 }
458 } 476 }
459 // 477 //
460 if (!webgltag) { 478 if (!webgltag) {
461 webgltag = template.file.content.document.createElement('script'); 479 webgltag = template.file.content.document.createElement('script');
462 webgltag.setAttribute('data-ninja-webgl', 'true'); 480 webgltag.setAttribute('data-ninja-webgl', 'true');
463 template.file.content.document.head.appendChild(webgltag); 481 if (ninjaWrapper) {
482 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgltag);
483 } else {
484 template.file.content.document.head.appendChild(webgltag);
485 }
464 } 486 }
465 //TODO: Remove this tag and place inside JS file 487 //TODO: Remove this tag and place inside JS file
466 if (!webgljstag) { 488 if (!webgljstag) {
467 webgljstag = template.file.content.document.createElement('script'); 489 webgljstag = template.file.content.document.createElement('script');
468 webgljstag.setAttribute('type', 'text/javascript'); 490 webgljstag.setAttribute('type', 'text/javascript');
469 webgljstag.setAttribute('data-ninja-webgl-js', 'true'); 491 webgljstag.setAttribute('data-ninja-webgl-js', 'true');
470 template.file.content.document.head.appendChild(webgljstag); 492 if (ninjaWrapper) {
493 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgljstag);
494 } else {
495 template.file.content.document.head.appendChild(webgljstag);
496 }
471 } 497 }
472 //TODO: Decide if this should be over-writter or only written on creation 498 //TODO: Decide if this should be over-writter or only written on creation
473 var rootElement = 'document.body'; //TODO: Set actual root element 499 var rootElement = 'document.body'; //TODO: Set actual root element
@@ -549,10 +575,15 @@ for (var m in template.mjs) {
549 575
550 576
551 577
552 578
553 579
554 //Cleaning URLs from HTML 580 //Cleaning URLs from HTML
555 var cleanHTML = template.file.content.document.documentElement.outerHTML.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaRootUrl.bind(this)); 581 var cleanHTML;
582 if (ninjaWrapper) {
583 cleanHTML = template.file.content.document.body.innerHTML.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaRootUrl.bind(this));
584 } else {
585 cleanHTML = template.file.content.document.documentElement.outerHTML.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaRootUrl.bind(this));
586 }
556 // 587 //
557 function parseNinjaRootUrl(url) { 588 function parseNinjaRootUrl(url) {
558 if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { 589 if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) {
@@ -562,6 +593,12 @@ for (var m in template.mjs) {
562 } 593 }
563 } 594 }
564 // 595 //
596 if (ninjaWrapper) {
597 cleanHTML = cleanHTML.replace(/ninja-viewport/gi, 'div');
598 cleanHTML = cleanHTML.replace(/ninja-content/gi, 'div');
599 }
600
601 //
565 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); 602 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), ''));
566 } 603 }
567 }, 604 },