{"version":3,"sources":["webpack:///../node_modules/load-script/index.js","webpack:///./handlers/modalVideoPlayer.js","webpack:///./utils/utils.js"],"names":["$","jQuery","CONSENT_COOKIE_NAME","CONSENT_REQUIRED_CATEGORY","initYoutubePlayer","videoId","$container","onYouTubePlayerAPIReady","append","$videoContainer","find","player","YT","Player","playerVars","playlist","mute","controls","enablejsapi","origin","window","location","events","e","playVideo","fn","loadScript","loading","id","setInterval","loaded","clearInterval","initVimeoPlayer","initPlayer","Vimeo","muted","dnt","ready","then","play","err","script","modalVideoPlayer","playButton","$videoModal","$closeButton","$noVideoWarningContainer","$noVideoCloseButton","$playButton","closeModal","removeClass","remove","playVideoInModal","addClass","youtubeVideoId","attr","vimeoVideoId","rawConsentCookie","getCookie","consentCookie","JSON","parse","categories","Array","isArray","length","indexOf","document","one","key","on","sleep","ms","Promise","resolve","setTimeout","isInViewport","element","rect","getBoundingClientRect","top","left","bottom","innerHeight","documentElement","clientHeight","right","innerWidth","clientWidth","name","cookieArr","cookie","split","i","cookiePair","trim","decodeURIComponent"],"mappings":";;;;;;;;;;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;AChEA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAMA,CAAC,GAAGC,MAAV;AACA;AAEA;AAEA,IAAMC,mBAAmB,GAAG,qBAA5B;AACA,IAAMC,yBAAyB,GAAG,WAAlC;;AAEA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,OAAD,EAAUC,UAAV,EAAyB;EAC/C,IAAMC,uBAAuB,GAAG,SAA1BA,uBAA0B,GAA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AAsC4B,CAAC,EAAvC,EAA2C;IACvC,IAAIC,UAAU,GAAGJ,SAAS,CAACG,CAAD,CAAT,CAAaD,KAAb,CAAmB,GAAnB,CAAjB;;IAEA,IAAIH,IAAI,IAAIK,UAAU,CAAC,CAAD,CAAV,CAAcC,IAAd,EAAZ,EAAkC;MAC9B,OAAOC,kBAAkB,CAACF,UAAU,CAAC,CAAD,CAAX,CAAzB;IACH;EACJ;;EAED,OAAO,IAAP;AACH","file":"modal-video-player.js","sourcesContent":["\nmodule.exports = function load (src, opts, cb) {\n  var head = document.head || document.getElementsByTagName('head')[0]\n  var script = document.createElement('script')\n\n  if (typeof opts === 'function') {\n    cb = opts\n    opts = {}\n  }\n\n  opts = opts || {}\n  cb = cb || function() {}\n\n  script.type = opts.type || 'text/javascript'\n  script.charset = opts.charset || 'utf8';\n  script.async = 'async' in opts ? !!opts.async : true\n  script.src = src\n\n  if (opts.attrs) {\n    setAttributes(script, opts.attrs)\n  }\n\n  if (opts.text) {\n    script.text = '' + opts.text\n  }\n\n  var onend = 'onload' in script ? stdOnEnd : ieOnEnd\n  onend(script, cb)\n\n  // some good legacy browsers (firefox) fail the 'in' detection above\n  // so as a fallback we always set onload\n  // old IE will ignore this and new IE will set onload\n  if (!script.onload) {\n    stdOnEnd(script, cb);\n  }\n\n  head.appendChild(script)\n}\n\nfunction setAttributes(script, attrs) {\n  for (var attr in attrs) {\n    script.setAttribute(attr, attrs[attr]);\n  }\n}\n\nfunction stdOnEnd (script, cb) {\n  script.onload = function () {\n    this.onerror = this.onload = null\n    cb(null, script)\n  }\n  script.onerror = function () {\n    // this.onload = null here is necessary\n    // because even IE9 works not like others\n    this.onerror = this.onload = null\n    cb(new Error('Failed to load ' + this.src), script)\n  }\n}\n\nfunction ieOnEnd (script, cb) {\n  script.onreadystatechange = function () {\n    if (this.readyState != 'complete' && this.readyState != 'loaded') return\n    this.onreadystatechange = null\n    cb(null, script) // there is no way to catch loading errors in IE8\n  }\n}\n","const $ = jQuery;\nimport loadScript from 'load-script';\n\nimport { getCookie } from '../utils/utils';\n\nconst CONSENT_COOKIE_NAME = 'CookieScriptConsent';\nconst CONSENT_REQUIRED_CATEGORY = 'targeting';\n\nconst initYoutubePlayer = (videoId, $container) => {\n    const onYouTubePlayerAPIReady = () => {\n        $container.append('<div></div>');\n        const $videoContainer = $container.find('div');\n\n        let player = new YT.Player($videoContainer[0], {\n            videoId: videoId,\n            playerVars: {\n                playlist: videoId,\n                mute: 0,\n                controls: 1,\n                enablejsapi: 1,\n                origin: window.location.origin\n            },\n            events: {\n                'onReady': (e) => {\n                    player.playVideo();\n                }\n            }\n        });\n    }\n\n    if (typeof YT === 'undefined') {\n        let fn = null;\n        if (window.onYouTubePlayerAPIReady) {\n            fn = window.onYouTubePlayerAPIReady;\n        }\n\n        window.onYouTubePlayerAPIReady = () => {\n            if(fn) {\n                fn();\n            }\n\n            onYouTubePlayerAPIReady()\n        };\n\n        loadScript('https://www.youtube.com/player_api');\n    } else if (YT.loading) {\n        let id = setInterval(() => {\n            if(YT.loaded) {\n                clearInterval(id);\n                onYouTubePlayerAPIReady();\n            }\n        }, 250);\n\n    } else {\n        onYouTubePlayerAPIReady();\n    }\n}\n\nconst initVimeoPlayer = (videoId, $container) => {\n    $container.append('<div></div>');\n    const $videoContainer = $container.find('div');\n\n    const initPlayer = () => {\n        let player = new Vimeo.Player($videoContainer[0], {\n            id: videoId,\n            muted: 0,\n            controls: 1,\n            dnt: 1\n        })\n\n        player.ready().then(() => {\n            player.play();\n        });\n    }\n\n    if (typeof window.Vimeo === 'undefined') {\n        loadScript('https://player.vimeo.com/api/player.js', (err, script) => {\n            if (err) {\n                throw 'Could not load Vimeo SDK';\n            }\n\n            initPlayer();\n        });\n    } else {\n        initPlayer();\n    }\n}\n\nconst modalVideoPlayer = (playButton) => {\n    const $videoContainer = $('.js-video-modal-container');\n    const $videoModal = $('.js-video-modal');\n    const $closeButton = $('.js-video-modal-close-button');\n    const $noVideoWarningContainer = $('.js-no-video-warning');\n    const $noVideoCloseButton = $('.js-close-video-warning');\n\n    const $playButton = $(playButton);\n\n    const closeModal = (e) => {\n        $videoModal.removeClass('js-video-modal-active');\n        // youtube appropriates div element and moves its classes & attrs to an iframe\n        $videoContainer.find('iframe').remove();\n        // vimeo injects iframe in div\n        $videoContainer.find('div').remove();\n        // hide any shown warnings\n        $noVideoWarningContainer.removeClass('js-visible');\n    };\n\n    const playVideoInModal = (e) => {\n        $videoModal.addClass('js-video-modal-active');\n\n        const youtubeVideoId = $playButton.attr('data-mentor-youtube-id');\n        const vimeoVideoId = $playButton.attr('data-mentor-vimeo-id');\n\n        // show warning if playing youtube video but targeting cookies not accepted\n        const rawConsentCookie = getCookie(CONSENT_COOKIE_NAME);\n        if (rawConsentCookie && youtubeVideoId) {\n            const consentCookie = JSON.parse(rawConsentCookie);\n            const categories = Array.isArray(consentCookie?.categories)\n                ? consentCookie.categories\n                : JSON.parse(consentCookie?.categories);\n\n            if (categories?.length === 0 || categories.indexOf(CONSENT_REQUIRED_CATEGORY) === -1) {\n                $noVideoWarningContainer.addClass('js-visible');\n                return;\n            } else {\n                $noVideoWarningContainer.removeClass('js-visible');\n            }\n        }\n\n        if (youtubeVideoId) {\n            initYoutubePlayer(youtubeVideoId, $videoContainer);\n        } else if (vimeoVideoId) {\n            initVimeoPlayer(vimeoVideoId, $videoContainer);\n        }\n\n        $(document).one('keyup', (e) => {\n            if (e.key === 'Escape') {\n                closeModal();\n            }\n        });\n    };\n\n    $playButton.on('click', playVideoInModal);\n    $closeButton.on('click', closeModal);\n    $noVideoCloseButton.on('click', closeModal);\n};\n\nexport default modalVideoPlayer;\nexport {\n    modalVideoPlayer\n};\n","function sleep(ms) {\n    return new Promise(resolve => setTimeout(resolve, ms));\n}\n\nfunction isInViewport(element) {\n    const rect = element.getBoundingClientRect();\n\n    return (\n        rect.top >= 0 &&\n        rect.left >= 0 &&\n        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&\n        rect.right <= (window.innerWidth || document.documentElement.clientWidth)\n    );\n}\n\nfunction getCookie(name) {\n    let cookieArr = document.cookie.split(\";\");\n\n    for (let i = 0; i < cookieArr.length; i++) {\n        let cookiePair = cookieArr[i].split(\"=\");\n\n        if (name == cookiePair[0].trim()) {\n            return decodeURIComponent(cookiePair[1]);\n        }\n    }\n\n    return null;\n}\n\nexport {\n    sleep,\n    isInViewport,\n    getCookie\n};\n"],"sourceRoot":""}