Skip to content

Instantly share code, notes, and snippets.

@reosablo
Last active January 30, 2016 16:28
Show Gist options
  • Save reosablo/f932dcbc0bb8b9293777 to your computer and use it in GitHub Desktop.
Save reosablo/f932dcbc0bb8b9293777 to your computer and use it in GitHub Desktop.
// Templates inside SVG won't work in polymer-1.0 without some monkeypatching.
(function() {
var templates = document.currentScript.parentElement.querySelector("template").content.querySelectorAll("svg template");
Array.prototype.slice.call(templates).reverse().forEach(function(template) {
var new_template = template.ownerDocument.createElement("template");
template.parentElement.replaceChild(new_template, template);
Array.prototype.forEach.call(template.attributes, function(attribute) {
new_template.setAttribute(attribute.name, attribute.value);
});
for (var child; child = template.firstChild; new_template.content.appendChild(child));
});
})();
@reosablo
Copy link
Author

querySelector("svg template") elements should be processed descendants first (in reverse order) for nested <template>

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