safer JS demo encapsulation
This commit is contained in:
parent
5e201b8d71
commit
6805cefbac
|
@ -38,6 +38,21 @@ p {
|
|||
|
||||
<p>Nulla vel magna sit — amet dui lobortis commodo — vitae vel nulla. Nulla lobortis tempus commodo. </p>
|
||||
|
||||
{{<demo>}}
|
||||
<p>Everyone must not be having a laugh.</p>
|
||||
<style>
|
||||
p {
|
||||
color: blue !important;
|
||||
font-family: cursive;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
demo.querySelector('p').addEventListener('click', function() {
|
||||
alert('fuck');
|
||||
})
|
||||
</script>
|
||||
{{</demo>}}
|
||||
|
||||
{{% ticks %}}
|
||||
* Something good
|
||||
* Something else good
|
||||
|
|
|
@ -11,9 +11,10 @@
|
|||
root.attachShadow({mode: 'open'});
|
||||
var template = document.getElementById('template-{{ $uniq }}');
|
||||
var script = template.content.querySelector('script');
|
||||
script.textContent = 'var demo = document.getElementById(\'demo-{{ $uniq }}\').shadowRoot;' + script.textContent;
|
||||
if (script) {
|
||||
script.textContent = `(function() { var demo = document.getElementById(\'demo-{{ $uniq }}\').shadowRoot; ${script.textContent} })()`
|
||||
}
|
||||
root.shadowRoot.appendChild(document.importNode(template.content, true));
|
||||
console.log(root);
|
||||
})();
|
||||
</script>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user