aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xjs/document/html-document.js25
-rw-r--r--js/mediators/io-mediator.js65
2 files changed, 84 insertions, 6 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index ace1390f..a3424259 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -436,7 +436,14 @@ exports.HTMLDocument = Montage.create(TextDocument, {
436 prop = prop.replace(/"([^"]*)"/gi, ninjaUrlPrepend.bind(this)); 436 prop = prop.replace(/"([^"]*)"/gi, ninjaUrlPrepend.bind(this));
437 } else if (prop.indexOf('url') !== -1) { //From CSS property 437 } else if (prop.indexOf('url') !== -1) { //From CSS property
438 //TODO: Add functionality 438 //TODO: Add functionality
439 console.log('CSS: '+prop); 439 var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
440 prop = prop.replace(/[^()\\""\\'']+/g, test);
441 function test (s) {
442 if (s !== 'url') {
443 s = docRootUrl + s;
444 }
445 return s;
446 }
440 } 447 }
441 } 448 }
442 return prop; 449 return prop;
@@ -643,11 +650,24 @@ exports.HTMLDocument = Montage.create(TextDocument, {
643 console.log('ERROR: Cross-Domain-Stylesheet detected, unable to load in Ninja'); 650 console.log('ERROR: Cross-Domain-Stylesheet detected, unable to load in Ninja');
644 //None local stylesheet, probably on a CDN (locked) 651 //None local stylesheet, probably on a CDN (locked)
645 /* 652 /*
646tag = this.iframe.contentWindow.document.createElement('style'); 653var tag = this.iframe.contentWindow.document.createElement('style');
647 tag.setAttribute('type', 'text/css'); 654 tag.setAttribute('type', 'text/css');
648 tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); 655 tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href);
649 tag.setAttribute('data-ninja-file-read-only', "true"); 656 tag.setAttribute('data-ninja-file-read-only', "true");
650 tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]); 657 tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]);
658 //Copying attributes to maintain same properties as the <link>
659 for (var n in this._document.styleSheets[i].ownerNode.attributes) {
660 if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled' && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') {
661 if (this._document.styleSheets[i].ownerNode.attributes[n].value.indexOf(docRootUrl) !== -1) {
662 tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value.split(docRootUrl)[1]);
663 } else {
664 tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value);
665 }
666 }
667 }
668
669
670
651 671
652 //TODO: Figure out cross-domain XHR issue, might need cloud to handle 672 //TODO: Figure out cross-domain XHR issue, might need cloud to handle
653 var xhr = new XMLHttpRequest(); 673 var xhr = new XMLHttpRequest();
@@ -658,7 +678,6 @@ tag = this.iframe.contentWindow.document.createElement('style');
658 console.log(xhr); 678 console.log(xhr);
659 } 679 }
660 //tag.innerHTML = xhr.responseText //xhr.response; 680 //tag.innerHTML = xhr.responseText //xhr.response;
661
662 //Currently no external styles will load if unable to load via XHR request 681 //Currently no external styles will load if unable to load via XHR request
663 682
664 //Disabling external style sheets 683 //Disabling external style sheets
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 ////////////////////////////////////////////////////////////////////