aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators')
-rw-r--r--js/mediators/io-mediator.js149
1 files changed, 112 insertions, 37 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index ade27728..e9ed86d7 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -203,6 +203,59 @@ exports.IoMediator = Montage.create(Component, {
203 }, 203 },
204 //////////////////////////////////////////////////////////////////// 204 ////////////////////////////////////////////////////////////////////
205 // 205 //
206 getDataDirectory: {
207 value: function (path) {
208 //TODO: Implement user overwrite
209 return this._getUserDirectory(path+'data/');
210 }
211 },
212 ////////////////////////////////////////////////////////////////////
213 //
214 getNinjaDirectory: {
215 value: function (path) {
216 //TODO: Implement user overwrite
217 return this._getUserDirectory(this.getDataDirectory(path)+'ninja/');
218 }
219 },
220 ////////////////////////////////////////////////////////////////////
221 //
222 getCanvasDirectory: {
223 value: function (path) {
224 //TODO: Implement user overwrite
225 return this._getUserDirectory(this.getNinjaDirectory(path)+'canvas/');
226 }
227 },
228 ////////////////////////////////////////////////////////////////////
229 //
230 _getUserDirectory: {
231 value: function (path) {
232 //Checking for data directory
233 var check = this.application.ninja.coreIoApi.fileExists({uri: path}), directory;
234 //Creating directory if doesn't exists
235 switch (check.status) {
236 case 204: //Exists
237 directory = path;
238 break;
239 case 404: //Doesn't exists
240 directory = this.application.ninja.coreIoApi.createDirectory({uri: path});
241 //Checking for success
242 if (directory.status === 201) {
243 directory = path;
244 } else {
245 //Error
246 directory = null;
247 }
248 break;
249 default: //Error
250 directory = null;
251 break;
252 }
253 //Returning the path to the directory on disk (null for any error)
254 return directory;
255 }
256 },
257 ////////////////////////////////////////////////////////////////////
258 //
206 parseHtmlToNinjaTemplate: { 259 parseHtmlToNinjaTemplate: {
207 enumerable: false, 260 enumerable: false,
208 value: function (html) { 261 value: function (html) {
@@ -406,20 +459,19 @@ exports.IoMediator = Montage.create(Component, {
406 } 459 }
407 } 460 }
408 // 461 //
409 var matchingtags = [], scripts = template.file.content.document.getElementsByTagName('script'), webgltag, webgljstag, webgllibtag, webglrdgetag, mjstag, mjslibtag; 462 var matchingtags = [], scripts = template.file.content.document.getElementsByTagName('script'), webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag;
463 //this.getDataDirectory(template.file.root)
464 //this.getNinjaDirectory(template.file.root)
410 // 465 //
411 for (var i in scripts) { 466 for (var i in scripts) {
412 if (scripts[i].getAttribute) { 467 if (scripts[i].getAttribute) {
413 if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll 468 if (scripts[i].getAttribute('data-ninja-canvas') !== null) {//TODO: Use querySelectorAll
414 matchingtags.push(scripts[i]); 469 matchingtags.push(scripts[i]);
415 } 470 }
416 if (scripts[i].getAttribute('data-ninja-webgl-js') !== null) { 471 if (scripts[i].getAttribute('data-ninja-canvas-lib') !== null) {
417 webgljstag = scripts[i]; // TODO: Add logic to delete unneccesary tags
418 }
419 if (scripts[i].getAttribute('data-ninja-webgl-lib') !== null) {
420 webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags 472 webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags
421 } 473 }
422 if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) { 474 if (scripts[i].getAttribute('data-ninja-canvas-rdge') !== null) {
423 webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags 475 webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags
424 } 476 }
425 if (scripts[i].getAttribute('type') === 'text/montage-serialization') { 477 if (scripts[i].getAttribute('type') === 'text/montage-serialization') {
@@ -432,7 +484,19 @@ exports.IoMediator = Montage.create(Component, {
432 } 484 }
433 //Checking for webGL elements in document 485 //Checking for webGL elements in document
434 if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix 486 if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix
435 var rdgeDirName, rdgeVersion; 487 var rdgeDirName, rdgeVersion, cvsDataDir = this.getCanvasDirectory(template.file.root), fileCvsDir, fileCvsDirAppend, cvsDirCounter = 1;
488 //
489 if (cvsDataDir && !matchingtags.length) {
490 fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0];
491 if (!this._getUserDirectory(fileCvsDir)) {
492 fileCvsDirAppend = fileCvsDir+cvsDirCounter;
493 while (!this._getUserDirectory(fileCvsDirAppend)) {
494 fileCvsDirAppend = fileCvsDir+(cvsDirCounter++);
495 }
496 }
497 //TODO: Allow user overwrite
498 fileCvsDir += '/';
499 }
436 //Copy webGL library if needed 500 //Copy webGL library if needed
437 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { 501 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
438 //Checking for RDGE library to be available 502 //Checking for RDGE library to be available
@@ -453,12 +517,12 @@ exports.IoMediator = Montage.create(Component, {
453 webgltag = matchingtags[matchingtags.length - 1]; //Saving all data to last one... 517 webgltag = matchingtags[matchingtags.length - 1]; //Saving all data to last one...
454 } 518 }
455 } 519 }
456 // 520 //TODO: Add check for file needed
457 if (!webglrdgetag) { 521 if (!webglrdgetag) {
458 webglrdgetag = template.file.content.document.createElement('script'); 522 webglrdgetag = template.file.content.document.createElement('script');
459 webglrdgetag.setAttribute('type', 'text/javascript'); 523 webglrdgetag.setAttribute('type', 'text/javascript');
460 webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js'); 524 webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js');
461 webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true'); 525 webglrdgetag.setAttribute('data-ninja-canvas-rdge', 'true');
462 if (ninjaWrapper) { 526 if (ninjaWrapper) {
463 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webglrdgetag); 527 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webglrdgetag);
464 } else { 528 } else {
@@ -470,7 +534,7 @@ exports.IoMediator = Montage.create(Component, {
470 webgllibtag = template.file.content.document.createElement('script'); 534 webgllibtag = template.file.content.document.createElement('script');
471 webgllibtag.setAttribute('type', 'text/javascript'); 535 webgllibtag.setAttribute('type', 'text/javascript');
472 webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js'); 536 webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js');
473 webgllibtag.setAttribute('data-ninja-webgl-lib', 'true'); 537 webgllibtag.setAttribute('data-ninja-canvas-lib', 'true');
474 if (ninjaWrapper) { 538 if (ninjaWrapper) {
475 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgllibtag); 539 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgllibtag);
476 } else { 540 } else {
@@ -478,51 +542,62 @@ exports.IoMediator = Montage.create(Component, {
478 } 542 }
479 } 543 }
480 // 544 //
481 if (!webgltag) { 545 if (!webgltag && !fileCvsDir) {
482 webgltag = template.file.content.document.createElement('script'); 546 webgltag = template.file.content.document.createElement('script');
483 webgltag.setAttribute('data-ninja-webgl', 'true'); 547 webgltag.setAttribute('data-ninja-canvas', 'true');
484 if (ninjaWrapper) { 548 if (ninjaWrapper) {
485 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgltag); 549 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgltag);
486 } else { 550 } else {
487 template.file.content.document.head.appendChild(webgltag); 551 template.file.content.document.head.appendChild(webgltag);
488 } 552 }
489 } 553 }
490 //TODO: Remove this tag and place inside JS file 554
491 if (!webgljstag) {
492 webgljstag = template.file.content.document.createElement('script');
493 webgljstag.setAttribute('type', 'text/javascript');
494 webgljstag.setAttribute('data-ninja-webgl-js', 'true');
495 if (ninjaWrapper) {
496 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgljstag);
497 } else {
498 template.file.content.document.head.appendChild(webgljstag);
499 }
500 }
501 //TODO: Decide if this should be over-writter or only written on creation 555 //TODO: Decide if this should be over-writter or only written on creation
502 var rootElement = 'document.body'; //TODO: Set actual root element 556 var rootElement = 'document.body'; //TODO: Set actual root element
503 webgljstag.innerHTML = "\ 557
504//Loading webGL/canvas data on window load\n\
505window.addEventListener('load', loadWebGL, false);\n\
506function loadWebGL (e) {\n\
507 window.removeEventListener('load', loadWebGL, false);\n\
508 //Calling method to initialize all webGL/canvas(es)\n\
509 NinjaCvsRt.initWebGl(" + rootElement + ", '" + rdgeDirName + "/');\n\
510}\
511 ";
512 //TODO: This data should be saved to a JSON file eventually 558 //TODO: This data should be saved to a JSON file eventually
513 var json = '\n({\n\t"version": "' + rdgeVersion + '",\n\t"directory": "' + rdgeDirName + '/",\n\t"data": ['; 559 var json = '\n({\n\t"version": "' + rdgeVersion + '",\n\t"directory": "' + rdgeDirName + '/",\n\t"data": [';
514 //Looping through data to create escaped array 560 //Looping through data to create escaped array
515 for (var j = 0; template.webgl[j]; j++) { 561 for (var j = 0; template.webgl[j]; j++) {
516 if (j === 0) { 562 if (j === 0) {
517 json += '\n\t\t\t"' + escape(template.webgl[j]) + '"'; 563 //if (fileCvsDir) {
564 // json += '\n\t\t\t"' + template.webgl[j] + '"';
565 //} else {
566 json += '\n\t\t\t"' + escape(template.webgl[j]) + '"';
567 //}
518 } else { 568 } else {
519 json += ',\n\t\t\t"' + escape(template.webgl[j]) + '"'; 569 //if (fileCvsDir) {
570 // json += ',\n\t\t\t"' + template.webgl[j] + '"';
571 //} else {
572 json += ',\n\t\t\t"' + escape(template.webgl[j]) + '"';
573 //}
520 } 574 }
521 } 575 }
522 //Closing array (make-shift JSON string to validate data in <script> tag) 576 //Closing array (make-shift JSON string to validate data in <script> tag)
523 json += '\n\t\t]\n})\n'; 577 json += '\n\t\t]\n})\n';
524 //Setting string in tag 578 //Setting string in tag