66 lines
2.1 KiB
Plaintext
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.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.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 %} |