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

Commit

Permalink
factor path code a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Jan 22, 2014
1 parent 99e7ac7 commit 10a5b68
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ var importParser = {
// NOTE: styles are the only elements that require direct path fixup.
function cloneStyle(style) {
var clone = style.ownerDocument.createElement('style');
clone.textContent = path.resolveUrlsInStyle(style);
clone.textContent = style.textContent;
path.resolveUrlsInStyle(clone);
return clone;
}

Expand All @@ -145,17 +146,21 @@ var path = {
resolveUrlsInStyle: function(style) {
var doc = style.ownerDocument;
var resolver = doc.createElement('a');
var cssText = this.resolveUrlsInCssText(style.textContent, resolver,
CSS_URL_REGEXP);
return this.resolveUrlsInCssText(cssText, resolver, CSS_IMPORT_REGEXP);
style.textContent = this.resolveUrlsInCssText(style.textContent, resolver);
return style;
},
resolveUrlsInCssText: function(cssText, resolver, regexp) {
return cssText.replace(regexp, function(m, pre, url, post) {
resolveUrlsInCssText: function(cssText, urlObj) {
var r = this.replaceUrls(cssText, urlObj, CSS_URL_REGEXP);
r = this.replaceUrls(r, urlObj, CSS_IMPORT_REGEXP);
return r;
},
replaceUrls: function(text, urlObj, regexp) {
return text.replace(regexp, function(m, pre, url, post) {
var urlPath = url.replace(/["']/g, '');
resolver.href = urlPath;
urlPath = resolver.href;
urlObj.href = urlPath;
urlPath = urlObj.href;
return pre + '\'' + urlPath + '\'' + post;
});
});
}
}

Expand Down

0 comments on commit 10a5b68

Please sign in to comment.