From 792c83a0fe8f7f22d139684ed6d711a2c334c098 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 17 May 2012 16:55:19 -0700 Subject: Adding component initialization on open This is for opening components, selection is still not reflecting component data. --- js/document/views/design.js | 29 +++++++++-------- js/mediators/io-mediator.js | 78 +++++++++++++++++++++++++-------------------- 2 files changed, 59 insertions(+), 48 deletions(-) (limited to 'js') diff --git a/js/document/views/design.js b/js/document/views/design.js index 2ccb82d1..bd8c25ec 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -184,8 +184,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { this._bodyFragment = null; //Calling standard method to finish opening document this.bodyContentLoaded(null); - - // TODO: Clean up this code + //TODO: Move this to be set via the controller this.application.ninja.stage.documentOffsetLeft = parseInt((this.document.body.scrollWidth - this._template.size.width)/2); this.application.ninja.stage.documentOffsetTop = parseInt((this.document.body.scrollHeight - this._template.size.height)/2); } @@ -243,17 +242,15 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { } } } - //Checking and initializing webGL + //Checking for script tags then parsing check for montage and webgl if (scripttags.length > 0) { + //Checking and initializing webGL this.initWebGl(scripttags); - } //Else there is not data to parse - - - - //TODO: Load Montage Components (blocking) - //this.initMontage(); - - + //Checking and initializing Montage + this.initMontage(scripttags); + } else { + //Else there is not data to parse + } //Makign callback if specified if (this._callback) this._callback(); } @@ -350,8 +347,14 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { //////////////////////////////////////////////////////////////////// // initMontage: { - value: function () { - //initWithDocument(window.document) instantiateWithOwnerAndDocument(null, window.document) + value: function (scripttags) { + // + this.iframe.contentWindow.document.body.addEventListener('mjsTemplateReady', function () { + //Initializing template with user's seriliazation + var template = this.iframe.contentWindow.mjsTemplate.create(); + template.initWithDocument(this.iframe.contentWindow.document); + template.instantiateWithOwnerAndDocument(null, this.iframe.contentWindow.document, function (e){/*Nothing just a required extra parameter*/}); + }.bind(this), false); } }, //////////////////////////////////////////////////////////////////// diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index b1916446..c506e186 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -225,7 +225,7 @@ exports.IoMediator = Montage.create(Component, { mjsCreator = template.mjsTemplateCreator.create(), mJsSerialization, montageTemplate; - // + //Creating instance of template creator montageTemplate = mjsCreator.initWithDocument(template.document); //Setting up expression for parsing URLs regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); @@ -239,7 +239,6 @@ exports.IoMediator = Montage.create(Component, { 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) { @@ -250,6 +249,7 @@ exports.IoMediator = Montage.create(Component, { //TODO: Add attribute copying for and + //console.log(template.file.content.document.getElementsByTagName('html')[0].innerHTML); //Getting all CSS (style or link) tags @@ -266,7 +266,7 @@ exports.IoMediator = Montage.create(Component, { } ////////////////////////////////////////////////// - // + //Adding to tags to be removed form template for (var f in njtemplatetags) { if (njtemplatetags[f].getAttribute) toremovetags.push(njtemplatetags[f]); } @@ -405,6 +405,31 @@ exports.IoMediator = Montage.create(Component, { } } } + // + var matchingtags = [], scripts = template.file.content.document.getElementsByTagName('script'), webgltag, webgljstag, webgllibtag, webglrdgetag, mjstag, mjslibtag; + // + for (var i in scripts) { + if (scripts[i].getAttribute) { + if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll + matchingtags.push(scripts[i]); + } + if (scripts[i].getAttribute('data-ninja-webgl-js') !== null) { + webgljstag = scripts[i]; // TODO: Add logic to delete unneccesary tags + } + if (scripts[i].getAttribute('data-ninja-webgl-lib') !== null) { + webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags + } + 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') { + mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags + } + if (scripts[i].getAttribute('data-mjs-lib') !== null) { + mjslibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags + } + } + } //Checking for webGL elements in document if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix var rdgeDirName, rdgeVersion; @@ -420,31 +445,6 @@ exports.IoMediator = Montage.create(Component, { } } // - var json, matchingtags = [], webgltag, scripts = template.file.content.document.getElementsByTagName('script'), webgljstag, webgllibtag, webglrdgetag, mjstag, mjslibtag; - // - for (var i in scripts) { - if (scripts[i].getAttribute) { - if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll - matchingtags.push(scripts[i]); - } - if (scripts[i].getAttribute('data-ninja-webgl-js') !== null) { - webgljstag = scripts[i]; // TODO: Add logic to delete unneccesary tags - } - if (scripts[i].getAttribute('data-ninja-webgl-lib') !== null) { - webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags - } - 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') { - mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags - } - if (scripts[i].getAttribute('data-mjs-lib') !== null) { - mjslibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags - } - } - } - // if (matchingtags.length) { if (matchingtags.length === 1) { webgltag = matchingtags[0]; @@ -510,7 +510,7 @@ function loadWebGL (e) {\n\ }\ "; //TODO: This data should be saved to a JSON file eventually - json = '\n({\n\t"version": "' + rdgeVersion + '",\n\t"directory": "' + rdgeDirName + '/",\n\t"data": ['; + var json = '\n({\n\t"version": "' + rdgeVersion + '",\n\t"directory": "' + rdgeDirName + '/",\n\t"data": ['; //Looping through data to create escaped array for (var j = 0; template.webgl[j]; j++) { if (j === 0) { @@ -524,11 +524,6 @@ function loadWebGL (e) {\n\ //Setting string in tag webgltag.innerHTML = json; } - - - - - //Checking for Montage if (mJsSerialization) { //Copy Montage library if needed @@ -538,8 +533,21 @@ function loadWebGL (e) {\n\ 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/"}}' }); + var mjsCheck, mjsPath = template.file.root + 'package.json'; + mjsCheck = this.application.ninja.coreIoApi.fileExists({uri: mjsPath}); + // + if (!mjsCheck || mjsCheck.status !== 204) { + var packjson = this.application.ninja.coreIoApi.createFile({ uri: mjsPath, contents: '{"mappings": {"montage": "' + mjsDirName + '/montage/"}}' }); + } else { + //Already exists + } + + + } else { //TODO: Error handle no available library to copy } -- cgit v1.2.3