55 lines
1.7 KiB
Plaintext
55 lines
1.7 KiB
Plaintext
{% assign content_type = content_type | default: 'awdawd' %}
|
|
|
|
{% if content_type == 'init' %}
|
|
|
|
<script type="text/javascript">
|
|
// create new html tag called "shx-drehteller"
|
|
|
|
class MyCustomElement extends HTMLElement {
|
|
constructor() {
|
|
super();
|
|
// element functionality written in here
|
|
this.currentVariant = null;
|
|
}
|
|
|
|
connectedCallback() {
|
|
this.attachShadow({ mode: 'open' }); // Attach a shadow root to the element.
|
|
}
|
|
|
|
initCurrentVariant(id) {
|
|
this.currentVariant = id;
|
|
|
|
// edit inner html
|
|
this.shadowRoot.innerHTML = `<div>Init variant: ${this.currentVariant}</div>`;
|
|
}
|
|
|
|
disconnectedCallback() {
|
|
// Clean up the element when it is removed from the DOM.
|
|
}
|
|
|
|
reloadCurrentVariant(id) {
|
|
this.currentVariant = id;
|
|
|
|
// edit inner html
|
|
this.shadowRoot.innerHTML = `<div>Current variant: ${this.currentVariant}</div>`;
|
|
|
|
document.querySelectorAll('[thumbnail-alt-mobile]').forEach((thumbnail) => {
|
|
console.log(thumbnail.getAttribute('thumbnail-alt-mobile'));
|
|
if (thumbnail.getAttribute('thumbnail-alt-mobile') === "__" + this.currentVariant) {
|
|
this.shadowRoot.innerHTML = thumbnail.outerHTML;
|
|
|
|
|
|
}
|
|
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
customElements.define('shx-drehteller', MyCustomElement);
|
|
</script>
|
|
|
|
|
|
{% endif %} |