aboutsummaryrefslogtreecommitdiff
path: root/js/document/html-document.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-03-22 16:23:40 -0700
committerJose Antonio Marquez2012-03-22 16:24:33 -0700
commitd87cded11dcc0faf41a4a3e6b587e5549c0da6df (patch)
treea6ab56d0ad88566b19d1472452657ab20c92a14b /js/document/html-document.js
parente9c6c5e333e097dfeadc944d9b7fcd8f4d3a06f6 (diff)
downloadninja-d87cded11dcc0faf41a4a3e6b587e5549c0da6df.tar.gz
Adding Ninja URL method to io-mediator
Diffstat (limited to 'js/document/html-document.js')
-rwxr-xr-xjs/document/html-document.js65
1 files changed, 5 insertions, 60 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index d4db6e2f..ed1569d4 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) {