From 7fbda862c62f37d4c67e4d5a619b7e3cffc309ff Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 22 Mar 2012 16:23:40 -0700 Subject: Adding Ninja URL method to io-mediator --- js/document/html-document.js | 65 ++++---------------------------------------- 1 file changed, 5 insertions(+), 60 deletions(-) (limited to 'js/document') 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, { } // if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; - //Inserting user's document into template - - - - - - - - - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - //TODO: Clean up and make public method to prepend properties with Ninja URL - 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)); - 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)); - // - //var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); - // - function ninjaUrlRedirect (prop) { - //Checking for property value to not contain a full direct URL - 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)) { - //Checking for attributes and type of source - if (prop.indexOf('href') !== -1 || prop.indexOf('src') !== -1) { //From HTML attribute - // - prop = prop.replace(/"([^"]*)"/gi, ninjaUrlPrepend.bind(this)); - } else if (prop.indexOf('url') !== -1) { //From CSS property - //TODO: Add functionality - var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); - prop = prop.replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl); - function cssUrlToNinjaUrl (s) { - if (s !== 'url') { - s = docRootUrl + s; - } - return s; - } - } - } - return prop; - } - // - function ninjaUrlPrepend (url) { - var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); - if (url.indexOf('data:image') !== -1) { - return url; - } else { - return '"'+docRootUrl+url.replace(/\"/gi, '')+'"'; - } - } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - - - - + //TODO: Clean up, using for prototyping + 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)); + 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)); + var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; //TODO: Use querySelectorAll @@ -603,7 +549,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { - //Temporarily checking for disabled special case var stags = this.iframe.contentWindow.document.getElementsByTagName('style'), ltags = this.iframe.contentWindow.document.getElementsByTagName('link'); @@ -628,7 +573,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { - //Adding a handler for the main user document reel to finish loading this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); @@ -687,6 +631,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { // fileCouldDirUrl = this._document.styleSheets[i].href.split(this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1])[0]; + //TODO: Make public version of this.application.ninja.ioMediator.getNinjaPropUrlRedirect with dynamic ROOT tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl); function detectUrl (prop) { -- cgit v1.2.3