File: /var/www/quadcode/frontend/src/js/components/modal/ModalVideo.js
export const ModalVideo = (name) => {
const modalEl = document.querySelector(`[data-widget="${name}"]`);
const btnEl = document.querySelectorAll(`[data-role="${name}"]`);
if (modalEl) {
const iFrame = modalEl.querySelector('.modal-video__iframe');
if (btnEl.length === 0 && !modalEl) return false;
const btnModalEl = modalEl.querySelector('.modal-video__close');
const open = () => {
document.body.style.overflowY = 'hidden';
return modalEl.classList.add('modal-video--active');
}
const close = () => {
if (iFrame) {
iFrame.src = '';
}
document.body.style.overflowY = 'scroll';
return modalEl.classList.remove('modal-video--active');
}
btnEl.forEach((item) => {
item.addEventListener('click', () => {
if (iFrame) {
iFrame.src = item.dataset.src;
}
open();
}, false);
})
btnModalEl.addEventListener('click', close, false);
}
}