aboutsummaryrefslogtreecommitdiff
path: root/js/mediators/io-mediator.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r--js/mediators/io-mediator.js88
1 files changed, 41 insertions, 47 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 8346c75e..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,19 +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//Testing using montage clean up method
238 var mjscode, mjsTemp = TemplateCreator.create();
239
240 //mjscode = mjsTemp.initWithHeadAndBodyElements(template.head, template.body);
241 //mjscode = mjsTemp.initWithDocument(template.file.content.document);
242 mjscode = mjsTemp.initWithDocument(template.document);
243
244 console.log(template.head, mjscode._document.head);
245 template.file.content.document.head.innerHTML = mjscode._document.head.innerHTML.replace(regexRootUrl, '');
246 template.file.content.document.body.innerHTML = mjscode._document.body.innerHTML.replace(regexRootUrl, '');
247*/
248
249 252
250 253
251 254
@@ -433,7 +436,7 @@ exports.IoMediator = Montage.create(Component, {
433 if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) { 436 if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) {
434 webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags 437 webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags
435 } 438 }
436 if (scripts[i].getAttribute('type') !== 'text/montage-serialization') { 439 if (scripts[i].getAttribute('type') === 'text/montage-serialization') {
437 mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags 440 mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags
438 } 441 }
439 if (scripts[i].getAttribute('data-mjs-lib') !== null) { 442 if (scripts[i].getAttribute('data-mjs-lib') !== null) {
@@ -525,21 +528,10 @@ function loadWebGL (e) {\n\
525 528
526 529
527 530
528 531
529 532 //Checking for Montage
530 533 if (mJsSerialization) {
531 // 534 //Copy Montage library if needed
532
533 /*
534for (var m in template.mjs) {
535 mjsComponents.push(template.mjs[m]);
536 mjsCounter++;
537 }
538 //
539 if (template.mjs && mjsCounter > 0) {
540 var mjsDirName, mjsVersion,
541 mjscode = temp.initWithHeadAndBodyElements(template.file.content.document.documentElement.head, template.file.content.document.documentElement.body, mjsComponents)._ownerSerialization;
542 //Copy Montage library if needed
543 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { 535 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
544 //Checking for Montage library to be available 536 //Checking for Montage library to be available
545 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') { 537 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') {
@@ -547,7 +539,7 @@ for (var m in template.mjs) {
547 mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; 539 mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
548 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName); 540 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName);
549 //TODO: Fix to allow no overwrite and nested locations 541 //TODO: Fix to allow no overwrite and nested locations
550 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/"}}' });
551 } else { 543 } else {
552 //TODO: Error handle no available library to copy 544 //TODO: Error handle no available library to copy
553 } 545 }
@@ -556,27 +548,30 @@ for (var m in template.mjs) {
556 if (!mjslibtag) { 548 if (!mjslibtag) {
557 mjslibtag = template.file.content.document.createElement('script'); 549 mjslibtag = template.file.content.document.createElement('script');
558 mjslibtag.setAttribute('type', 'text/javascript'); 550 mjslibtag.setAttribute('type', 'text/javascript');
559 mjslibtag.setAttribute('src', mjsDirName + '/montage.js'); 551 mjslibtag.setAttribute('src', mjsDirName + '/montage/montage.js');
560 mjslibtag.setAttribute('data-mjs-lib', 'true'); 552 mjslibtag.setAttribute('data-mjs-lib', 'true');
561 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
562 } 559 }
563 // 560 //
564 if (!mjstag) { 561 if (!mjstag) {
565 mjstag = template.file.content.document.createElement('script'); 562 mjstag = template.file.content.document.createElement('script');
566 mjstag.setAttribute('type', 'text/montage-serialization'); 563 mjstag.setAttribute('type', 'text/montage-serialization');
567 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
568 } 570 }
569 // 571 //
570 mjstag.innerHTML = mjscode; 572 mjstag.innerHTML = mJsSerialization;
571 } 573 mjsCreator = null;
572*/ 574 }
573
574
575
576
577
578
579
580 //Cleaning URLs from HTML 575 //Cleaning URLs from HTML
581 var cleanHTML; 576 var cleanHTML;
582 if (ninjaWrapper) { 577 if (ninjaWrapper) {
@@ -597,7 +592,6 @@ for (var m in template.mjs) {
597 cleanHTML = cleanHTML.replace(/ninja-viewport/gi, 'div'); 592 cleanHTML = cleanHTML.replace(/ninja-viewport/gi, 'div');
598 cleanHTML = cleanHTML.replace(/ninja-content/gi, 'div'); 593 cleanHTML = cleanHTML.replace(/ninja-content/gi, 'div');
599 } 594 }
600
601 // 595 //
602 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); 596 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), ''));
603 } 597 }