@@ -271,6 +271,8 @@ Loader.prototype = {
271
271
var URL_ATTRS = [ 'href' , 'src' , 'action' ] ;
272
272
var URL_ATTRS_SELECTOR = '[' + URL_ATTRS . join ( '],[' ) + ']' ;
273
273
var URL_TEMPLATE_SEARCH = '{{.*}}' ;
274
+ var CSS_URL_REGEXP = / ( u r l \( ) ( [ ^ ) ] * ) ( \) ) / g;
275
+ var CSS_IMPORT_REGEXP = / ( @ i m p o r t [ \s ] * ) ( [ ^ ; ] * ) ( ; ) / g;
274
276
275
277
var path = {
276
278
nodeUrl : function ( node ) {
@@ -334,8 +336,10 @@ var path = {
334
336
// test url against document to see if we can construct a relative path
335
337
path . urlElt . href = url ;
336
338
// 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 &&
339
343
path . urlElt . protocol === window . location . protocol ) ) {
340
344
return this . makeRelPath ( path . documentURL , path . urlElt . href ) ;
341
345
} else {
@@ -387,22 +391,14 @@ var path = {
387
391
}
388
392
} ,
389
393
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 ) ;
392
396
} ,
393
- resolveUrlInCssText : function ( cssText , baseUrl ) {
394
- return cssText . replace ( / ( u r l \( ) ( [ ^ ) ] * ) ( \) ) / g , function ( m , pre , url , post ) {
397
+ replaceUrlsInCssText : function ( cssText , baseUrl , regexp ) {
398
+ return cssText . replace ( regexp , function ( m , pre , url , post ) {
395
399
var urlPath = url . replace ( / [ " ' ] / g, '' ) ;
396
400
urlPath = path . resolveRelativeUrl ( baseUrl , urlPath ) ;
397
- return pre + urlPath + post ;
398
- } ) ;
399
- } ,
400
- resolveImportInCssText : function ( cssText , baseUrl ) {
401
- return cssText . replace ( / ( @ i m p o r t [ \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 ;
406
402
} ) ;
407
403
} ,
408
404
resolveAttributes : function ( root , url ) {
0 commit comments