From e065244ac75d1d0f25fd5c75cb58e714a13fe16b Mon Sep 17 00:00:00 2001 From: Jonathan Duran Date: Wed, 14 Mar 2012 08:59:17 -0700 Subject: Squashed commit of the following: merge master into timeline Signed-off-by: Jonathan Duran --- js/mediators/element-mediator.js | 15 +------ js/mediators/io-mediator.js | 93 +++++++++++++++++++++++++++++++--------- 2 files changed, 74 insertions(+), 34 deletions(-) (limited to 'js/mediators') diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 127f73e1..d62fa1f8 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js @@ -459,13 +459,12 @@ exports.ElementMediator = Montage.create(NJComponent, { //-------------------------------------------------------------------------------------------------------- // Routines to get/set color - // for now just return the bg/fill color getColor: { - value: function(el, isFill) { + value: function(el, isFill, borderSide) { if(!el.elementModel) { NJUtils.makeModelFromElement(el); } - return el.elementModel.controller["getColor"](el, isFill); + return el.elementModel.controller["getColor"](el, isFill, borderSide); } }, @@ -621,16 +620,6 @@ exports.ElementMediator = Montage.create(NJComponent, { } }, - getColor2: { - value: function(el, prop, mutator) { - if(!el.elementModel) { - NJUtils.makeModelFromElement(el); - } - - return this.getColor(el, (prop === "background")); - } - }, - //-------------------------------------------------------------------------------------------------------- // Routines to get/set 3D properties get3DProperty: { diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index dcafb38d..d81f4543 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -152,17 +152,7 @@ exports.IoMediator = Montage.create(Component, { // switch (file.mode) { case 'html': - //Copy webGL library if needed - if (file.webgl && file.webgl.length > 0) { - for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { - //Checking for RDGE library to be available - if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { - this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(file.document.root, (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase()); - } else { - //TODO: Error handle no available library to copy - } - } - } + //TODO: Add check for Monatage library to copy @@ -357,15 +347,44 @@ exports.IoMediator = Montage.create(Component, { } } //Checking for webGL elements in document - if (template.webgl && template.webgl.length) { + if (template.webgl && template.webgl.length > 0) { + var rdgeDirName, rdgeVersion; + //Copy webGL library if needed + for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { + //Checking for RDGE library to be available + if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { + rdgeDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); + rdgeVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; + this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.document.root, rdgeDirName, hackRename.bind(this)); + //TODO: Remove, this is copying the library into a static name + function hackRename (status) { + if (status) { + setTimeout(function () { + this.application.ninja.coreIoApi.copyDirectory({sourceUri: template.document.root+rdgeDirName, destUri: template.document.root+'assets'}); + }.bind(this), 3000); + } + } + } else { + //TODO: Error handle no available library to copy + } + } // - var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'); + var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'), webgljstag, webgllibtag, webglrdgetag; // 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 + } } } // @@ -378,13 +397,47 @@ exports.IoMediator = Montage.create(Component, { } } // + if (!webglrdgetag) { + webglrdgetag = template.document.content.document.createElement('script'); + webglrdgetag.setAttribute('type', 'text/javascript'); + webglrdgetag.setAttribute('src', rdgeDirName+'/rdge-compiled.js'); + webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true'); + template.document.content.document.head.appendChild(webglrdgetag); + } + // + if (!webgllibtag) { + webgllibtag = template.document.content.document.createElement('script'); + webgllibtag.setAttribute('type', 'text/javascript'); + webgllibtag.setAttribute('src', rdgeDirName+'/canvas-runtime.js'); + webgllibtag.setAttribute('data-ninja-webgl-lib', 'true'); + template.document.content.document.head.appendChild(webgllibtag); + } + // if (!webgltag) { webgltag = template.document.content.document.createElement('script'); webgltag.setAttribute('data-ninja-webgl', 'true'); template.document.content.document.head.appendChild(webgltag); } - //TODO: Add version and other data for RDGE - json = '\n({\n\t"version": "X.X.X.X",\n\t"data": ['; + //TODO: Remove this tag and place inside JS file + if (!webgljstag) { + webgljstag = template.document.content.document.createElement('script'); + webgljstag.setAttribute('type', 'text/javascript'); + webgljstag.setAttribute('data-ninja-webgl-js', 'true'); + template.document.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\ + initWebGl("+rootElement+", '"+rdgeDirName+"/');\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": ['; //Looping through data to create escaped array for (var j=0; template.webgl[j]; j++) { if (j === 0) { @@ -398,18 +451,16 @@ exports.IoMediator = Montage.create(Component, { //Setting string in tag webgltag.innerHTML = json; } + //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)); - //console.log(this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), ''))); + // function parseNinjaRootUrl (url) { if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { - return this.getUrlfromNinjaUrl(url, rootUrl, rootUrl.replace(new RegExp((this.application.ninja.coreIoApi.rootUrl).replace(/\//gi, '\\\/'), 'gi'), '')+'file.ext');//Wrong parameters + return this.getUrlfromNinjaUrl(url, rootUrl, rootUrl.replace(new RegExp((this.application.ninja.coreIoApi.rootUrl).replace(/\//gi, '\\\/'), 'gi'), '')+'file.ext'); } else { return url; } - } - //console.log(rootUrl, this.application.ninja.coreIoApi.rootUrl, this.application.ninja.documentController.documentHackReference.root, this.application.ninja.coreIoApi.cloudData.root); - //console.log(this.getPrettyHtml(template.document.content.document.documentElement.outerHTML)); - //return; + } // return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); } -- cgit v1.2.3