diff options
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r-- | js/mediators/io-mediator.js | 72 |
1 files changed, 59 insertions, 13 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index e6f2cc2d..6cdf70fe 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -219,11 +219,24 @@ 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 | montageTemplate = template.mjsTemplateCreator.initWithDocument(template.document), | ||
226 | mJsSerialization; | ||
227 | //Setting up expression for parsing URLs | ||
223 | regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); | 228 | regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); |
224 | //Injecting head and body into old document | 229 | //Injecting head and body into old document |
225 | template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); | 230 | if (montageTemplate._ownerSerialization.length > 0) { |
226 | template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); | 231 | template.file.content.document.head.innerHTML = montageTemplate._document.head.innerHTML.replace(regexRootUrl, ''); |
232 | template.file.content.document.body.innerHTML = montageTemplate._document.body.innerHTML.replace(regexRootUrl, ''); | ||
233 | // | ||
234 | mJsSerialization = montageTemplate._ownerSerialization; | ||
235 | } else { | ||
236 | template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); | ||
237 | template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); | ||
238 | } | ||
239 | |||
227 | //Copying attributes to maintain same properties as the <body> | 240 | //Copying attributes to maintain same properties as the <body> |
228 | for (var n in template.body.attributes) { | 241 | for (var n in template.body.attributes) { |
229 | if (template.body.attributes[n].value) { | 242 | if (template.body.attributes[n].value) { |
@@ -233,15 +246,6 @@ exports.IoMediator = Montage.create(Component, { | |||
233 | } | 246 | } |
234 | //TODO: Add attribute copying for <HEAD> and <HTML> | 247 | //TODO: Add attribute copying for <HEAD> and <HTML> |
235 | 248 | ||
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 | 249 | ||
246 | 250 | ||
247 | 251 | ||
@@ -521,7 +525,49 @@ function loadWebGL (e) {\n\ | |||
521 | 525 | ||
522 | 526 | ||
523 | 527 | ||
524 | 528 | ||
529 | //Checking for Montage | ||
530 | if (mJsSerialization) { | ||
531 | //Copy Montage library if needed | ||
532 | for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { | ||
533 | //Checking for Montage library to be available | ||
534 | if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') { | ||
535 | mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); | ||
536 | mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; | ||
537 | this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName); | ||
538 | //TODO: Fix to allow no overwrite and nested locations | ||
539 | var packjson = this.application.ninja.coreIoApi.createFile({ uri: template.file.root + 'package.json', contents: '{"mappings": {"montage": "' + mjsDirName + '/montage/"}}' }); | ||
540 | } else { | ||
541 | //TODO: Error handle no available library to copy | ||
542 | } | ||
543 | } | ||
544 | // | ||
545 | if (!mjslibtag) { | ||
546 | mjslibtag = template.file.content.document.createElement('script'); | ||
547 | mjslibtag.setAttribute('type', 'text/javascript'); | ||
548 | mjslibtag.setAttribute('src', mjsDirName + '/montage/montage.js'); | ||
549 | mjslibtag.setAttribute('data-mjs-lib', 'true'); | ||
550 | if (ninjaWrapper) { | ||
551 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjslibtag); | ||
552 | } else { | ||
553 | template.file.content.document.head.appendChild(mjslibtag); | ||
554 | } | ||
555 | |||
556 | } | ||
557 | // | ||
558 | if (!mjstag) { | ||
559 | mjstag = template.file.content.document.createElement('script'); | ||
560 | mjstag.setAttribute('type', 'text/montage-serialization'); | ||
561 | if (ninjaWrapper) { | ||
562 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjstag); | ||
563 | } else { | ||
564 | template.file.content.document.head.appendChild(mjstag); | ||
565 | } | ||
566 | |||
567 | } | ||
568 | // | ||
569 | mjstag.innerHTML = mJsSerialization; | ||
570 | } | ||
525 | 571 | ||
526 | 572 | ||
527 | // | 573 | // |