From fda7b595c96d99177fdd93de8da9030348a3f8fb Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sun, 18 Mar 2012 12:34:29 -0700 Subject: Temp I/O functionality for M-JS components Added the ability to save montages component serialization from Ninja. Very rough, but functional. --- js/mediators/io-mediator.js | 70 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 5 deletions(-) (limited to 'js/mediators') diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index d81f4543..01879bac 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -6,10 +6,11 @@ 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, - FileIo = require("js/io/system/fileio").FileIo, - ProjectIo = require("js/io/system/projectio").ProjectIo; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component, + FileIo = require("js/io/system/fileio").FileIo, + ProjectIo = require("js/io/system/projectio").ProjectIo, + TemplateCreator = require("node_modules/tools/template-creator").TemplateCreator; //////////////////////////////////////////////////////////////////////// // exports.IoMediator = Montage.create(Component, { @@ -369,7 +370,7 @@ exports.IoMediator = Montage.create(Component, { } } // - var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'), webgljstag, webgllibtag, webglrdgetag; + var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'), webgljstag, webgllibtag, webglrdgetag, mjstag, mjslibtag; // for (var i in scripts) { if (scripts[i].getAttribute) { @@ -385,6 +386,12 @@ 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') { + 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 + } } } // @@ -451,6 +458,59 @@ function loadWebGL (e) {\n\ //Setting string in tag webgltag.innerHTML = json; } + + + + + // + var mjsCounter = 0, mjsComponents = [], temp = TemplateCreator.create(); + for (var m in template.mjs) { + mjsComponents.push(template.mjs[m]); + mjsCounter++; + } + +// console.log(mjsComponents); + + //console.log(TemplateCreator.) + + if (template.mjs && mjsCounter > 0) { + var mjsDirName, mjsVersion, + mjscode = temp.initWithHeadAndBodyElements(template.document.content.document.documentElement.head, template.document.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.document.root, mjsDirName); + //TODO: Fix to allow no overwrite + var packjson = this.application.ninja.coreIoApi.createFile({uri: template.document.root+'package.json', contents: '{"mappings": {"montage": "'+mjsDirName+'/"}}'}); + } else { + //TODO: Error handle no available library to copy + } + } + // + if (!mjslibtag) { + mjslibtag = template.document.content.document.createElement('script'); + mjslibtag.setAttribute('type', 'text/javascript'); + mjslibtag.setAttribute('src', mjsDirName+'/montage.js'); + mjslibtag.setAttribute('data-mjs-lib', 'true'); + template.document.content.document.head.appendChild(mjslibtag); + } + // + if (!mjstag) { + mjstag = template.document.content.document.createElement('script'); + mjstag.setAttribute('type', 'text/montage-serialization'); + template.document.content.document.head.appendChild(mjstag); + } + // + mjstag.innerHTML = mjscode; + } + + + + + //Cleaning URLs from HTML var cleanHTML = template.document.content.document.documentElement.outerHTML.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaRootUrl.bind(this)); // -- cgit v1.2.3 From 9cb68d376870eea3db3636c30e5fa09d9f71c8cf Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sun, 18 Mar 2012 18:07:40 -0700 Subject: Tests and clean-up --- js/mediators/io-mediator.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'js/mediators') diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 01879bac..18a517a5 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -462,17 +462,17 @@ function loadWebGL (e) {\n\ + + + // var mjsCounter = 0, mjsComponents = [], temp = TemplateCreator.create(); + // for (var m in template.mjs) { mjsComponents.push(template.mjs[m]); mjsCounter++; } - -// console.log(mjsComponents); - - //console.log(TemplateCreator.) - + // if (template.mjs && mjsCounter > 0) { var mjsDirName, mjsVersion, mjscode = temp.initWithHeadAndBodyElements(template.document.content.document.documentElement.head, template.document.content.document.documentElement.body, mjsComponents)._ownerSerialization; @@ -483,7 +483,7 @@ 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.document.root, mjsDirName); - //TODO: Fix to allow no overwrite + //TODO: Fix to allow no overwrite and nested locations var packjson = this.application.ninja.coreIoApi.createFile({uri: template.document.root+'package.json', contents: '{"mappings": {"montage": "'+mjsDirName+'/"}}'}); } else { //TODO: Error handle no available library to copy @@ -511,6 +511,8 @@ function loadWebGL (e) {\n\ + + //Cleaning URLs from HTML var cleanHTML = template.document.content.document.documentElement.outerHTML.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaRootUrl.bind(this)); // -- cgit v1.2.3 From 2557f463c1cfe2d0dd8ea187c184755bd141dab4 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 22 Mar 2012 10:38:44 -0700 Subject: IKNINJA-1302 : For File>New and File>SaveAll dialogs, 'ESC' key now triggers Cancel button and 'Enter' key now triggers OK button. For File picker, the 'ESC' now triggers the Cancel button. Signed-off-by: Ananya Sen Conflicts: js/io/ui/new-file-dialog/new-file-workflow-controller.js Signed-off-by: Ananya Sen --- js/mediators/keyboard-mediator.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'js/mediators') diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js index 65dd34cd..63dcfa88 100755 --- a/js/mediators/keyboard-mediator.js +++ b/js/mediators/keyboard-mediator.js @@ -246,6 +246,35 @@ exports.KeyboardMediator = Montage.create(Component, { return; } + // check for ENTER key + if((evt.keyCode == Keyboard.ENTER) && !(evt.ctrlKey || evt.metaKey)) { + //new file + if((this.application.ninja.newFileController.newFileOptionsNav !== null) + && !this.application.ninja.newFileController.newFileOptionsNav.okButton.hasAttribute("disabled")){ + + this.application.ninja.newFileController.newFileOptionsNav.handleOkButtonAction(); + } + //save as + if((this.application.ninja.newFileController.saveAsDialog !== null) + && !this.application.ninja.newFileController.saveAsDialog.okButton.hasAttribute("disabled")){ + + this.application.ninja.newFileController.saveAsDialog.handleOkButtonAction(); + } + return; + } + //ESC key + if(evt.keyCode === Keyboard.ESCAPE){ + if(this.application.ninja.filePickerController.pickerNavChoices !== null){ + this.application.ninja.filePickerController.pickerNavChoices.handleCancelButtonAction(); + } + if(this.application.ninja.newFileController.newFileOptionsNav !== null){ + this.application.ninja.newFileController.newFileOptionsNav.handleCancelButtonAction(); + } + if(this.application.ninja.newFileController.saveAsDialog !== null){ + this.application.ninja.newFileController.saveAsDialog.handleCancelButtonAction(); + } + return; + } } }, -- cgit v1.2.3 From 80ceeffeb3dd3227008714b8b56383f9556ff409 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 22 Mar 2012 14:49:17 -0700 Subject: KNINJA-1302 : refactored fixed as per request Signed-off-by: Ananya Sen --- js/mediators/keyboard-mediator.js | 31 ------------------------------- 1 file changed, 31 deletions(-) (limited to 'js/mediators') diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js index 63dcfa88..fc0d0f6a 100755 --- a/js/mediators/keyboard-mediator.js +++ b/js/mediators/keyboard-mediator.js @@ -245,37 +245,6 @@ exports.KeyboardMediator = Montage.create(Component, { //menuViewManagerModule.MenuViewManager.closeMenu("mainMenuBar"); return; } - - // check for ENTER key - if((evt.keyCode == Keyboard.ENTER) && !(evt.ctrlKey || evt.metaKey)) { - //new file - if((this.application.ninja.newFileController.newFileOptionsNav !== null) - && !this.application.ninja.newFileController.newFileOptionsNav.okButton.hasAttribute("disabled")){ - - this.application.ninja.newFileController.newFileOptionsNav.handleOkButtonAction(); - } - //save as - if((this.application.ninja.newFileController.saveAsDialog !== null) - && !this.application.ninja.newFileController.saveAsDialog.okButton.hasAttribute("disabled")){ - - this.application.ninja.newFileController.saveAsDialog.handleOkButtonAction(); - } - return; - } - //ESC key - if(evt.keyCode === Keyboard.ESCAPE){ - if(this.application.ninja.filePickerController.pickerNavChoices !== null){ - this.application.ninja.filePickerController.pickerNavChoices.handleCancelButtonAction(); - } - if(this.application.ninja.newFileController.newFileOptionsNav !== null){ - this.application.ninja.newFileController.newFileOptionsNav.handleCancelButtonAction(); - } - if(this.application.ninja.newFileController.saveAsDialog !== null){ - this.application.ninja.newFileController.saveAsDialog.handleCancelButtonAction(); - } - return; - } - } }, -- cgit v1.2.3 From 7fbda862c62f37d4c67e4d5a619b7e3cffc309ff Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 22 Mar 2012 16:23:40 -0700 Subject: Adding Ninja URL method to io-mediator --- js/mediators/io-mediator.js | 56 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'js/mediators') diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 18a517a5..cbed3a99 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -532,8 +532,6 @@ function loadWebGL (e) {\n\ getUrlfromNinjaUrl: { enumerable: false, value: function (url, fileRootUrl, fileUrl) { - //console.log("Params: ", url, fileRootUrl, fileUrl); - //console.log("Getting: " + url); // if (url.indexOf(fileRootUrl) !== -1) { url = url.replace(new RegExp(fileRootUrl.replace(/\//gi, '\\\/'), 'gi'), ''); @@ -561,13 +559,63 @@ function loadWebGL (e) {\n\ // url = (path+newURL).replace(/\/\//gi, '/'); } - //console.log("Returning: " + url); - //console.log("-----"); // return url; } }, //////////////////////////////////////////////////////////////////// + // + getDocRootUrl: { + value: function () { + return this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); + } + }, + //////////////////////////////////////////////////////////////////// + // + getNinjaPropUrlRedirect: { + enumerable: false, + value: function (prop/* , root */) { + //Checking for property value to not contain a full direct URL + if (!prop.match(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi)) { + //Checking for attributes and type of source + if (prop.indexOf('href') !== -1 || prop.indexOf('src') !== -1) { + //From HTML attribute + //if (root) { + //prop = (root+prop).replace(/"([^"]*)"/gi, this.getNinjaUrlPrepend.bind(this)); + //} else { + prop = prop.replace(/"([^"]*)"/gi, this.getNinjaUrlPrepend.bind(this)); + //} + } else if (prop.indexOf('url') !== -1) { + //From CSS property + //if (root) { + //prop = (root+prop).replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl.bind(this)); + //} else { + prop = prop.replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl.bind(this)); + //} + function cssUrlToNinjaUrl (s) { + if (s !== 'url') { + s = this.getDocRootUrl() + s; + } + return s; + } + } + } + return prop; + } + }, + //////////////////////////////////////////////////////////////////// + // + getNinjaUrlPrepend: { + enumerable: false, + value: function (url) { + if (url.indexOf('data:') !== -1) { + return url; + } else { + return '"'+this.getDocRootUrl()+url.replace(/\"/gi, '')+'"'; + } + } + }, + //////////////////////////////////////////////////////////////////// //Method to return a string from CSS rules (to be saved to a file) getCssFromRules: { enumerable: false, -- cgit v1.2.3 From 7e61ce5aba0c8465595804da21e365baf4d8c15d Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 23 Mar 2012 13:22:42 -0700 Subject: Removing m-js components I/O and fix for webGL Removed saving m-js components as new components broke I/O when present. Also made a fix for checking length of webGL array since first item now is non-user data. (That is to be removed) --- js/mediators/io-mediator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/mediators') diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index cbed3a99..1efbb8bb 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -348,7 +348,7 @@ exports.IoMediator = Montage.create(Component, { } } //Checking for webGL elements in document - if (template.webgl && template.webgl.length > 0) { + if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix var rdgeDirName, rdgeVersion; //Copy webGL library if needed for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { -- cgit v1.2.3