From ac750fd9b9c311dcd48c6ee309607edc6fa048e1 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 16 May 2012 14:22:18 -0700 Subject: Adding basic montage components I/O Only for saving basic components without a reel. --- js/mediators/io-mediator.js | 72 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 13 deletions(-) (limited to 'js/mediators/io-mediator.js') 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, { parseNinjaTemplateToHtml: { enumerable: false, value: function (template, ninjaWrapper) { - var regexRootUrl, rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])); + //TODO: Improve reference for rootUrl + var regexRootUrl, + rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), + montageTemplate = template.mjsTemplateCreator.initWithDocument(template.document), + mJsSerialization; + //Setting up expression for parsing URLs regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); //Injecting head and body into old document - template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); - template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); + if (montageTemplate._ownerSerialization.length > 0) { + template.file.content.document.head.innerHTML = montageTemplate._document.head.innerHTML.replace(regexRootUrl, ''); + template.file.content.document.body.innerHTML = montageTemplate._document.body.innerHTML.replace(regexRootUrl, ''); + // + mJsSerialization = montageTemplate._ownerSerialization; + } else { + template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); + template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); + } + //Copying attributes to maintain same properties as the for (var n in template.body.attributes) { if (template.body.attributes[n].value) { @@ -233,15 +246,6 @@ exports.IoMediator = Montage.create(Component, { } //TODO: Add attribute copying for and - /* - var tc = this.application.ninja.documentController.activeDocument.model.views.design.iframe.contentWindow.mjsTemplateCreator, code; - code = tc.initWithDocument(this.application.ninja.documentController.activeDocument.model.views.design.iframe.contentWindow.document); - console.log(code._ownerSerialization, code._document.getElementsByTagName('html')[0].innerHTML); - - template.file.content.document.head.innerHTML = mjscode._document.head.innerHTML.replace(regexRootUrl, ''); - template.file.content.document.body.innerHTML = mjscode._document.body.innerHTML.replace(regexRootUrl, ''); - */ - @@ -521,7 +525,49 @@ function loadWebGL (e) {\n\ - + + //Checking for Montage + if (mJsSerialization) { + //Copy Montage library if needed + for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { + //Checking for Montage library to be available + if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') { + mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); + mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; + this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName); + //TODO: Fix to allow no overwrite and nested locations + var packjson = this.application.ninja.coreIoApi.createFile({ uri: template.file.root + 'package.json', contents: '{"mappings": {"montage": "' + mjsDirName + '/montage/"}}' }); + } else { + //TODO: Error handle no available library to copy + } + } + // + if (!mjslibtag) { + mjslibtag = template.file.content.document.createElement('script'); + mjslibtag.setAttribute('type', 'text/javascript'); + mjslibtag.setAttribute('src', mjsDirName + '/montage/montage.js'); + mjslibtag.setAttribute('data-mjs-lib', 'true'); + if (ninjaWrapper) { + template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjslibtag); + } else { + template.file.content.document.head.appendChild(mjslibtag); + } + + } + // + if (!mjstag) { + mjstag = template.file.content.document.createElement('script'); + mjstag.setAttribute('type', 'text/montage-serialization'); + if (ninjaWrapper) { + template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjstag); + } else { + template.file.content.document.head.appendChild(mjstag); + } + + } + // + mjstag.innerHTML = mJsSerialization; + } // -- cgit v1.2.3