aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-03-05 20:06:32 -0800
committerJose Antonio Marquez2012-03-05 20:06:32 -0800
commit4c4d49ae7958e2c87764f9319665189cf69c5c0a (patch)
tree4502367b07f3c938cb617bf59a4f7d2d459ded93 /js/mediators
parent56efed8b1ed9974aade615fce2d96bc214d21540 (diff)
downloadninja-4c4d49ae7958e2c87764f9319665189cf69c5c0a.tar.gz
Fixed URL parsing issue on actual opened document
Still need to implement CSS loaded from a CDN, currently this would break Ninja.
Diffstat (limited to 'js/mediators')
-rw-r--r--js/mediators/io-mediator.js65
1 files changed, 62 insertions, 3 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index c02710c2..d6b4bd37 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -228,6 +228,8 @@ exports.IoMediator = Montage.create(Component, {
228 if (styletags[j].getAttribute) { 228 if (styletags[j].getAttribute) {
229 if(styletags[j].getAttribute('data-ninja-uri') !== null && !styletags[j].getAttribute('data-ninja-template')) { 229 if(styletags[j].getAttribute('data-ninja-uri') !== null && !styletags[j].getAttribute('data-ninja-template')) {
230 toremovetags.push(styletags[j]); 230 toremovetags.push(styletags[j]);
231 } else if (styletags[j].getAttribute('data-ninja-external-url')) {
232 toremovetags.push(styletags[j]);
231 } 233 }
232 } 234 }
233 } 235 }
@@ -342,9 +344,13 @@ exports.IoMediator = Montage.create(Component, {
342 fileUrl = template.css[i].ownerNode.getAttribute('data-ninja-file-url'), 344 fileUrl = template.css[i].ownerNode.getAttribute('data-ninja-file-url'),
343 fileRootUrl = this.application.ninja.coreIoApi.rootUrl+fileUrl.split(fileUrl.split('/')[fileUrl.split('/').length-1])[0], 345 fileRootUrl = this.application.ninja.coreIoApi.rootUrl+fileUrl.split(fileUrl.split('/')[fileUrl.split('/').length-1])[0],
344 cleanedCss = dirtyCss.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaUrl.bind(this)); 346 cleanedCss = dirtyCss.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaUrl.bind(this));
345 347
346
347 function parseNinjaUrl (url) { 348 function parseNinjaUrl (url) {
349 return this.getUrlfromNinjaUrl(url, fileRootUrl, fileUrl);
350 }
351
352 /*
353function parseNinjaUrl (url) {
348 //console.log("Getting: " + url); 354 //console.log("Getting: " + url);
349 // 355 //
350 if (url.indexOf(fileRootUrl) !== -1) { 356 if (url.indexOf(fileRootUrl) !== -1) {
@@ -376,6 +382,7 @@ exports.IoMediator = Montage.create(Component, {
376 //console.log("-----"); 382 //console.log("-----");
377 return url; 383 return url;
378 } 384 }
385*/
379 386
380 /////////////////////////////////////////////////////////////////////////////////////////// 387 ///////////////////////////////////////////////////////////////////////////////////////////
381 /////////////////////////////////////////////////////////////////////////////////////////// 388 ///////////////////////////////////////////////////////////////////////////////////////////
@@ -433,8 +440,60 @@ exports.IoMediator = Montage.create(Component, {
433 //Setting string in tag 440 //Setting string in tag
434 webgltag.innerHTML = json; 441 webgltag.innerHTML = json;
435 } 442 }
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));
444 console.log(this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')));
445 function parseNinjaRootUrl (url) {
446 if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) {
447 return this.getUrlfromNinjaUrl(url, rootUrl, rootUrl.replace(new RegExp((this.application.ninja.coreIoApi.rootUrl).replace(/\//gi, '\\\/'), 'gi'), '')+'file.ext');//Wrong parameters
448 } else {
449 return url;
450 }
451 }
452 //console.log(rootUrl, this.application.ninja.coreIoApi.rootUrl, this.application.ninja.documentController.documentHackReference.root, this.application.ninja.coreIoApi.cloudData.root);
453 //console.log(this.getPrettyHtml(template.document.content.document.documentElement.outerHTML));
454 return;
455 //
456 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), ''));
457 }
458 },
459 ////////////////////////////////////////////////////////////////////
460 //
461 getUrlfromNinjaUrl: {
462 enumerable: false,
463 value: function (url, fileRootUrl, fileUrl) {
464 //console.log("Params: ", url, fileRootUrl, fileUrl);
465 //console.log("Getting: " + url);
466 //
467 if (url.indexOf(fileRootUrl) !== -1) {
468 url = url.replace(new RegExp(fileRootUrl.replace(/\//gi, '\\\/'), 'gi'), '');
469 } else {
470 //TODO: Clean up vars
471 var assetsDirs = (url.replace(new RegExp((this.application.ninja.coreIoApi.rootUrl).replace(/\//gi, '\\\/'), 'gi'), '')).split('/');
472 var fileDirs = (fileUrl.split(fileUrl.split('/')[fileUrl.split('/').length-1])[0]).split('/');
473 var counter = 0;
474 var path = '';
475 var newURL = '';
476 //
477 for (var p=0; p < fileDirs.length-1; p++) {
478 if (fileDirs[p] === assetsDirs[p]) {
479 counter++;
480 }
481 }
482 //
483 for (var p=0; p < (fileDirs.length-counter)-1; p++) {
484 path += '../';
485 }
486 //
487 for (var p=counter; p < assetsDirs.length; p++) {
488 newURL += '/'+assetsDirs[p];
489 }
490 //
491 url = (path+newURL).replace(/\/\//gi, '/');
492 }
493 //console.log("Returning: " + url);
494 //console.log("-----");
436 // 495 //
437 return this.getPrettyHtml(template.document.content.document.documentElement.outerHTML.replace(this.getAppTemplatesUrlRegEx(), '')); 496 return url;
438 } 497 }
439 }, 498 },
440 //////////////////////////////////////////////////////////////////// 499 ////////////////////////////////////////////////////////////////////