{"version":3,"file":"VideoModal.js","names":["defineDs","m","ObserverUtil","_Modal","controller","_ref","Object","assign","pageModalsCount","document","querySelectorAll","length","view","ignoreArgs","slots","class","concat","actionClassName","onclick","remove","href","Modal","$parent","extraClassNames","arguments","undefined","$container","createElement","classList","add","prop","onCloseCallback","classNames","split","forEach","className","close","event","stopPropagation","preventDefault","videoElement","querySelector","currentTime","pause","onClose","callback","setContent","content","initVideo","video","container","stopPlaying","addEventListener","_container$querySelec","observerCallback","mutation","observerInstance","type","addedNodes","node","tagName","contains","disconnect","build","_$parent","body","appendChild","setTimeout","observer","play","toggle","mount"],"sources":["DanskeSpil/Domain/NumberGames/Scripts/Templates/Shared/VideoModal.js"],"sourcesContent":["defineDs('DanskeSpil/Domain/NumberGames/Scripts/Templates/Shared/VideoModal',\r\n [\r\n 'Shared/Framework/Mithril/Scripts/Core/Mithril',\r\n 'DanskeSpil/Domain/NumberGames/Scripts/Helpers/MutationObserverUtil'\r\n ],\r\n function (m, ObserverUtil) {\r\n const _Modal = {\r\n controller: function ({ controller }) {\r\n Object.assign(this, controller);\r\n\r\n this.pageModalsCount = document.querySelectorAll('.generic-modal').length + 1;\r\n\r\n },\r\n view: function (controller, ignoreArgs, slots) {\r\n // View:\r\n return m('.generic-modal', {\r\n class: `generic-modal--${controller.pageModalsCount} ${controller.actionClassName()}`\r\n }, m('.generic-modal__card', [\r\n m('button.generic-modal__close-button', {\r\n onclick: controller.remove\r\n }, m('svg.icon-x', m('use', { href: '/Components/DanskeSpil/Domain/NumberGames/Graphics/SpriteSheets/NumberGamesGenericCommonIcons.svg#icon-x' }))),\r\n m('.generic-modal__card-content', slots())\r\n ]));\r\n }\r\n };\r\n\r\n const Modal = function ({ $parent, extraClassNames } = {}) {\r\n this.$container = document.createElement('div');\r\n this.$container.classList.add('generic-modal__container');\r\n const slots = m.prop(null);\r\n let onCloseCallback = m.prop(null);\r\n this.actionClassName = m.prop('generic-modal--active');\r\n\r\n if (extraClassNames?.length > 0) {\r\n const classNames = extraClassNames.split(' ');\r\n classNames.forEach((className) => {\r\n this.$container.classList.add(className);\r\n });\r\n }\r\n\r\n this.close = (event) => {\r\n if (event) {\r\n\r\n event.stopPropagation();\r\n event.preventDefault();\r\n }\r\n };\r\n\r\n this.remove = () => {\r\n onCloseCallback();\r\n const videoElement = this.$container.querySelector('video');\r\n if (videoElement) {\r\n videoElement.currentTime = 0;\r\n videoElement.pause();\r\n }\r\n this.$container.classList.add('hidden');\r\n };\r\n\r\n this.onClose = function (callback) {\r\n onCloseCallback = callback;\r\n };\r\n\r\n this.setContent = (content) => {\r\n slots(content);\r\n };\r\n\r\n const initVideo = (video, container, stopPlaying) => {\r\n if (stopPlaying) {\r\n video.pause();\r\n return;\r\n }\r\n video.addEventListener('loadeddata', () => {\r\n video.pause(); // Pause after preloading enough for a seamless start\r\n });\r\n video.addEventListener('canplay', () => {\r\n container.querySelector('.ds-cube-loader-wrapper')?.remove();\r\n });\r\n };\r\n\r\n const observerCallback = (mutation, observerInstance, container) => {\r\n if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {\r\n mutation.addedNodes.forEach((node) => {\r\n if (node.tagName === 'VIDEO') {\r\n initVideo(node, container, !document.contains(node));\r\n observerInstance.disconnect();\r\n }\r\n });\r\n }\r\n };\r\n\r\n this.build = () => {\r\n const _$parent = $parent || document.body;\r\n _$parent.appendChild(this.$container);\r\n\r\n setTimeout(() => {\r\n const videoElement = this.$container.querySelector('video');\r\n if (videoElement) {\r\n initVideo(videoElement, this.$container);\r\n } else {\r\n ObserverUtil.observer(this.$container, observerCallback);\r\n }\r\n });\r\n };\r\n\r\n this.play = () => {\r\n this.$container.classList.toggle('hidden');\r\n const videoElement = this.$container.querySelector('video');\r\n if (videoElement) {\r\n videoElement.currentTime = 0;\r\n videoElement.play();\r\n }\r\n\r\n };\r\n\r\n\r\n m.mount(this.$container, m(_Modal, { controller: this }, slots));\r\n };\r\n\r\n // Public functions:\r\n return Modal;\r\n });\r\n"],"mappings":"AAAAA,QAA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