aboutsummaryrefslogtreecommitdiff
path: root/js/mediators/io-mediator.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r--js/mediators/io-mediator.js93
1 files changed, 72 insertions, 21 deletions
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, {
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,44 @@ 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, hackRename.bind(this));
359 //TODO: Remove, this is copying the library into a static name
360 function hackRename (status) {
361 if (status) {
362 setTimeout(function () {
363 this.application.ninja.coreIoApi.copyDirectory({sourceUri: template.document.root+rdgeDirName, destUri: template.document.root+'assets'});
364 }.bind(this), 3000);
365 }
366 }
367 } else {
368 //TODO: Error handle no available library to copy
369 }
370 }
361 // 371 //
362 var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'); 372 var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'), webgljstag, webgllibtag, webglrdgetag;
363 // 373 //
364 for (var i in scripts) { 374 for (var i in scripts) {
365 if (scripts[i].getAttribute) { 375 if (scripts[i].getAttribute) {
366 if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll 376 if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll
367 matchingtags.push(scripts[i]); 377 matchingtags.push(scripts[i]);
368 } 378 }
379 if (scripts[i].getAttribute('data-ninja-webgl-js') !== null) {
380 webgljstag = scripts[i]; // TODO: Add logic to delete unneccesary tags
381 }
382 if (scripts[i].getAttribute('data-ninja-webgl-lib') !== null) {
383 webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags
384 }
385 if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) {
386 webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags
387 }
369 } 388 }
370 } 389 }
371 // 390 //
@@ -378,13 +397,47 @@ exports.IoMediator = Montage.create(Component, {
378 } 397 }
379 } 398 }
380 // 399 //
400 if (!webglrdgetag) {
401 webglrdgetag = template.document.content.document.createElement('script');
402 webglrdgetag.setAttribute('type', 'text/javascript');
403 webglrdgetag.setAttribute('src', rdgeDirName+'/rdge-compiled.js');
404 webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true');
405 template.document.content.document.head.appendChild(webglrdgetag);
406 }
407 //
408 if (!webgllibtag) {
409 webgllibtag = template.document.content.document.createElement('script');
410 webgllibtag.setAttribute('type', 'text/javascript');
411 webgllibtag.setAttribute('src', rdgeDirName+'/canvas-runtime.js');
412 webgllibtag.setAttribute('data-ninja-webgl-lib', 'true');
413 template.document.content.document.head.appendChild(webgllibtag);
414 }
415 //
381 if (!webgltag) { 416 if (!webgltag) {
382 webgltag = template.document.content.document.createElement('script'); 417 webgltag = template.document.content.document.createElement('script');
383 webgltag.setAttribute('data-ninja-webgl', 'true'); 418 webgltag.setAttribute('data-ninja-webgl', 'true');
384 template.document.content.document.head.appendChild(webgltag); 419 template.document.content.document.head.appendChild(webgltag);
385 } 420 }
386 //TODO: Add version and other data for RDGE 421 //TODO: Remove this tag and place inside JS file
387 json = '\n({\n\t"version": "X.X.X.X",\n\t"data": ['; 422 if (!webgljstag) {
423 webgljstag = template.document.content.document.createElement('script');
424 webgljstag.setAttribute('type', 'text/javascript');
425 webgljstag.setAttribute('data-ninja-webgl-js', 'true');
426 template.document.content.document.head.appendChild(webgljstag);
427 }
428 //TODO: Decide if this should be over-writter or only written on creation
429 var rootElement = 'document.body'; //TODO: Set actual root element
430 webgljstag.innerHTML = "\
431//Loading webGL/canvas data on window load\n\
432window.addEventListener('load', loadWebGL, false);\n\
433function loadWebGL (e) {\n\
434 window.removeEventListener('load', loadWebGL, false);\n\
435 //Calling method to initialize all webGL/canvas(es)\n\
436 initWebGl("+rootElement+", '"+rdgeDirName+"/');\n\
437}\
438 ";
439 //TODO: This data should be saved to a JSON file eventually
440 json = '\n({\n\t"version": "'+rdgeVersion+'",\n\t"directory": "'+rdgeDirName+'/",\n\t"data": [';
388 //Looping through data to create escaped array 441 //Looping through data to create escaped array
389 for (var j=0; template.webgl[j]; j++) { 442 for (var j=0; template.webgl[j]; j++) {
390 if (j === 0) { 443 if (j === 0) {
@@ -398,18 +451,16 @@ exports.IoMediator = Montage.create(Component, {
398 //Setting string in tag 451 //Setting string in tag
399 webgltag.innerHTML = json; 452 webgltag.innerHTML = json;
400 } 453 }
454 //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)); 455 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(), ''))); 456 //
403 function parseNinjaRootUrl (url) { 457 function parseNinjaRootUrl (url) {
404 if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { 458 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 459 return this.getUrlfromNinjaUrl(url, rootUrl, rootUrl.replace(new RegExp((this.application.ninja.coreIoApi.rootUrl).replace(/\//gi, '\\\/'), 'gi'), '')+'file.ext');
406 } else { 460 } else {
407 return url; 461 return url;
408 } 462 }
409 } 463 }
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 // 464 //
414 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); 465 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), ''));
415 } 466 }