Last active
April 23, 2022 19:54
-
-
Save bendavis78/15528ca2f501c44f2fa4 to your computer and use it in GitHub Desktop.
Polymer 1.0 suppoert for template inside svg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?