Slots Without Shadow Dom
![Slots Without Shadow Dom Slots Without Shadow Dom](https://olgakudrina.com/static/bba8cad710890dda1eed20e2bfb93036/56e34/3db863b8-552a-4704-91fe-da7c7f370ad2_Screen%2BShot%2B2020-07-11%2Bat%2B2.14.25%2BPM.png)
![Web components slots without shadow dom Web components slots without shadow dom](https://vaadin.com/static/content/learning-center/learn/tutorials/css-encapsulation-with-shadow-dom/images/html-and-dom-1.png)
index.js
// Custom Template/Slot without Shadow DOM |
// template refers to <template></template> |
// context refers to stuff inside <your-custom-element> <span slot='bork'>🍭</span> </your-custom-element> |
// overall flow of operation translates to YOUR-HTML = TEMPLATE(CONTEXT) |
// a map of all <slot name='bork'> elements, where key is the name attribute, and value the <slot name='bork'> node; |
consttemplate=newMap(Array.from(this.querySelectorAll('slot').values()).map(i=>[i.name,i])); |
// an array of [[name, element]] where name is the slot attribute of html element <span slot='bork'>🍭</span> |
constcontext=Array.from(this.querySelectorAll(':scope > *[slot]').values()).map(i=>[i.slot,i]); |
console.log(context) |
// traverse context, the list of elements with slot='*' property |
// name is taken from context (see above) |
// element is the thing we want to replace <slot> with |
for(const[slotName,element]ofcontext){ |
// slot is the <slot name='bork'> referenced by <span slot='bork'>🍭</span> inside your custom element |
constslot=template.get(slotName); |
// if template had the slot bork, replace the entire <slot name='bork'>*</slot> with <span slot='bork'>🍭</span> |
if(slot)slot.parentElement.replaceChild(element,slot);// Syntax: replacedNode = parentNode.replaceChild(newChild, oldChild); |
// remove the remove slot='bork' from <span slot='bork'>🍭</span> |
// NOTE: THIS IS NON SPEC, YOU SHOULD COMMENT THIS OUT FOR FUTURE COMPAT |
// element.removeAttribute('slot'); |
} |
Slots Without Shadow Domain
![Slots without shadow domain Slots without shadow domain](https://78.media.tumblr.com/df04b4d3e9bce3488b276a6b909e57c5/tumblr_naobeybkZM1qhttpto5_1280.jpg)
Web Components Slots Without Shadow Dom
No deposit bonus. When the best new online casino games are released, the casino can award a small no deposit for the new gamblers to draw new customers and allow them to play the new slots free. No deposit bonus means you are getting a certain amount of money (usually about $10) to play new slots online right after you create your casino account. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Custom Template/Slot without Shadow DOM. GitHub Gist: instantly share code, notes, and snippets. Aurelia Shadow DOM slots (Blog). GitHub Gist: instantly share code, notes, and snippets.
![Without Without](https://image.slidesharecdn.com/introductiontolightningwebcomponentonjanuary19th2019-190122133157/95/introduction-to-lightning-web-component-10-638.jpg?cb=1548164016)
![Slots without shadow domain Slots without shadow domain](https://alligator.io/images/polymer/polymer-shadow-dom.png)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
index.js
// Custom Template/Slot without Shadow DOM |
// template refers to <template></template> |
// context refers to stuff inside <your-custom-element> <span slot='bork'>🍭</span> </your-custom-element> |
// overall flow of operation translates to YOUR-HTML = TEMPLATE(CONTEXT) |
// a map of all <slot name='bork'> elements, where key is the name attribute, and value the <slot name='bork'> node; |
consttemplate=newMap(Array.from(this.querySelectorAll('slot').values()).map(i=>[i.name,i])); |
// an array of [[name, element]] where name is the slot attribute of html element <span slot='bork'>🍭</span> |
constcontext=Array.from(this.querySelectorAll(':scope > *[slot]').values()).map(i=>[i.slot,i]); |
console.log(context) |
// traverse context, the list of elements with slot='*' property |
// name is taken from context (see above) |
// element is the thing we want to replace <slot> with |
for(const[slotName,element]ofcontext){ |
// slot is the <slot name='bork'> referenced by <span slot='bork'>🍭</span> inside your custom element |
constslot=template.get(slotName); |
// if template had the slot bork, replace the entire <slot name='bork'>*</slot> with <span slot='bork'>🍭</span> |
if(slot)slot.parentElement.replaceChild(element,slot);// Syntax: replacedNode = parentNode.replaceChild(newChild, oldChild); |
// remove the remove slot='bork' from <span slot='bork'>🍭</span> |
// NOTE: THIS IS NON SPEC, YOU SHOULD COMMENT THIS OUT FOR FUTURE COMPAT |
// element.removeAttribute('slot'); |
} |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment