aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators')
-rw-r--r--js/mediators/io-mediator.js85
1 files changed, 64 insertions, 21 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index dcafb38d..277b3a1b 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+'/CanvasRuntime.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.data);\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"directory": "'+rdgeDirName+'/",\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) {
@@ -396,20 +437,22 @@ exports.IoMediator = Montage.create(Component, {
396 //Closing array (make-shift JSON string to validate data in <script> tag) 437 //Closing array (make-shift JSON string to validate data in <script> tag)
397 json += '\n\t\t]\n})\n'; 438 json += '\n\t\t]\n})\n';
398 //Setting string in tag 439 //Setting string in tag
399 webgltag.innerHTML = json; 440 webgltag.innerHTML = json.replace(/assets\//gi, webGlDirSwap);
441 //
442 function webGlDirSwap (dir) {
443 return rdgeDirName+'/';
444 }
400 } 445 }
446 //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)); 447 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(), ''))); 448 //
403 function parseNinjaRootUrl (url) { 449 function parseNinjaRootUrl (url) {
404 if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { 450 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 451 return this.getUrlfromNinjaUrl(url, rootUrl, rootUrl.replace(new RegExp((this.application.ninja.coreIoApi.rootUrl).replace(/\//gi, '\\\/'), 'gi'), '')+'file.ext');
406 } else { 452 } else {
407 return url; 453 return url;
408 } 454 }
409 } 455 }
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 // 456 //
414 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); 457 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), ''));
415 } 458 }