From 195624da6d0c5d15bcde8a8655355544687ef58a Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sun, 4 Mar 2012 19:21:34 -0800 Subject: Setting up document level URL parsing Set up logic to parse URLs document level (href, src, url) still need to add functionality to return proper value, currently only detecting current value. --- js/document/html-document.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/js/document/html-document.js b/js/document/html-document.js index a56a7e3c..1e41a797 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -408,10 +408,18 @@ exports.HTMLDocument = Montage.create(TextDocument, { // if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; //Inserting user's document into template - this._templateDocument.head.innerHTML = this._userDocument.content.head; - this._templateDocument.body.innerHTML = this._userDocument.content.body; - //TODO: Use querySelectorAll - var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; + + //TODO: Add logic to parse URLs from head/body + 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)); + // + function ninjaUrlRedirect (prop) { + console.log(prop); + return prop; + } + // + + var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; //TODO: Use querySelectorAll // for (var w in scripttags) { if (scripttags[w].getAttribute) { @@ -513,13 +521,9 @@ exports.HTMLDocument = Montage.create(TextDocument, { //TODO: Fix regEx to have logic for all possible URLs strings (currently prefixing all url()) - prefixUrl = 'url('+fileCouldDirUrl; + prefixUrl = 'url('+fileCouldDirUrl; //This should be re-written with better RegEx tag.innerHTML = cssData.content.replace(/url\(/gi, prefixUrl); - //console.log(("http://hello.com, https://google.com").replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, 'hello')) - - //console.log(tag.innerHTML); - //Looping through DOM to insert style tag at location of link element query = this._templateDocument.html.querySelectorAll(['link']); for (var j in query) { -- cgit v1.2.3