diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-06-03 14:18:49 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-06-03 14:18:49 +0200 |
commit | 88e05fc523ec7a2c366b0e7831991efee538566c (patch) | |
tree | 29d748bfa2c967bfff54c3f4722c0cbae8074c93 /toolkit/components/reader/JSDOMParser.js | |
parent | 87d742b6832303266ce1bd737e3d421f0f809335 (diff) | |
parent | 83394569a1e3c6a48a5c0dbd380a1a7cf741d17a (diff) | |
download | UXP-88e05fc523ec7a2c366b0e7831991efee538566c.tar UXP-88e05fc523ec7a2c366b0e7831991efee538566c.tar.gz UXP-88e05fc523ec7a2c366b0e7831991efee538566c.tar.lz UXP-88e05fc523ec7a2c366b0e7831991efee538566c.tar.xz UXP-88e05fc523ec7a2c366b0e7831991efee538566c.zip |
Merge branch 'master' of https://github.com/MoonchildProductions/UXP
Diffstat (limited to 'toolkit/components/reader/JSDOMParser.js')
-rw-r--r-- | toolkit/components/reader/JSDOMParser.js | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/toolkit/components/reader/JSDOMParser.js b/toolkit/components/reader/JSDOMParser.js index 38f59c4ea..dd9d37230 100644 --- a/toolkit/components/reader/JSDOMParser.js +++ b/toolkit/components/reader/JSDOMParser.js @@ -560,7 +560,8 @@ }, }; - var Document = function () { + var Document = function (url) { + this.documentURI = url; this.styleSheets = []; this.childNodes = []; this.children = []; @@ -600,6 +601,20 @@ node.textContent = text; return node; }, + + get baseURI() { + if (!this.hasOwnProperty("_baseURI")) { + this._baseURI = this.documentURI; + var baseElements = this.getElementsByTagName("base"); + var href = baseElements[0] && baseElements[0].getAttribute("href"); + if (href) { + try { + this._baseURI = (new URL(href, this._baseURI)).href; + } catch (ex) {/* Just fall back to documentURI */} + } + } + return this._baseURI; + }, }; var Element = function (tag) { @@ -1118,9 +1133,9 @@ /** * Parses an HTML string and returns a JS implementation of the Document. */ - parse: function (html) { + parse: function (html, url) { this.html = html; - var doc = this.doc = new Document(); + var doc = this.doc = new Document(url); this.readChildren(doc); // If this is an HTML document, remove root-level children except for the |