aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-03-08 16:07:02 -0800
committerJose Antonio Marquez2012-03-08 16:07:02 -0800
commit4bdb951f2dab6d132ed28ab17888cc819ed811ee (patch)
tree4fa0ac486431b1fb39383c3bb3a01a230a73f422 /js/mediators
parent85f21e020ac281e8e545df1cf269034de99a00b1 (diff)
downloadninja-4bdb951f2dab6d132ed28ab17888cc819ed811ee.tar.gz
Adding I/O functionality to RDGE
Added webGL/Canvas file I/O for Ninja, it also created routine for saving data for runtime, however, the runtime RDGE library needs an update for runtime to work, so right now I/O will only work for Ninja.
Diffstat (limited to 'js/mediators')
-rw-r--r--js/mediators/io-mediator.js79
1 files changed, 59 insertions, 20 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index dcafb38d..c22d95be 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -152,17 +152,7 @@ exports.IoMediator = Montage.create(Component, {
152 // 152 //
153 switch (file.mode) { 153 switch (file.mode) {
154 case 'html': 154 case 'html':
155 //Copy webGL library if needed 155
156 if (file.webgl && file.webgl.length > 0) {
157 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
158 //Checking for RDGE library to be available
159 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') {
160 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());
161 } else {
162 //TODO: Error handle no available library to copy
163 }
164 }
165 }
166 156
167 //TODO: Add check for Monatage library to copy 157 //TODO: Add check for Monatage library to copy
168 158
@@ -357,15 +347,33 @@ exports.IoMediator = Montage.create(Component, {
357 } 347 }
358 } 348 }
359 //Checking for webGL elements in document 349 //Checking for webGL elements in document
360 if (template.webgl && template.webgl.length) { 350 if (template.webgl && template.webgl.length > 0) {
351 var rdgeDirName, rdgeVersion;
352 //Copy webGL library if needed
353 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
354 //Checking for RDGE library to be available
355 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') {
356 rdgeDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase();
357 rdgeVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
358 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.document.root, rdgeDirName);
359 } else {
360 //TODO: Error handle no available library to copy
361 }
362 }
361 // 363 //
362 var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'); 364 var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'), webgljstag, webgllibtag;
363 // 365 //
364 for (var i in scripts) { 366 for (var i in scripts) {
365 if (scripts[i].getAttribute) { 367 if (scripts[i].getAttribute) {
366 if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll 368 if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll
367 matchingtags.push(scripts[i]); 369 matchingtags.push(scripts[i]);
368 } 370 }
371 if (scripts[i].getAttribute('data-ninja-webgl-js') !== null) {
372 webgljstag = scripts[i]; // TODO: Add logic to delete unneccesary tags
373 }
374 if (scripts[i].getAttribute('data-ninja-webgl-lib') !== null) {
375 webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags
376 }
369 } 377 }
370 } 378 }
371 // 379 //
@@ -378,13 +386,46 @@ exports.IoMediator = Montage.create(Component, {
378 } 386 }
379 } 387 }
380 // 388 //
389 if (!webgllibtag) {
390 webgllibtag = template.document.content.document.createElement('script');
391 webgllibtag.setAttribute('type', 'text/javascript');
392 webgllibtag.setAttribute('src', rdgeDirName+'/CanvasDataManager.js');
393 webgllibtag.setAttribute('data-ninja-webgl-lib', 'true');
394 template.document.content.document.head.appendChild(webgllibtag);
395 }
396 //
381 if (!webgltag) { 397 if (!webgltag) {
382 webgltag = template.document.content.document.createElement('script'); 398 webgltag = template.document.content.document.createElement('script');
383 webgltag.setAttribute('data-ninja-webgl', 'true'); 399 webgltag.setAttribute('data-ninja-webgl', 'true');
384 template.document.content.document.head.appendChild(webgltag); 400 template.document.content.document.head.appendChild(webgltag);
385 } 401 }
402 //
403 if (!webgljstag) {
404 webgljstag = template.document.content.document.createElement('script');
405 webgljstag.setAttribute('type', 'text/javascript');
406 webgljstag.setAttribute('data-ninja-webgl-js', 'true');
407 template.document.content.document.head.appendChild(webgljstag);
408 }
409 //TODO: Decide if this should be over-writter or only written on creation
410 webgljstag.innerHTML = "\
411//Loading webGL/canvas data on window load\n\
412window.addEventListener('load', initWebGl, false);\n\
413function initWebGl (e) {\n\
414 window.removeEventListener('load', initWebGl, false);\n\
415 var cvsDataMngr, ninjaWebGlData = JSON.parse((document.querySelectorAll(['script[data-ninja-webgl]'])[0].innerHTML.replace(\"(\", \"\")).replace(\")\", \"\"));\n\
416 if (ninjaWebGlData && ninjaWebGlData.data) {\n\
417 for (var n=0; ninjaWebGlData.data[n]; n++) {\n\
418 ninjaWebGlData.data[n] = unescape(ninjaWebGlData.data[n]);\n\
419 }\n\
420 }\n\
421 //Creating data manager\n\
422 cvsDataMngr = new CanvasDataManager();\n\
423 //Loading data to canvas(es)\n\
424 cvsDataMngr.loadGLData(document.body, ninjaWebGlData, '"+rdgeDirName+"');\n\
425}\
426 ";
386 //TODO: Add version and other data for RDGE 427 //TODO: Add version and other data for RDGE
387 json = '\n({\n\t"version": "X.X.X.X",\n\t"data": ['; 428 json = '\n({\n\t"version": "'+rdgeVersion+'",\n\t"data": [';
388 //Looping through data to create escaped array 429 //Looping through data to create escaped array
389 for (var j=0; template.webgl[j]; j++) { 430 for (var j=0; template.webgl[j]; j++) {
390 if (j === 0) { 431 if (j === 0) {
@@ -398,18 +439,16 @@ exports.IoMediator = Montage.create(Component, {
398 //Setting string in tag 439 //Setting string in tag
399 webgltag.innerHTML = json; 440 webgltag.innerHTML = json;
400 } 441 }
442 //Cleaning URLs from HTML
401 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)); 443 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));
402 //console.log(this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), ''))); 444 //
403 function parseNinjaRootUrl (url) { 445 function parseNinjaRootUrl (url) {
404 if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { 446 if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) {
405 return this.getUrlfromNinjaUrl(url, rootUrl, rootUrl.replace(new RegExp((this.application.ninja.coreIoApi.rootUrl).replace(/\//gi, '\\\/'), 'gi'), '')+'file.ext');//Wrong parameters 447 return this.getUrlfromNinjaUrl(url, rootUrl, rootUrl.replace(new RegExp((this.application.ninja.coreIoApi.rootUrl).replace(/\//gi, '\\\/'), 'gi'), '')+'file.ext');
406 } else { 448 } else {
407 return url; 449 return url;
408 } 450 }
409 } 451 }
410 //console.log(rootUrl, this.application.ninja.coreIoApi.rootUrl, this.application.ninja.documentController.documentHackReference.root, this.application.ninja.coreIoApi.cloudData.root);
411 //console.log(this.getPrettyHtml(template.document.content.document.documentElement.outerHTML));
412 //return;
413 // 452 //
414 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); 453 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), ''));
415 } 454 }