diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/components/microformats/test/lib/url.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/microformats/test/lib/url.js')
-rw-r--r-- | toolkit/components/microformats/test/lib/url.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/toolkit/components/microformats/test/lib/url.js b/toolkit/components/microformats/test/lib/url.js new file mode 100644 index 000000000..81ed9f29e --- /dev/null +++ b/toolkit/components/microformats/test/lib/url.js @@ -0,0 +1,73 @@ +/* + url + Where possible use the modern window.URL API if its not available use the DOMParser method. + + Copyright (C) 2010 - 2015 Glenn Jones. All Rights Reserved. + MIT License: https://raw.github.com/glennjones/microformat-shiv/master/license.txt +*/ + +var Modules = (function (modules) { + + + modules.url = { + + + /** + * creates DOM objects needed to resolve URLs + */ + init: function(){ + //this._domParser = new DOMParser(); + this._domParser = modules.domUtils.getDOMParser(); + // do not use a head tag it does not work with IE9 + this._html = '<base id="base" href=""></base><a id="link" href=""></a>'; + this._nodes = this._domParser.parseFromString( this._html, 'text/html' ); + this._baseNode = modules.domUtils.getElementById(this._nodes,'base'); + this._linkNode = modules.domUtils.getElementById(this._nodes,'link'); + }, + + + /** + * resolves url to absolute version using baseUrl + * + * @param {String} url + * @param {String} baseUrl + * @return {String} + */ + resolve: function(url, baseUrl) { + // use modern URL web API where we can + if(modules.utils.isString(url) && modules.utils.isString(baseUrl) && url.indexOf('://') === -1){ + // this try catch is required as IE has an URL object but no constuctor support + // http://glennjones.net/articles/the-problem-with-window-url + try { + var resolved = new URL(url, baseUrl).toString(); + // deal with early Webkit not throwing an error - for Safari + if(resolved === '[object URL]'){ + resolved = URI.resolve(baseUrl, url); + } + return resolved; + }catch(e){ + // otherwise fallback to DOM + if(this._domParser === undefined){ + this.init(); + } + + // do not use setAttribute it does not work with IE9 + this._baseNode.href = baseUrl; + this._linkNode.href = url; + + // dont use getAttribute as it returns orginal value not resolved + return this._linkNode.href; + } + }else{ + if(modules.utils.isString(url)){ + return url; + } + return ''; + } + }, + + }; + + return modules; + +} (Modules || {})); |