From 48beced355a5d4ee959ed41e104b0a343411658c Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 18 May 2012 16:33:10 -0700 Subject: Clean up and adding TODOs --- js/document/document-html.js | 18 +++++++++++++----- js/document/models/base.js | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/js/document/document-html.js b/js/document/document-html.js index 983da966..ae5b73b6 100755 --- a/js/document/document-html.js +++ b/js/document/document-html.js @@ -125,9 +125,10 @@ exports.HtmlDocument = Montage.create(Component, { // closeDocument: { value: function (context, callback) { + //Closing document and getting outcome var closed = this.model.close(null); - - callback.call(context, this); + //Making callback if specified + if (callback) callback.call(context, this); } }, //////////////////////////////////////////////////////////////////// @@ -139,6 +140,7 @@ exports.HtmlDocument = Montage.create(Component, { //this.gridVerticalSpacing = this.application.ninja.stage.drawUtils.gridVerticalSpacing; // Serialize the current scroll position + //TODO: Move these properties to the design view class this.model.scrollLeft = this.application.ninja.stage._scrollLeft; this.model.scrollTop = this.application.ninja.stage._scrollTop; this.model.userContentLeft = this.application.ninja.stage._userContentLeft; @@ -146,6 +148,7 @@ exports.HtmlDocument = Montage.create(Component, { // Serialize the selection + //TODO: Move this property to the design view class this.model.selection = this.application.ninja.selectedElements.slice(0); this.draw3DGrid = this.application.ninja.appModel.show3dGrid; @@ -153,8 +156,10 @@ exports.HtmlDocument = Montage.create(Component, { // TODO: Save the montage undo queue // Pause the videos + //TODO: Move these to be handled on the show/hide methods in the view this.model.views.design.pauseVideos(); - + + //TODO: Move this to the document controller this.model.isActive = false; } }, @@ -167,18 +172,21 @@ exports.HtmlDocument = Montage.create(Component, { //this.application.ninja.stage.drawUtils.gridVerticalSpacing = this.gridVerticalSpacing; // Deserialize the current scroll position + //TODO: Move these properties to the design view class this.application.ninja.stage._scrollLeft = this.model.scrollLeft; this.application.ninja.stage._scrollTop = this.model.scrollTop; this.application.ninja.stage._userContentLeft = this.model.userContentLeft; this.application.ninja.stage._userContentTop = this.model.userContentTop; - + + //TODO: Move this property to the design view class this.application.ninja.selectedElements = this.model.selection.slice(0); this.application.ninja.appModel.show3dGrid = this.draw3DGrid; // Serialize the undo // TODO: Save the montage undo queue - + + //TODO: Move this to the document controller this.model.isActive = true; } } diff --git a/js/document/models/base.js b/js/document/models/base.js index c99e36c7..6d9d2e89 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js @@ -100,7 +100,7 @@ exports.BaseDocumentModel = Montage.create(Component, { } break; default: - if (this.template.type === 'banner' || this.template.type === 'animation') { + if (this.template && (this.template.type === 'banner' || this.template.type === 'animation')) { window.open('/js/document/templates/preview/banner.html?width='+this.template.size.width+'&height='+this.template.size.height+'&url='+this.url); } else { window.open(this.url); -- cgit v1.2.3 From 2994a18010dec4023d904ddc28ca19101f206d6b Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 21 May 2012 12:19:58 -0700 Subject: Adding mappings to Google Components This is just to add correct mappings to Google Montage components in the package.json file generated. --- 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 ade27728..8fe88ee6 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -541,7 +541,7 @@ function loadWebGL (e) {\n\ 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/"}}' }); + var packjson = this.application.ninja.coreIoApi.createFile({ uri: mjsPath, contents: '{"mappings": {\n\t\t"montage": "' + mjsDirName + '/montage/",\n\t\t"montage-google": "' + mjsDirName + '/montage-google/"\n\t}\n}' }); } else { //Already exists } -- cgit v1.2.3 From 11a5be59ff80e0672e9ecf36679be28effb7696c Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 21 May 2012 18:28:38 -0700 Subject: Modifying Canvas Data I/O Changing methods to save all data to external files, this will be optional for the user. Currently save will only save to external files, but UI will allow user to save in file. Need to implement loading data on file open for external file, only works for in file currently. Modified the Runtime file to load all data itself to not bulk up the user document. --- assets/canvas-runtime.js | 32 +++++++++- js/mediators/io-mediator.js | 147 +++++++++++++++++++++++++++++++++----------- 2 files changed, 141 insertions(+), 38 deletions(-) diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index eeafaab6..9bf22313 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js @@ -7,10 +7,38 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot // namespace for the Ninja Canvas Runtime var NinjaCvsRt = NinjaCvsRt || {}; +/////////////////////////////////////////////////////////////////////// +//Loading webGL/canvas data on window load +window.addEventListener('load', loadCanvasData, false); +//Load data function (on document loaded) +function loadCanvasData (e) { + //Cleaning up events + window.removeEventListener('load', loadCanvasData, false); + //Getting tag with data, MUST contain attribute + var xhr, tag = document.querySelectorAll(['script[data-ninja-canvas-lib]'])[0]; + //Checking for data to be external file + if (tag.getAttribute('data-ninja-canvas-json') !== null) { + //Loading JSON data + xhr = new XMLHttpRequest(); + xhr.open("GET", tag.getAttribute('data-ninja-canvas-json'), false); + xhr.send(); + //Checking for data + if (xhr.readyState === 4) { + //Calling method to initialize all webGL/canvas(es) + NinjaCvsRt.initWebGl(document.body, tag.getAttribute('data-ninja-canvas-libpath'), xhr.response); + } else { + //TODO: Add error for users + } + } else {//Data in document itself + //Calling method to initialize all webGL/canvas(es) + NinjaCvsRt.initWebGl(document.body, tag.getAttribute('data-ninja-canvas-libpath'), document.querySelectorAll(['script[data-ninja-canvas]'])[0].innerHTML); + } +} + /////////////////////////////////////////////////////////////////////// //Loading webGL/canvas data -NinjaCvsRt.initWebGl = function (rootElement, directory) { - var cvsDataMngr, ninjaWebGlData = JSON.parse((document.querySelectorAll(['script[data-ninja-webgl]'])[0].innerHTML.replace('(', '')).replace(')', '')); +NinjaCvsRt.initWebGl = function (rootElement, directory, data) { + var cvsDataMngr, ninjaWebGlData = JSON.parse((data.replace('(', '')).replace(')', '')); if (ninjaWebGlData && ninjaWebGlData.data) { for (var n=0; ninjaWebGlData.data[n]; n++) { ninjaWebGlData.data[n] = unescape(ninjaWebGlData.data[n]); diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 8fe88ee6..bbb78a8b 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -203,6 +203,59 @@ exports.IoMediator = Montage.create(Component, { }, //////////////////////////////////////////////////////////////////// // + getDataDirectory: { + value: function (path) { + //TODO: Implement user overwrite + return this._getUserDirectory(path+'data/'); + } + }, + //////////////////////////////////////////////////////////////////// + // + getNinjaDirectory: { + value: function (path) { + //TODO: Implement user overwrite + return this._getUserDirectory(this.getDataDirectory(path)+'ninja/'); + } + }, + //////////////////////////////////////////////////////////////////// + // + getCanvasDirectory: { + value: function (path) { + //TODO: Implement user overwrite + return this._getUserDirectory(this.getNinjaDirectory(path)+'canvas/'); + } + }, + //////////////////////////////////////////////////////////////////// + // + _getUserDirectory: { + value: function (path) { + //Checking for data directory + var check = this.application.ninja.coreIoApi.fileExists({uri: path}), directory; + //Creating directory if doesn't exists + switch (check.status) { + case 204: //Exists + directory = path; + break; + case 404: //Doesn't exists + directory = this.application.ninja.coreIoApi.createDirectory({uri: path}); + //Checking for success + if (directory.status === 201) { + directory = path; + } else { + //Error + directory = null; + } + break; + default: //Error + directory = null; + break; + } + //Returning the path to the directory on disk (null for any error) + return directory; + } + }, + //////////////////////////////////////////////////////////////////// + // parseHtmlToNinjaTemplate: { enumerable: false, value: function (html) { @@ -406,20 +459,19 @@ exports.IoMediator = Montage.create(Component, { } } // - var matchingtags = [], scripts = template.file.content.document.getElementsByTagName('script'), webgltag, webgljstag, webgllibtag, webglrdgetag, mjstag, mjslibtag; + var matchingtags = [], scripts = template.file.content.document.getElementsByTagName('script'), webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag; + //this.getDataDirectory(template.file.root) + //this.getNinjaDirectory(template.file.root) // for (var i in scripts) { if (scripts[i].getAttribute) { - if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll + if (scripts[i].getAttribute('data-ninja-canvas') !== 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) { + if (scripts[i].getAttribute('data-ninja-canvas-lib') !== null) { webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags } - if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) { + if (scripts[i].getAttribute('data-ninja-canvas-rdge') !== null) { webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags } if (scripts[i].getAttribute('type') === 'text/montage-serialization') { @@ -432,7 +484,19 @@ exports.IoMediator = Montage.create(Component, { } //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; + var rdgeDirName, rdgeVersion, cvsDataDir = this.getCanvasDirectory(template.file.root), fileCvsDir, fileCvsDirAppend, cvsDirCounter = 1; + // + if (cvsDataDir) { + fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0]; + if (!this._getUserDirectory(fileCvsDir)) { + fileCvsDirAppend = fileCvsDir+cvsDirCounter; + while (!this._getUserDirectory(fileCvsDirAppend)) { + fileCvsDirAppend = fileCvsDir+(cvsDirCounter++); + } + } + //TODO: Allow user overwrite + fileCvsDir += '/'; + } //Copy webGL library if needed for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { //Checking for RDGE library to be available @@ -453,12 +517,12 @@ exports.IoMediator = Montage.create(Component, { webgltag = matchingtags[matchingtags.length - 1]; //Saving all data to last one... } } - // + //TODO: Add check for file needed if (!webglrdgetag) { webglrdgetag = template.file.content.document.createElement('script'); webglrdgetag.setAttribute('type', 'text/javascript'); webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js'); - webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true'); + webglrdgetag.setAttribute('data-ninja-canvas-rdge', 'true'); if (ninjaWrapper) { template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webglrdgetag); } else { @@ -470,7 +534,7 @@ exports.IoMediator = Montage.create(Component, { webgllibtag = template.file.content.document.createElement('script'); webgllibtag.setAttribute('type', 'text/javascript'); webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js'); - webgllibtag.setAttribute('data-ninja-webgl-lib', 'true'); + webgllibtag.setAttribute('data-ninja-canvas-lib', 'true'); if (ninjaWrapper) { template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgllibtag); } else { @@ -478,51 +542,62 @@ exports.IoMediator = Montage.create(Component, { } } // - if (!webgltag) { + if (!webgltag && !fileCvsDir) { webgltag = template.file.content.document.createElement('script'); - webgltag.setAttribute('data-ninja-webgl', 'true'); + webgltag.setAttribute('data-ninja-canvas', 'true'); if (ninjaWrapper) { template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgltag); } else { template.file.content.document.head.appendChild(webgltag); } } - //TODO: Remove this tag and place inside JS file - if (!webgljstag) { - webgljstag = template.file.content.document.createElement('script'); - webgljstag.setAttribute('type', 'text/javascript'); - webgljstag.setAttribute('data-ninja-webgl-js', 'true'); - if (ninjaWrapper) { - template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgljstag); - } else { - template.file.content.document.head.appendChild(webgljstag); - } - } + //TODO: Decide if this should be over-writter or only written on creation var rootElement = 'document.body'; //TODO: Set actual root element - webgljstag.innerHTML = "\ -//Loading webGL/canvas data on window load\n\ -window.addEventListener('load', loadWebGL, false);\n\ -function loadWebGL (e) {\n\ - window.removeEventListener('load', loadWebGL, false);\n\ - //Calling method to initialize all webGL/canvas(es)\n\ - NinjaCvsRt.initWebGl(" + rootElement + ", '" + rdgeDirName + "/');\n\ -}\ - "; + //TODO: This data should be saved to a JSON file eventually 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) { - json += '\n\t\t\t"' + escape(template.webgl[j]) + '"'; + //if (fileCvsDir) { + // json += '\n\t\t\t"' + template.webgl[j] + '"'; + //} else { + json += '\n\t\t\t"' + escape(template.webgl[j]) + '"'; + //} } else { - json += ',\n\t\t\t"' + escape(template.webgl[j]) + '"'; + //if (fileCvsDir) { + // json += ',\n\t\t\t"' + template.webgl[j] + '"'; + //} else { + json += ',\n\t\t\t"' + escape(template.webgl[j]) + '"'; + //} } } //Closing array (make-shift JSON string to validate data in