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/document/models/base.js | 6 +- js/document/templates/html/main.js | 2 +- js/mediators/io-mediator.js | 72 ++++++++++++++++++---- .../components-panel.reel/components-panel.js | 6 +- 4 files changed, 67 insertions(+), 19 deletions(-) diff --git a/js/document/models/base.js b/js/document/models/base.js index 033e16f6..649539ea 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js @@ -149,7 +149,8 @@ exports.BaseDocumentModel = Montage.create(Component, { template: this.fileTemplate, document: this.views.design.iframe.contentWindow.document, head: this.views.design.iframe.contentWindow.document.head, - body: this.views.design.iframe.contentWindow.document.body + body: this.views.design.iframe.contentWindow.document.body, + mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator }, callback.bind(this)); } else { //TODO: Add logic to save code view data @@ -177,7 +178,8 @@ exports.BaseDocumentModel = Montage.create(Component, { template: this.fileTemplate, document: this.views.design.iframe.contentWindow.document, head: this.views.design.iframe.contentWindow.document.head, - body: this.views.design.iframe.contentWindow.document.body + body: this.views.design.iframe.contentWindow.document.body, + mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator }, callback.bind(this)); } else { //TODO: Add logic to save code view data diff --git a/js/document/templates/html/main.js b/js/document/templates/html/main.js index f45657bb..2696dfa0 100644 --- a/js/document/templates/html/main.js +++ b/js/document/templates/html/main.js @@ -42,7 +42,7 @@ exports.Main = Montage.create(Component, { // window.mjsTemplateCreator = TemplateCreator.create(); // - window.mjsTemplate = Template.create(); + window.mjsTemplate = Template.create(); // Dispatch event when this template has loaded. 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; + } // diff --git a/js/panels/components-panel.reel/components-panel.js b/js/panels/components-panel.reel/components-panel.js index 53049cad..fdf744d2 100755 --- a/js/panels/components-panel.reel/components-panel.js +++ b/js/panels/components-panel.reel/components-panel.js @@ -6,9 +6,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component, - ClassUUID = require("js/components/core/class-uuid").ClassUuid; - -var PIData = require("js/data/pi/pi-data").PiData; + NJUtils = require("js/lib/NJUtils").NJUtils; + ClassUUID = require("js/components/core/class-uuid").ClassUuid, + PIData = require("js/data/pi/pi-data").PiData; String.prototype.capitalizeFirstChar = function() { return this.charAt(0).toUpperCase() + this.slice(1); -- cgit v1.2.3 From a2afa558aba65b81f8b1b58687629def14ea471d Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 16 May 2012 14:37:32 -0700 Subject: Fixing reference to serialization tag --- js/mediators/io-mediator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 6cdf70fe..7f7bd72a 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -433,7 +433,7 @@ exports.IoMediator = Montage.create(Component, { if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) { webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags } - if (scripts[i].getAttribute('type') !== 'text/montage-serialization') { + if (scripts[i].getAttribute('type') === 'text/montage-serialization') { mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags } if (scripts[i].getAttribute('data-mjs-lib') !== null) { -- cgit v1.2.3 From 5cc5d29736d8bf253e3a168cdd6443e839ffb23c Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 16 May 2012 15:42:09 -0700 Subject: Fixing serialization referencing (new object per save) --- js/document/templates/html/main.js | 4 +-- js/mediators/io-mediator.js | 60 ++++---------------------------------- 2 files changed, 8 insertions(+), 56 deletions(-) diff --git a/js/document/templates/html/main.js b/js/document/templates/html/main.js index 2696dfa0..ffa3fab2 100644 --- a/js/document/templates/html/main.js +++ b/js/document/templates/html/main.js @@ -40,9 +40,9 @@ exports.Main = Montage.create(Component, { }; // - window.mjsTemplateCreator = TemplateCreator.create(); + window.mjsTemplateCreator = TemplateCreator; // - window.mjsTemplate = Template.create(); + window.mjsTemplate = Template; // Dispatch event when this template has loaded. diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 7f7bd72a..b1916446 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -222,8 +222,11 @@ exports.IoMediator = Montage.create(Component, { //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; + mjsCreator = template.mjsTemplateCreator.create(), + mJsSerialization, + montageTemplate; + // + montageTemplate = mjsCreator.initWithDocument(template.document); //Setting up expression for parsing URLs regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); //Injecting head and body into old document @@ -567,58 +570,8 @@ function loadWebGL (e) {\n\ } // mjstag.innerHTML = mJsSerialization; + mjsCreator = null; } - - - // - - /* -for (var m in template.mjs) { - mjsComponents.push(template.mjs[m]); - mjsCounter++; - } - // - if (template.mjs && mjsCounter > 0) { - var mjsDirName, mjsVersion, - mjscode = temp.initWithHeadAndBodyElements(template.file.content.document.documentElement.head, template.file.content.document.documentElement.body, mjsComponents)._ownerSerialization; - //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 + '/"}}' }); - } 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.js'); - mjslibtag.setAttribute('data-mjs-lib', 'true'); - template.file.content.document.head.appendChild(mjslibtag); - } - // - if (!mjstag) { - mjstag = template.file.content.document.createElement('script'); - mjstag.setAttribute('type', 'text/montage-serialization'); - template.file.content.document.head.appendChild(mjstag); - } - // - mjstag.innerHTML = mjscode; - } -*/ - - - - - - - //Cleaning URLs from HTML var cleanHTML; if (ninjaWrapper) { @@ -639,7 +592,6 @@ for (var m in template.mjs) { cleanHTML = cleanHTML.replace(/ninja-viewport/gi, 'div'); cleanHTML = cleanHTML.replace(/ninja-content/gi, 'div'); } - // return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); } -- cgit v1.2.3