Created
April 7, 2018 20:00
-
-
Save asika32764/e158f74b863cd73cfcc9c826029f1651 to your computer and use it in GitHub Desktop.
Polymer.Element without ShadowDOM but support slots
This file contains 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
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