Skip to content

Instantly share code, notes, and snippets.

@bendavis78
Last active April 23, 2022 19:54
Show Gist options
  • Save bendavis78/15528ca2f501c44f2fa4 to your computer and use it in GitHub Desktop.
Save bendavis78/15528ca2f501c44f2fa4 to your computer and use it in GitHub Desktop.
Polymer 1.0 suppoert for template inside svg
// Templates inside SVG won't work in polymer-1.0 without some monkeypatching.
(function(){
var doc = document.currentScript.ownerDocument;
var root = doc.querySelector('dom-module > template').content;
var templates = root.querySelectorAll('svg template');
var el, template, attribs, attrib, count, child, content;
for (var i=0; i<templates.length; i++) {
el = templates[i];
template = el.ownerDocument.createElement('template');
el.parentNode.insertBefore(template, el);
attribs = el.attributes;
count = attribs.length;
while (count-- > 0) {
attrib = attribs[count];
template.setAttribute(attrib.name, attrib.value);
el.removeAttribute(attrib.name);
}
el.parentNode.removeChild(el);
content = template.content;
while ((child = el.firstChild)) {
content.appendChild(child);
}
}
})();
@howellmichael
Copy link

This doesn't seem to work after you vulcanize the app. I need to vulcanize as we are making a chrome plugin and it runs serverless. Any idea how to make this work with vulcanize?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment