diff options
author | Jose Antonio Marquez | 2012-03-04 19:21:34 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-03-04 19:21:34 -0800 |
commit | 195624da6d0c5d15bcde8a8655355544687ef58a (patch) | |
tree | c2a37f8ba6b3891e04546d5b6624f09391eb6f66 /js | |
parent | b2de52888a7c976cc9ae40518e3653cec0aac296 (diff) | |
download | ninja-195624da6d0c5d15bcde8a8655355544687ef58a.tar.gz |
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.
Diffstat (limited to 'js')
-rwxr-xr-x | js/document/html-document.js | 22 |
1 files 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, { | |||
408 | // | 408 | // |
409 | if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; | 409 | if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; |
410 | //Inserting user's document into template | 410 | //Inserting user's document into template |
411 | this._templateDocument.head.innerHTML = this._userDocument.content.head; | 411 | |
412 | this._templateDocument.body.innerHTML = this._userDocument.content.body; | 412 | //TODO: Add logic to parse URLs from head/body |
413 | //TODO: Use querySelectorAll | 413 | 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)); |
414 | var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; | 414 | 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)); |
415 | // | ||
416 | function ninjaUrlRedirect (prop) { | ||
417 | console.log(prop); | ||
418 | return prop; | ||
419 | } | ||
420 | // | ||
421 | |||
422 | var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; //TODO: Use querySelectorAll | ||
415 | // | 423 | // |
416 | for (var w in scripttags) { | 424 | for (var w in scripttags) { |
417 | if (scripttags[w].getAttribute) { | 425 | if (scripttags[w].getAttribute) { |
@@ -513,13 +521,9 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
513 | 521 | ||
514 | 522 | ||
515 | //TODO: Fix regEx to have logic for all possible URLs strings (currently prefixing all url()) | 523 | //TODO: Fix regEx to have logic for all possible URLs strings (currently prefixing all url()) |
516 | prefixUrl = 'url('+fileCouldDirUrl; | 524 | prefixUrl = 'url('+fileCouldDirUrl; //This should be re-written with better RegEx |
517 | tag.innerHTML = cssData.content.replace(/url\(/gi, prefixUrl); | 525 | tag.innerHTML = cssData.content.replace(/url\(/gi, prefixUrl); |
518 | 526 | ||
519 | //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')) | ||
520 | |||
521 | //console.log(tag.innerHTML); | ||
522 | |||
523 | //Looping through DOM to insert style tag at location of link element | 527 | //Looping through DOM to insert style tag at location of link element |
524 | query = this._templateDocument.html.querySelectorAll(['link']); | 528 | query = this._templateDocument.html.querySelectorAll(['link']); |
525 | for (var j in query) { | 529 | for (var j in query) { |