SHX-Theme/snippets/shx-product-desc.liquid

66 lines
2.1 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.innerHTML = `<div>Hello, world!</div>`;
}
initCurrentVariant(id) {
this.currentVariant = id;
// edit inner html
this.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.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) {
let video = thumbnail.querySelector('.shx-video');
if (video) {
// clone video to shadow dom
let videoClone = video.cloneNode(true);
this.appendChild(videoClone);
// get video element
let videoElement = this.querySelector('.shx-video');
videoElement.classList.add('shx-video-for-desc');
}
}
}
);
}
}
customElements.define('shx-drehteller', MyCustomElement);
</script>
{% endif %}