diff options
Diffstat (limited to 'js/document/html-document.js')
-rwxr-xr-x | js/document/html-document.js | 65 |
1 files changed, 5 insertions, 60 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js index aa57d848..7ab4272b 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js | |||
@@ -564,67 +564,13 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
564 | } | 564 | } |
565 | // | 565 | // |
566 | if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; | 566 | if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; |
567 | //Inserting user's document into template | ||
568 | |||
569 | |||
570 | |||
571 | |||
572 | |||
573 | |||
574 | |||
575 | |||
576 | |||
577 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
578 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
579 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
580 | |||
581 | //TODO: Clean up and make public method to prepend properties with Ninja URL | ||
582 | 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)); | ||
583 | 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)); | ||
584 | // | ||
585 | //var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); | ||
586 | // | ||
587 | function ninjaUrlRedirect (prop) { | ||
588 | //Checking for property value to not contain a full direct URL | ||
589 | 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)) { | ||
590 | //Checking for attributes and type of source | ||
591 | if (prop.indexOf('href') !== -1 || prop.indexOf('src') !== -1) { //From HTML attribute | ||
592 | // | ||
593 | prop = prop.replace(/"([^"]*)"/gi, ninjaUrlPrepend.bind(this)); | ||
594 | } else if (prop.indexOf('url') !== -1) { //From CSS property | ||
595 | //TODO: Add functionality | ||
596 | var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); | ||
597 | prop = prop.replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl); | ||
598 | function cssUrlToNinjaUrl (s) { | ||
599 | if (s !== 'url') { | ||
600 | s = docRootUrl + s; | ||
601 | } | ||
602 | return s; | ||
603 | } | ||
604 | } | ||
605 | } | ||
606 | return prop; | ||
607 | } | ||
608 | // | ||
609 | function ninjaUrlPrepend (url) { | ||
610 | var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); | ||
611 | if (url.indexOf('data:image') !== -1) { | ||
612 | return url; | ||
613 | } else { | ||
614 | return '"'+docRootUrl+url.replace(/\"/gi, '')+'"'; | ||
615 | } | ||
616 | } | ||
617 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
618 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
619 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
620 | |||
621 | |||
622 | |||
623 | |||
624 | |||
625 | 567 | ||
626 | 568 | ||
627 | 569 | ||
570 | //TODO: Clean up, using for prototyping | ||
571 | 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)); | ||
572 | 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)); | ||
573 | |||
628 | 574 | ||
629 | 575 | ||
630 | var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; //TODO: Use querySelectorAll | 576 | var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; //TODO: Use querySelectorAll |
@@ -647,7 +593,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
647 | 593 | ||
648 | 594 | ||
649 | 595 | ||
650 | |||
651 | //Temporarily checking for disabled special case | 596 | //Temporarily checking for disabled special case |
652 | var stags = this.iframe.contentWindow.document.getElementsByTagName('style'), | 597 | var stags = this.iframe.contentWindow.document.getElementsByTagName('style'), |
653 | ltags = this.iframe.contentWindow.document.getElementsByTagName('link'); | 598 | ltags = this.iframe.contentWindow.document.getElementsByTagName('link'); |
@@ -672,7 +617,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
672 | 617 | ||
673 | 618 | ||
674 | 619 | ||
675 | |||
676 | //Adding a handler for the main user document reel to finish loading | 620 | //Adding a handler for the main user document reel to finish loading |
677 | this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); | 621 | this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); |
678 | 622 | ||
@@ -731,6 +675,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
731 | // | 675 | // |
732 | fileCouldDirUrl = this._document.styleSheets[i].href.split(this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1])[0]; | 676 | fileCouldDirUrl = this._document.styleSheets[i].href.split(this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1])[0]; |
733 | 677 | ||
678 | //TODO: Make public version of this.application.ninja.ioMediator.getNinjaPropUrlRedirect with dynamic ROOT | ||
734 | tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl); | 679 | tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl); |
735 | 680 | ||
736 | function detectUrl (prop) { | 681 | function detectUrl (prop) { |