{"version":3,"file":"Src_Scripts_components_modal_js.7ea1a15edf6adc6f0c48.js","sources":["webpack://AlmenNet.Setup/./Src/Scripts/components/modal.js"],"sourcesContent":["import VimeoPlayer from '@vimeo/player';\r\n\r\nexport default class Modal {\r\n constructor(elm) {\r\n\r\n if (!elm.dataset.modalId) { return; }\r\n\r\n const opener = document.querySelectorAll('[data-modal-opens=' + elm.dataset.modalId + ']');\r\n\r\n if (!opener) { return; }\r\n\r\n const iframe = elm.querySelector('iframe');\r\n const videoPlayer = elm.dataset.videoplayer;\r\n let vimeoPlayer = null;\r\n\r\n if (elm.dataset.videoPlayer === 'vimeo') {\r\n if (iframe) {\r\n vimeoPlayer = new VimeoPlayer(iframe);\r\n }\r\n }\r\n\r\n opener.forEach(x => x.addEventListener('click', function () { toggleModal(elm); }));\r\n elm.addEventListener('click', function (e)\r\n {\r\n e.preventDefault();\r\n if (!e.target.closest('video, iframe'))\r\n {\r\n toggleModal(elm);\r\n }\r\n });\r\n\r\n document.onkeydown = function (evt)\r\n {\r\n evt = evt || window.event;\r\n if (evt.keyCode === 27)\r\n {\r\n toggleModal(elm);\r\n }\r\n };\r\n\r\n var toggleModal = function (modal)\r\n {\r\n var video1 = modal.querySelector('.modal--active .media-with-video__video');\r\n\r\n if (modal.classList.contains('modal--active'))\r\n {\r\n // Closing\r\n modal.classList.remove('modal--active');\r\n\r\n // Stopping & resetting video if any\r\n if (iframe)\r\n {\r\n\r\n if (iframe.src.indexOf('?autoplay=1') > -1)\r\n {\r\n iframe.src = iframe.src.replace('?autoplay=1', '');\r\n }\r\n else\r\n {\r\n iframe.src = iframe.src.replace('&autoplay=1', '');\r\n }\r\n }\r\n if (video1)\r\n {\r\n video1.pause();\r\n video1.currentTime = 0;\r\n }\r\n }\r\n else\r\n {\r\n // Opening\r\n modal.classList.add('modal--active');\r\n\r\n // Playing video if any\r\n if (iframe)\r\n {\r\n document.resetUrl = iframe.src;\r\n if (iframe.src.indexOf('?autoplay=1') === -1 && iframe.src.indexOf('&autoplay=1') === -1)\r\n {\r\n if (iframe.src.indexOf('?') > -1)\r\n {\r\n iframe.src += '&autoplay=1';\r\n\r\n } else\r\n {\r\n iframe.src += '?autoplay=1';\r\n\r\n }\r\n }\r\n else\r\n {\r\n iframe.src = iframe.src;\r\n }\r\n }\r\n else\r\n {\r\n\r\n var video2 = modal.querySelector('.modal--active .media-with-video__video');\r\n video2.play();\r\n }\r\n }\r\n }; \r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AACA;;;AACA;AACA;AAEA;AAAA;AAAA;AACA;AACA;AACA;AACA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA;AACA;AAEA;AACA;AAAA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAAA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AAEA;AAGA;AAEA;AACA;AAGA;AACA;AACA;AACA;AAAA;AAEA;AACA;AACA;AACA;AAGA;AACA;AACA;AAEA;AAEA;AACA;AAAA;AAEA;AAEA;AAEA;AAEA;AAEA;AACA;AAGA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AArGA;AACA;A;;A;;A","sourceRoot":""}