import LightboxManager from 'lightboxManager'; export default class SgVimeoLightbox { /** * Initializes the LightboxManager with the necessary parameters. */ constructor() { const vimeoItems = document.querySelectorAll('.sg-vimeo-item'); const isMobile = window.matchMedia('(max-width: 679px)').matches; vimeoItems.forEach((item) => { if ( (item.dataset.disableLightboxMobile === '1' && isMobile) || (item.dataset.disableLightbox === '1' && !isMobile) ) { item.classList.remove('sg-vimeo-item'); item.addEventListener('click', this.disableLightbox.bind(this)); } }); LightboxManager.init({ type: 'video', glightbox: { selector: '.sg-vimeo-item', plyr: { config: { // override 16:9 default ratio, so that plyr automatically detects the video dimensions // without this, vertical videos will have black bars around them, // see also: https://github.com/biati-digital/glightbox/issues/196#issuecomment-817070671 ratio: '', } } } }); } disableLightbox(event) { event.preventDefault(); const item = event.currentTarget; item.classList.add('no-lightbox'); const videoImage = item.querySelector('.sg-video__image'); const height = videoImage.offsetHeight; const width = videoImage.offsetWidth; const iframe = document.createElement('iframe'); if (item.href.indexOf('?') > 0) { iframe.src = item.href + '&dnt=1&autoplay=1'; } else { iframe.src = item.href + '?dnt=1&autoplay=1'; } iframe.width = width; iframe.height = height; iframe.style.border = 'none'; iframe.allowFullscreen = true; iframe.allow = 'autoplay; fullscreen; picture-in-picture'; item.replaceChild(iframe, videoImage); } }