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

Commit df7aea9

Browse files
committed
slight factoring
1 parent ea79e75 commit df7aea9

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/HTMLImports.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ Loader.prototype = {
271271
var URL_ATTRS = ['href', 'src', 'action'];
272272
var URL_ATTRS_SELECTOR = '[' + URL_ATTRS.join('],[') + ']';
273273
var URL_TEMPLATE_SEARCH = '{{.*}}';
274+
var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g;
275+
var CSS_IMPORT_REGEXP = /(@import[\s]*)([^;]*)(;)/g;
274276

275277
var path = {
276278
nodeUrl: function(node) {
@@ -334,8 +336,10 @@ var path = {
334336
// test url against document to see if we can construct a relative path
335337
path.urlElt.href = url;
336338
// IE does not set host if same as document
337-
if (!path.urlElt.host ||
338-
(path.urlElt.host === window.location.host &&
339+
if (!path.urlElt.host ||
340+
(!window.location.port && path.urlElt.port === '80') ||
341+
(path.urlElt.hostname === window.location.hostname &&
342+
path.urlElt.port === window.location.port &&
339343
path.urlElt.protocol === window.location.protocol)) {
340344
return this.makeRelPath(path.documentURL, path.urlElt.href);
341345
} else {
@@ -387,22 +391,14 @@ var path = {
387391
}
388392
},
389393
resolveCssText: function(cssText, baseUrl) {
390-
var cssText = path.resolveUrlInCssText(cssText, baseUrl);
391-
return path.resolveImportInCssText(cssText, baseUrl);
394+
var cssText = path.replaceUrlsInCssText(cssText, baseUrl, CSS_URL_REGEXP);
395+
return path.replaceUrlsInCssText(cssText, baseUrl, CSS_IMPORT_REGEXP);
392396
},
393-
resolveUrlInCssText: function(cssText, baseUrl) {
394-
return cssText.replace(/(url\()([^)]*)(\))/g, function(m, pre, url, post) {
397+
replaceUrlsInCssText: function(cssText, baseUrl, regexp) {
398+
return cssText.replace(regexp, function(m, pre, url, post) {
395399
var urlPath = url.replace(/["']/g, '');
396400
urlPath = path.resolveRelativeUrl(baseUrl, urlPath);
397-
return pre + urlPath + post;
398-
});
399-
},
400-
resolveImportInCssText: function(cssText, baseUrl) {
401-
return cssText.replace(/(@import[\s]*)([^;]*)(;)/g,
402-
function(m, pre, url, post) {
403-
var urlPath = url.replace(/["']/g, '');
404-
urlPath = path.resolveRelativeUrl(baseUrl, urlPath);
405-
return pre + urlPath + post;
401+
return pre + '\'' + urlPath + '\'' + post;
406402
});
407403
},
408404
resolveAttributes: function(root, url) {

0 commit comments

Comments
 (0)