aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xjs/document/html-document.js65
-rw-r--r--js/mediators/io-mediator.js56
2 files changed, 57 insertions, 64 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index be1f89e2..9de2d8d6 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -520,67 +520,13 @@ exports.HTMLDocument = Montage.create(TextDocument, {
520 } 520 }
521 // 521 //
522 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; 522 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {};
523 //Inserting user's document into template
524
525
526
527
528
529
530
531
532
533 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
534 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
535 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
536
537 //TODO: Clean up and make public method to prepend properties with Ninja URL
538 this._templateDocument.head.innerHTML = (this._userDocument.content.head.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, ninjaUrlRedirect.bind(this))).replace(/url\(([^"]*)(.+?)\1\)/g, ninjaUrlRedirect.bind(this));
539 this._templateDocument.body.innerHTML = (this._userDocument.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, ninjaUrlRedirect.bind(this))).replace(/url\(([^"]*)(.+?)\1\)/g, ninjaUrlRedirect.bind(this));
540 //
541 //var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
542 //
543 function ninjaUrlRedirect (prop) {
544 //Checking for property value to not contain a full direct URL
545 if (!prop.match(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi)) {
546 //Checking for attributes and type of source
547 if (prop.indexOf('href') !== -1 || prop.indexOf('src') !== -1) { //From HTML attribute
548 //
549 prop = prop.replace(/"([^"]*)"/gi, ninjaUrlPrepend.bind(this));
550 } else if (prop.indexOf('url') !== -1) { //From CSS property
551 //TODO: Add functionality
552 var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
553 prop = prop.replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl);
554 function cssUrlToNinjaUrl (s) {
555 if (s !== 'url') {
556 s = docRootUrl + s;
557 }
558 return s;
559 }
560 }
561 }
562 return prop;
563 }
564 //
565 function ninjaUrlPrepend (url) {
566 var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
567 if (url.indexOf('data:image') !== -1) {
568 return url;
569 } else {
570 return '"'+docRootUrl+url.replace(/\"/gi, '')+'"';
571 }
572 }
573 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
574 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
575 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
576
577
578
579
580
581 523
582 524
583 525
526 //TODO: Clean up, using for prototyping
527 this._templateDocument.head.innerHTML = (this._userDocument.content.head.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator));
528 this._templateDocument.body.innerHTML = (this._userDocument.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator));
529
584 530
585 531
586 var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; //TODO: Use querySelectorAll 532 var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; //TODO: Use querySelectorAll
@@ -603,7 +549,6 @@ exports.HTMLDocument = Montage.create(TextDocument, {
603 549
604 550
605 551
606
607 //Temporarily checking for disabled special case 552 //Temporarily checking for disabled special case
608 var stags = this.iframe.contentWindow.document.getElementsByTagName('style'), 553 var stags = this.iframe.contentWindow.document.getElementsByTagName('style'),
609 ltags = this.iframe.contentWindow.document.getElementsByTagName('link'); 554 ltags = this.iframe.contentWindow.document.getElementsByTagName('link');
@@ -628,7 +573,6 @@ exports.HTMLDocument = Montage.create(TextDocument, {
628 573
629 574
630 575
631
632 //Adding a handler for the main user document reel to finish loading 576 //Adding a handler for the main user document reel to finish loading
633 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); 577 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false);
634 578
@@ -687,6 +631,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
687 // 631 //
688 fileCouldDirUrl = this._document.styleSheets[i].href.split(this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1])[0]; 632 fileCouldDirUrl = this._document.styleSheets[i].href.split(this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1])[0];
689 633
634 //TODO: Make public version of this.application.ninja.ioMediator.getNinjaPropUrlRedirect with dynamic ROOT
690 tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl); 635 tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl);
691 636
692 function detectUrl (prop) { 637 function detectUrl (prop) {
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 18a517a5..cbed3a99 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -532,8 +532,6 @@ function loadWebGL (e) {\n\
532 getUrlfromNinjaUrl: { 532 getUrlfromNinjaUrl: {
533 enumerable: false, 533 enumerable: false,
534 value: function (url, fileRootUrl, fileUrl) { 534 value: function (url, fileRootUrl, fileUrl) {
535 //console.log("Params: ", url, fileRootUrl, fileUrl);
536 //console.log("Getting: " + url);
537 // 535 //
538 if (url.indexOf(fileRootUrl) !== -1) { 536 if (url.indexOf(fileRootUrl) !== -1) {
539 url = url.replace(new RegExp(fileRootUrl.replace(/\//gi, '\\\/'), 'gi'), ''); 537 url = url.replace(new RegExp(fileRootUrl.replace(/\//gi, '\\\/'), 'gi'), '');
@@ -561,13 +559,63 @@ function loadWebGL (e) {\n\
561 // 559 //
562 url = (path+newURL).replace(/\/\//gi, '/'); 560 url = (path+newURL).replace(/\/\//gi, '/');
563 } 561 }
564 //console.log("Returning: " + url);
565 //console.log("-----");
566 // 562 //
567 return url; 563 return url;
568 } 564 }
569 }, 565 },
570 //////////////////////////////////////////////////////////////////// 566 ////////////////////////////////////////////////////////////////////
567 //
568 getDocRootUrl: {
569 value: function () {
570 return this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
571 }
572 },
573 ////////////////////////////////////////////////////////////////////
574 //
575 getNinjaPropUrlRedirect: {
576 enumerable: false,
577 value: function (prop/* , root */) {
578 //Checking for property value to not contain a full direct URL
579 if (!prop.match(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi)) {
580 //Checking for attributes and type of source
581 if (prop.indexOf('href') !== -1 || prop.indexOf('src') !== -1) {
582 //From HTML attribute
583 //if (root) {
584 //prop = (root+prop).replace(/"([^"]*)"/gi, this.getNinjaUrlPrepend.bind(this));
585 //} else {
586 prop = prop.replace(/"([^"]*)"/gi, this.getNinjaUrlPrepend.bind(this));
587 //}
588 } else if (prop.indexOf('url') !== -1) {
589 //From CSS property
590 //if (root) {
591 //prop = (root+prop).replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl.bind(this));
592 //} else {
593 prop = prop.replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl.bind(this));
594 //}
595 function cssUrlToNinjaUrl (s) {
596 if (s !== 'url') {
597 s = this.getDocRootUrl() + s;
598 }
599 return s;
600 }
601 }
602 }
603 return prop;
604 }
605 },
606 ////////////////////////////////////////////////////////////////////
607 //
608 getNinjaUrlPrepend: {
609 enumerable: false,
610 value: function (url) {
611 if (url.indexOf('data:') !== -1) {
612 return url;
613 } else {
614 return '"'+this.getDocRootUrl()+url.replace(/\"/gi, '')+'"';
615 }
616 }
617 },
618 ////////////////////////////////////////////////////////////////////
571 //Method to return a string from CSS rules (to be saved to a file) 619 //Method to return a string from CSS rules (to be saved to a file)
572 getCssFromRules: { 620 getCssFromRules: {
573 enumerable: false, 621 enumerable: false,