Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
factor url resolution slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Aug 23, 2013
1 parent ead1a04 commit badd01d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/HTMLImports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -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 + ")";
});
},
Expand All @@ -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) {
Expand Down

0 comments on commit badd01d

Please sign in to comment.