{ "version": 3, "sources": ["../../../Vettvangur.Frontend/src/scripts/components/podcast-player.ts"], "sourcesContent": ["import { breakpoint } from 'utility/breakpoints'\n\nconst podcastPlayer = {\n el: {\n background: document.querySelector('.podcast-player__background'),\n cards: document.querySelectorAll('.podcast-card'),\n closeButton: document.querySelector('.podcast-player__close-button'),\n embed: document.querySelector('.podcast-player__embed'),\n modal: document.querySelector('.podcast-player'),\n },\n\n EmbedController: null,\n IFrameAPI: null,\n isInitialized: false,\n\n init(): void {\n this.el.cards.forEach((card) => {\n card.addEventListener('click', () => {\n const uri = card.dataset.spotifyUri\n\n this.el.modal.classList.add('podcast-player--active')\n this.initPlayer(uri)\n })\n })\n ;[this.el.background, this.el.closeButton].forEach((trigger) => {\n trigger.addEventListener('click', this.closePodcast.bind(this))\n })\n },\n\n initPlayer(uri): void {\n const element = this.el.embed.firstElementChild\n const options = {\n height: '352',\n width: window.innerWidth < breakpoint.tablet ? '320' : '700',\n uri: uri,\n }\n\n if (!this.isInitialized) {\n const scriptElement = document.createElement('script')\n\n scriptElement.async = true\n scriptElement.src = 'https://open.spotify.com/embed/iframe-api/v1'\n scriptElement.type = 'text/javascript'\n\n this.el.modal.appendChild(scriptElement)\n\n // @ts-ignore\n window.onSpotifyIframeApiReady = (IFrameAPI) => {\n const callback = (EmbedController) => {\n this.EmbedController = EmbedController\n this.IFrameAPI = IFrameAPI\n this.isInitialized = true\n this.playPodcast()\n }\n\n IFrameAPI.createController(element, options, callback)\n }\n } else {\n const callback = (EmbedController) => {\n this.EmbedController = EmbedController\n this.playPodcast()\n }\n\n this.IFrameAPI.createController(element, options, callback)\n }\n },\n\n closeOnEscPress(event): void {\n if (event.key.match('Escape') && this.el.modal.classList.contains('podcast-player--active')) {\n this.closePodcast()\n }\n },\n\n closePodcast(): void {\n this.el.modal.classList.remove('podcast-player--active')\n\n setTimeout(() => {\n this.el.modal.classList.remove('podcast-player--ready')\n this.EmbedController.destroy()\n this.el.embed.innerHTML = '
'\n window.removeEventListener('keydown', this.closeOnEscPress.bind(this))\n }, 345)\n },\n\n playPodcast(): void {\n this.EmbedController.addListener('ready', () => {\n window.addEventListener('keydown', this.closeOnEscPress.bind(this))\n\n setTimeout(() => {\n this.el.modal.classList.add('podcast-player--ready')\n this.EmbedController.play()\n }, 345)\n })\n },\n}\n\nexport default podcastPlayer\n"], "mappings": "4EAEA,IAAMA,EAAgB,CACpB,GAAI,CACF,WAAY,SAAS,cAA2B,6BAA6B,EAC7E,MAAO,SAAS,iBAA8B,eAAe,EAC7D,YAAa,SAAS,cAA2B,+BAA+B,EAChF,MAAO,SAAS,cAA2B,wBAAwB,EACnE,MAAO,SAAS,cAA2B,iBAAiB,CAC9D,EAEA,gBAAiB,KACjB,UAAW,KACX,cAAe,GAEf,MAAa,CACX,KAAK,GAAG,MAAM,QAASC,GAAS,CAC9BA,EAAK,iBAAiB,QAAS,IAAM,CACnC,IAAMC,EAAMD,EAAK,QAAQ,WAEzB,KAAK,GAAG,MAAM,UAAU,IAAI,wBAAwB,EACpD,KAAK,WAAWC,CAAG,CACrB,CAAC,CACH,CAAC,EACA,CAAC,KAAK,GAAG,WAAY,KAAK,GAAG,WAAW,EAAE,QAASC,GAAY,CAC9DA,EAAQ,iBAAiB,QAAS,KAAK,aAAa,KAAK,IAAI,CAAC,CAChE,CAAC,CACH,EAEA,WAAWD,EAAW,CACpB,IAAME,EAAU,KAAK,GAAG,MAAM,kBACxBC,EAAU,CACd,OAAQ,MACR,MAAO,OAAO,WAAaC,EAAW,OAAS,MAAQ,MACvD,IAAKJ,CACP,EAEA,GAAK,KAAK,cAoBH,CACL,IAAMK,EAAYC,GAAoB,CACpC,KAAK,gBAAkBA,EACvB,KAAK,YAAY,CACnB,EAEA,KAAK,UAAU,iBAAiBJ,EAASC,EAASE,CAAQ,CAC5D,KA3ByB,CACvB,IAAME,EAAgB,SAAS,cAAc,QAAQ,EAErDA,EAAc,MAAQ,GACtBA,EAAc,IAAM,+CACpBA,EAAc,KAAO,kBAErB,KAAK,GAAG,MAAM,YAAYA,CAAa,EAGvC,OAAO,wBAA2BC,GAAc,CAC9C,IAAMH,EAAYC,GAAoB,CACpC,KAAK,gBAAkBA,EACvB,KAAK,UAAYE,EACjB,KAAK,cAAgB,GACrB,KAAK,YAAY,CACnB,EAEAA,EAAU,iBAAiBN,EAASC,EAASE,CAAQ,CACvD,CACF,CAQF,EAEA,gBAAgBI,EAAa,CACvBA,EAAM,IAAI,MAAM,QAAQ,GAAK,KAAK,GAAG,MAAM,UAAU,SAAS,wBAAwB,GACxF,KAAK,aAAa,CAEtB,EAEA,cAAqB,CACnB,KAAK,GAAG,MAAM,UAAU,OAAO,wBAAwB,EAEvD,WAAW,IAAM,CACf,KAAK,GAAG,MAAM,UAAU,OAAO,uBAAuB,EACtD,KAAK,gBAAgB,QAAQ,EAC7B,KAAK,GAAG,MAAM,UAAY,cAC1B,OAAO,oBAAoB,UAAW,KAAK,gBAAgB,KAAK,IAAI,CAAC,CACvE,EAAG,GAAG,CACR,EAEA,aAAoB,CAClB,KAAK,gBAAgB,YAAY,QAAS,IAAM,CAC9C,OAAO,iBAAiB,UAAW,KAAK,gBAAgB,KAAK,IAAI,CAAC,EAElE,WAAW,IAAM,CACf,KAAK,GAAG,MAAM,UAAU,IAAI,uBAAuB,EACnD,KAAK,gBAAgB,KAAK,CAC5B,EAAG,GAAG,CACR,CAAC,CACH,CACF,EAEOC,EAAQZ", "names": ["podcastPlayer", "card", "uri", "trigger", "element", "options", "breakpoint", "callback", "EmbedController", "scriptElement", "IFrameAPI", "event", "podcast_player_default"] }