From daaf460ac80d3db014c4c4a7ee0382d0046e151b Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Thu, 2 Mar 2017 16:46:27 -0800 Subject: [PATCH] Add `importPath` and `rootPath` to support 2.x hybrid compatible elements. --- src/lib/resolve-url.html | 16 ++++++- src/mini/template.html | 15 ++++++- src/standard/configure.html | 3 ++ src/standard/resolveUrl.html | 9 +--- test/unit/resolveurl.html | 62 ++++++++++++++++++++++++++ test/unit/sub/resolveurl-elements.html | 25 +++++++++++ 6 files changed, 120 insertions(+), 10 deletions(-) diff --git a/src/lib/resolve-url.html b/src/lib/resolve-url.html index 6b1b358c5b..74fc5f43fc 100644 --- a/src/lib/resolve-url.html +++ b/src/lib/resolve-url.html @@ -67,6 +67,16 @@ (ownerDocument.body.__urlResolver = ownerDocument.createElement('a')); } + /** + * Returns a path from a given `url`. The path includes the trailing + * `/` from the url. + * @param {string} url Input URL to transform + * @return {string} resolved path + */ + function pathFromUrl(url) { + return url.substring(0, url.lastIndexOf('/') + 1); + } + var CSS_URL_RX = /(url\()([^)]*)(\))/g; var URL_ATTRS = { '*': ['href', 'src', 'style', 'url'], @@ -79,9 +89,13 @@ Polymer.ResolveUrl = { resolveCss: resolveCss, resolveAttrs: resolveAttrs, - resolveUrl: resolveUrl + resolveUrl: resolveUrl, + pathFromUrl: pathFromUrl }; + // NOTE: IE11 does not support baseURI + Polymer.rootPath = pathFromUrl(document.baseURI || window.location.href); + })(); diff --git a/src/mini/template.html b/src/mini/template.html index c6e1296cbb..ca9587e29f 100644 --- a/src/mini/template.html +++ b/src/mini/template.html @@ -7,6 +7,7 @@ Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt --> + diff --git a/test/unit/sub/resolveurl-elements.html b/test/unit/sub/resolveurl-elements.html index 1fab8e53b4..6503acb256 100644 --- a/test/unit/sub/resolveurl-elements.html +++ b/test/unit/sub/resolveurl-elements.html @@ -31,6 +31,31 @@ Polymer({is: 'p-r'}); + + + + +