Skip to content
This repository has been archived by the owner on Jan 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #44 from webcomponents/no-template-url-fix
Browse files Browse the repository at this point in the history
no url fixup in templates
  • Loading branch information
Steve Orvell authored Mar 3, 2017
2 parents c09f8f5 + 74c38f1 commit e76e93b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 66 deletions.
29 changes: 14 additions & 15 deletions html-imports.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion html-imports.min.js.map

Large diffs are not rendered by default.

52 changes: 2 additions & 50 deletions src/html-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,58 +49,11 @@
Path.replaceAttrUrl(element.getAttribute('src'), base));
}
if (element.localName === 'style') {
Path.resolveUrlsInStyle(element, base);
const r = Path.replaceUrls(element.textContent, base, CSS_URL_REGEXP);
element.textContent = Path.replaceUrls(r, base, CSS_IMPORT_REGEXP);
}
},

fixUrlAttributes(element, base) {
const attrs = ['action', 'src', 'href', 'url', 'style'];
for (let i = 0, a; i < attrs.length && (a = attrs[i]); i++) {
const at = element.attributes[a];
const v = at && at.value;
// Skip bound attribute values (assume binding is done via {} and []).
// TODO(valdrin) consider exposing a library-implementable hook.
if (v && (v.search(/({{|\[\[)/) < 0)) {
at.value = (a === 'style') ?
Path.resolveUrlsInCssText(v, base) :
Path.replaceAttrUrl(v, base);
}
}
},

fixUrlsInTemplates(element, base) {
const t$ = element.querySelectorAll('template');
for (let i = 0; i < t$.length; i++) {
Path.fixUrlsInTemplate(t$[i], base);
}
},

fixUrlsInTemplate(template, base) {
// If template is not supported, still resolve urls within it.
const content = template.content || template;
const n$ = content.querySelectorAll(
'style, form[action], [src], [href], [url], [style]');
for (let i = 0; i < n$.length; i++) {
const n = n$[i];
if (n.localName == 'style') {
Path.resolveUrlsInStyle(n, base);
} else {
Path.fixUrlAttributes(n, base);
}
}
Path.fixUrlsInTemplates(content, base);
},

resolveUrlsInStyle(style, linkUrl) {
style.textContent = Path.resolveUrlsInCssText(style.textContent, linkUrl);
},

resolveUrlsInCssText(cssText, linkUrl) {
let r = Path.replaceUrls(cssText, linkUrl, CSS_URL_REGEXP);
r = Path.replaceUrls(r, linkUrl, CSS_IMPORT_REGEXP);
return r;
},

replaceUrls(text, linkUrl, regexp) {
return text.replace(regexp, (m, pre, url, post) => {
let urlPath = url.replace(/["']/g, '');
Expand Down Expand Up @@ -365,7 +318,6 @@
inlineScriptIndex++;
}
}
Path.fixUrlsInTemplates(content, url);
return content;
}

Expand Down

0 comments on commit e76e93b

Please sign in to comment.