diff options
Diffstat (limited to 'js')
-rwxr-xr-x | js/document/html-document.js | 65 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 56 |
2 files changed, 57 insertions, 64 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) { |
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index d81f4543..df0a41df 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -470,8 +470,6 @@ function loadWebGL (e) {\n\ | |||
470 | getUrlfromNinjaUrl: { | 470 | getUrlfromNinjaUrl: { |
471 | enumerable: false, | 471 | enumerable: false, |
472 | value: function (url, fileRootUrl, fileUrl) { | 472 | value: function (url, fileRootUrl, fileUrl) { |
473 | //console.log("Params: ", url, fileRootUrl, fileUrl); | ||
474 | //console.log("Getting: " + url); | ||
475 | // | 473 | // |
476 | if (url.indexOf(fileRootUrl) !== -1) { | 474 | if (url.indexOf(fileRootUrl) !== -1) { |
477 | url = url.replace(new RegExp(fileRootUrl.replace(/\//gi, '\\\/'), 'gi'), ''); | 475 | url = url.replace(new RegExp(fileRootUrl.replace(/\//gi, '\\\/'), 'gi'), ''); |
@@ -499,13 +497,63 @@ function loadWebGL (e) {\n\ | |||
499 | // | 497 | // |
500 | url = (path+newURL).replace(/\/\//gi, '/'); | 498 | url = (path+newURL).replace(/\/\//gi, '/'); |
501 | } | 499 | } |
502 | //console.log("Returning: " + url); | ||
503 | //console.log("-----"); | ||
504 | // | 500 | // |
505 | return url; | 501 | return url; |
506 | } | 502 | } |
507 | }, | 503 | }, |
508 | //////////////////////////////////////////////////////////////////// | 504 | //////////////////////////////////////////////////////////////////// |
505 | // | ||
506 | getDocRootUrl: { | ||
507 | value: function () { | ||
508 | return this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); | ||
509 | } | ||
510 | }, | ||
511 | //////////////////////////////////////////////////////////////////// | ||
512 | // | ||
513 | getNinjaPropUrlRedirect: { | ||
514 | enumerable: false, | ||
515 | value: function (prop/* , root */) { | ||
516 | //Checking for property value to not contain a full direct URL | ||
517 | 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)) { | ||
518 | //Checking for attributes and type of source | ||
519 | if (prop.indexOf('href') !== -1 || prop.indexOf('src') !== -1) { | ||
520 | //From HTML attribute | ||
521 | //if (root) { | ||
522 | //prop = (root+prop).replace(/"([^"]*)"/gi, this.getNinjaUrlPrepend.bind(this)); | ||
523 | //} else { | ||
524 | prop = prop.replace(/"([^"]*)"/gi, this.getNinjaUrlPrepend.bind(this)); | ||
525 | //} | ||
526 | } else if (prop.indexOf('url') !== -1) { | ||
527 | //From CSS property | ||
528 | //if (root) { | ||
529 | //prop = (root+prop).replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl.bind(this)); | ||
530 | //} else { | ||
531 | prop = prop.replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl.bind(this)); | ||
532 | //} | ||
533 | function cssUrlToNinjaUrl (s) { | ||
534 | if (s !== 'url') { | ||
535 | s = this.getDocRootUrl() + s; | ||
536 | } | ||
537 | return s; | ||
538 | } | ||
539 | } | ||
540 | } | ||
541 | return prop; | ||
542 | } | ||
543 | }, | ||
544 | //////////////////////////////////////////////////////////////////// | ||
545 | // | ||
546 | getNinjaUrlPrepend: { | ||
547 | enumerable: false, | ||
548 | value: function (url) { | ||
549 | if (url.indexOf('data:') !== -1) { | ||
550 | return url; | ||
551 | } else { | ||
552 | return '"'+this.getDocRootUrl()+url.replace(/\"/gi, '')+'"'; | ||
553 | } | ||
554 | } | ||
555 | }, | ||
556 | //////////////////////////////////////////////////////////////////// | ||
509 | //Method to return a string from CSS rules (to be saved to a file) | 557 | //Method to return a string from CSS rules (to be saved to a file) |
510 | getCssFromRules: { | 558 | getCssFromRules: { |
511 | enumerable: false, | 559 | enumerable: false, |