Skip to content

Instantly share code, notes, and snippets.

@asika32764
Created April 7, 2018 20:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asika32764/e158f74b863cd73cfcc9c826029f1651 to your computer and use it in GitHub Desktop.
Save asika32764/e158f74b863cd73cfcc9c826029f1651 to your computer and use it in GitHub Desktop.
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