From badd01d11b9ce0960fc62d54d8820f6fb24adf44 Mon Sep 17 00:00:00 2001 From: Steve Orvell Date: Fri, 23 Aug 2013 10:10:02 -0700 Subject: [PATCH] factor url resolution slightly --- src/HTMLImports.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/HTMLImports.js b/src/HTMLImports.js index e304d2d..3df66ba 100644 --- a/src/HTMLImports.js +++ b/src/HTMLImports.js @@ -266,7 +266,7 @@ var URL_TEMPLATE_SEARCH = '{{.*}}'; var path = { nodeUrl: function(node) { - return path.resolveUrl(path.getDocumentUrl(document), path.hrefOrSrc(node)); + return path.resolveUrl(path.documentURL, path.hrefOrSrc(node)); }, hrefOrSrc: function(node) { return node.getAttribute("href") || node.getAttribute("src"); @@ -283,15 +283,17 @@ var path = { // take only the left side if there is a # return url.split('#')[0]; }, - resolveUrl: function(baseUrl, url, relativeToDocument) { + resolveUrl: function(baseUrl, url) { if (this.isAbsUrl(url)) { return url; } - url = this.compressUrl(this.urlToPath(baseUrl) + url); - if (relativeToDocument) { - url = path.makeRelPath(path.getDocumentUrl(document), url); + return this.compressUrl(this.urlToPath(baseUrl) + url); + }, + resolveRelativeUrl: function(baseUrl, url) { + if (this.isAbsUrl(url)) { + return url; } - return url; + return path.makeRelPath(path.documentURL, this.resolveUrl(baseUrl, url)); }, isAbsUrl: function(url) { return /(^data:)|(^http[s]?:)|(^\/)/.test(url); @@ -369,7 +371,7 @@ var path = { return cssText.replace(/url\([^)]*\)/g, function(match) { // find the url path, ignore quotes in url string var urlPath = match.replace(/["']/g, "").slice(4, -1); - urlPath = path.resolveUrl(baseUrl, urlPath, true); + urlPath = path.resolveRelativeUrl(baseUrl, urlPath); return "url(" + urlPath + ")"; }); }, @@ -387,13 +389,15 @@ var path = { var attr = node.attributes[v]; if (attr && attr.value && (attr.value.search(URL_TEMPLATE_SEARCH) < 0)) { - var urlPath = path.resolveUrl(url, attr.value, true); + var urlPath = path.resolveRelativeUrl(url, attr.value); attr.value = urlPath; } }); } }; +path.documentURL = path.getDocumentUrl(document); + xhr = xhr || { async: true, ok: function(request) {