Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Polymer.Element without ShadowDOM but support slots
class LightDom extends Polymer.Element {
_attachDom(dom) {
const slots = dom.querySelectorAll('slot[name]');
slots.forEach((slot) => {
const name = slot.getAttribute('name');
const tmpl = this.querySelector(`[slot=${name}]`);
if (tmpl) {
slot.parentNode.replaceChild(tmpl, slot);
}
});
const slot = dom.querySelector('slot:not([name])');
if (slot) {
this.childNodes.forEach(e => {
slot.parentNode.insertBefore(e, slot.nextSibling);
});
slot.parentNode.removeChild(slot);
} else {
this.childNodes.forEach(e => {
this.removeChild(e);
});
}
this.appendChild(dom);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.