aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
authorValerio Virgillito2012-05-16 20:33:57 -0700
committerValerio Virgillito2012-05-16 20:33:57 -0700
commit9d001ec773c9568e9f825468631013fc9b20eb7e (patch)
tree6eb6ed621c9d7e4faa9b0b8420e0fe43d48e8256 /js/mediators
parentf48bb7aa60a5eb1f9319ddd0334bd7a0afa2aca4 (diff)
parentd34c57638ef57fb9fedfdb8fa7add895bc585f8e (diff)
downloadninja-9d001ec773c9568e9f825468631013fc9b20eb7e.tar.gz
Merge branch 'dom-architecture' of github.com:Motorola-Mobility/ninja-internal into dom-architecture
Diffstat (limited to 'js/mediators')
-rw-r--r--js/mediators/io-mediator.js84
1 files changed, 41 insertions, 43 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index e6f2cc2d..b1916446 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -219,11 +219,27 @@ exports.IoMediator = Montage.create(Component, {
219 parseNinjaTemplateToHtml: { 219 parseNinjaTemplateToHtml: {
220 enumerable: false, 220 enumerable: false,
221 value: function (template, ninjaWrapper) { 221 value: function (template, ninjaWrapper) {
222 var regexRootUrl, rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])); 222 //TODO: Improve reference for rootUrl
223 var regexRootUrl,
224 rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])),
225 mjsCreator = template.mjsTemplateCreator.create(),
226 mJsSerialization,
227 montageTemplate;
228 //
229 montageTemplate = mjsCreator.initWithDocument(template.document);
230 //Setting up expression for parsing URLs
223 regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); 231 regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi');
224 //Injecting head and body into old document 232 //Injecting head and body into old document
225 template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); 233 if (montageTemplate._ownerSerialization.length > 0) {
226 template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); 234 template.file.content.document.head.innerHTML = montageTemplate._document.head.innerHTML.replace(regexRootUrl, '');
235 template.file.content.document.body.innerHTML = montageTemplate._document.body.innerHTML.replace(regexRootUrl, '');
236 //
237 mJsSerialization = montageTemplate._ownerSerialization;
238 } else {
239 template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, '');
240 template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, '');
241 }
242
227 //Copying attributes to maintain same properties as the <body> 243 //Copying attributes to maintain same properties as the <body>
228 for (var n in template.body.attributes) { 244 for (var n in template.body.attributes) {
229 if (template.body.attributes[n].value) { 245 if (template.body.attributes[n].value) {
@@ -233,15 +249,6 @@ exports.IoMediator = Montage.create(Component, {
233 } 249 }
234 //TODO: Add attribute copying for <HEAD> and <HTML> 250 //TODO: Add attribute copying for <HEAD> and <HTML>
235 251
236 /*
237 var tc = this.application.ninja.documentController.activeDocument.model.views.design.iframe.contentWindow.mjsTemplateCreator, code;
238 code = tc.initWithDocument(this.application.ninja.documentController.activeDocument.model.views.design.iframe.contentWindow.document);
239 console.log(code._ownerSerialization, code._document.getElementsByTagName('html')[0].innerHTML);
240
241 template.file.content.document.head.innerHTML = mjscode._document.head.innerHTML.replace(regexRootUrl, '');
242 template.file.content.document.body.innerHTML = mjscode._document.body.innerHTML.replace(regexRootUrl, '');
243 */
244
245 252
246 253
247 254
@@ -429,7 +436,7 @@ exports.IoMediator = Montage.create(Component, {
429 if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) { 436 if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) {
430 webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags 437 webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags
431 } 438 }
432 if (scripts[i].getAttribute('type') !== 'text/montage-serialization') { 439 if (scripts[i].getAttribute('type') === 'text/montage-serialization') {
433 mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags 440 mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags
434 } 441 }
435 if (scripts[i].getAttribute('data-mjs-lib') !== null) { 442 if (scripts[i].getAttribute('data-mjs-lib') !== null) {
@@ -521,21 +528,10 @@ function loadWebGL (e) {\n\
521 528
522 529
523 530
524 531
525 532 //Checking for Montage
526 533 if (mJsSerialization) {
527 // 534 //Copy Montage library if needed
528
529 /*
530for (var m in template.mjs) {
531 mjsComponents.push(template.mjs[m]);
532 mjsCounter++;
533 }
534 //
535 if (template.mjs && mjsCounter > 0) {
536 var mjsDirName, mjsVersion,
537 mjscode = temp.initWithHeadAndBodyElements(template.file.content.document.documentElement.head, template.file.content.document.documentElement.body, mjsComponents)._ownerSerialization;
538 //Copy Montage library if needed
539 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { 535 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
540 //Checking for Montage library to be available 536 //Checking for Montage library to be available
541 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') { 537 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') {
@@ -543,7 +539,7 @@ for (var m in template.mjs) {
543 mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; 539 mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
544 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName); 540 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName);
545 //TODO: Fix to allow no overwrite and nested locations 541 //TODO: Fix to allow no overwrite and nested locations
546 var packjson = this.application.ninja.coreIoApi.createFile({ uri: template.file.root + 'package.json', contents: '{"mappings": {"montage": "' + mjsDirName + '/"}}' }); 542 var packjson = this.application.ninja.coreIoApi.createFile({ uri: template.file.root + 'package.json', contents: '{"mappings": {"montage": "' + mjsDirName + '/montage/"}}' });
547 } else { 543 } else {
548 //TODO: Error handle no available library to copy 544 //TODO: Error handle no available library to copy
549 } 545 }
@@ -552,27 +548,30 @@ for (var m in template.mjs) {
552 if (!mjslibtag) { 548 if (!mjslibtag) {
553 mjslibtag = template.file.content.document.createElement('script'); 549 mjslibtag = template.file.content.document.createElement('script');
554 mjslibtag.setAttribute('type', 'text/javascript'); 550 mjslibtag.setAttribute('type', 'text/javascript');
555 mjslibtag.setAttribute('src', mjsDirName + '/montage.js'); 551 mjslibtag.setAttribute('src', mjsDirName + '/montage/montage.js');
556 mjslibtag.setAttribute('data-mjs-lib', 'true'); 552 mjslibtag.setAttribute('data-mjs-lib', 'true');
557 template.file.content.document.head.appendChild(mjslibtag); 553 if (ninjaWrapper) {
554 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjslibtag);
555 } else {
556 template.file.content.document.head.appendChild(mjslibtag);
557 }
558
558 } 559 }
559 // 560 //
560 if (!mjstag) { 561 if (!mjstag) {
561 mjstag = template.file.content.document.createElement('script'); 562 mjstag = template.file.content.document.createElement('script');
562 mjstag.setAttribute('type', 'text/montage-serialization'); 563 mjstag.setAttribute('type', 'text/montage-serialization');
563 template.file.content.document.head.appendChild(mjstag); 564 if (ninjaWrapper) {
565 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjstag);
566 } else {
567 template.file.content.document.head.appendChild(mjstag);
568 }
569
564 } 570 }
565 // 571 //
566 mjstag.innerHTML = mjscode; 572 mjstag.innerHTML = mJsSerialization;
567 } 573 mjsCreator = null;
568*/ 574 }
569
570
571
572
573
574
575
576 //Cleaning URLs from HTML 575 //Cleaning URLs from HTML
577 var cleanHTML; 576 var cleanHTML;
578 if (ninjaWrapper) { 577 if (ninjaWrapper) {
@@ -593,7 +592,6 @@ for (var m in template.mjs) {
593 cleanHTML = cleanHTML.replace(/ninja-viewport/gi, 'div'); 592 cleanHTML = cleanHTML.replace(/ninja-viewport/gi, 'div');
594 cleanHTML = cleanHTML.replace(/ninja-content/gi, 'div'); 593 cleanHTML = cleanHTML.replace(/ninja-content/gi, 'div');
595 } 594 }
596
597 // 595 //
598 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); 596 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), ''));
599 } 597 }