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,iBACfnD,EAAiCC,SAAQ,SAAAkE,GAEnCA,EAAMV,OAAOW,WAAYb,EAAAA,EAAAA,IAA6B/D,SAASa,cAAc,IAADgE,OAAKF,EAAMhE,OACzFgE,EAAMV,OAAOa,QACbH,EAAMI,YAAa,GACTJ,EAAMV,OAAOW,UAAYD,EAAMI,aAAcJ,EAAMb,WAC7Da,EAAMV,OAAOe,OACbL,EAAMb,UAAW,EACjBa,EAAMI,YAAa,EAEvB,IAEJ,GAIFL,IAEA9E,OAAOuC,iBAAiB,SAAUuC,EACpC,G","sources":["webpack://fitflop-storefront/./core-app/grails-app/assets/javascripts/app/cmscomponents/videoBanner/videoBanner.js"],"sourcesContent":["import { isElementVisibleWithinParent, findAncestorBySelector } from 'app/utils/helpers';\nimport { loadAsyncScript } from 'app/utils/ajaxHelpers';\nimport mediaQueries from 'app/utils/mediaQueries';\nimport './video.scss';\n\nconst { plyr } = window.inlineGlobalConfig.hashedPaths;\nconst videoBannerComponents = [...document.querySelectorAll('.video-banner')].filter(\n  videoBanner => !findAncestorBySelector(videoBanner, '#content-spots')\n);\n\nif (videoBannerComponents.length) {\n  loadAsyncScript(plyr).then(() => {\n    const videoBannerComponentsInitialized = [];\n    videoBannerComponents.forEach(videoBanner => {\n      const videoId = videoBanner.id;\n      const videoElement = videoBanner.querySelector('video');\n      const { videoOptions, ctaBanner, url, target, linkName } = videoBanner.dataset;\n\n      try {\n        if (!videoOptions && !videoBanner.classList.contains('video-banner--in-media')) {\n          throw Error('Options are empty');\n        }\n\n        const setClickableArea = entireVideoBanner => {\n          const eventListenerFunc = event => {\n            if (target.toUpperCase() === 'SAMEWINDOW') {\n              window.location.href = url;\n            } else {\n              window.open(url);\n            }\n            event.stopPropagation();\n          };\n\n          const addOnClickFunc = el => {\n            el.addEventListener('click', eventListenerFunc);\n          };\n\n          setTimeout(() => {\n            if (entireVideoBanner) {\n              const videoBannerWrapper = videoBanner.querySelector('.plyr__video-wrapper');\n\n              videoBannerWrapper.classList.add('with-pointer-events');\n              addOnClickFunc(videoBannerWrapper);\n            } else {\n              const realEstateCta = videoBanner.querySelector('.copy');\n              if (realEstateCta) {\n                const childElements = Array.prototype.slice.call(realEstateCta.children);\n                childElements.forEach(el => {\n                  el.classList.add('with-pointer-events');\n                  addOnClickFunc(el);\n                });\n              }\n            }\n          }, 0);\n        };\n\n        if (linkName) {\n          videoBanner.querySelector('a').classList.add('label-background');\n        }\n        if (ctaBanner === 'true') {\n          setClickableArea(true);\n        } else if (!linkName) {\n          setClickableArea(false);\n        }\n\n        const options = videoOptions ? JSON.parse(videoOptions.replace(/"/g, '\"')) : {};\n        const shadow = options.shadow && options.controls.length !== 0;\n        if (!shadow) {\n          setTimeout(() => {\n            const playerControls = videoBanner.querySelector('.plyr__controls');\n            playerControls.classList.add('no-shadow');\n          }, 0);\n        }\n        const duration = options.displayTime || null;\n        if (duration) {\n          window.addEventListener('load', () => {\n            const plyrEl = videoBanner.querySelector('.plyr');\n            plyrEl.classList.add('plyr--hide-controls');\n          });\n\n          const handlePlyrControlVisibility = event => {\n            const plyrEl = videoBanner.querySelector('.plyr');\n            event.preventDefault();\n            plyrEl.classList.remove('plyr--hide-controls');\n            setTimeout(() => {\n              plyrEl.classList.add('plyr--hide-controls');\n            }, duration * 1000);\n          };\n\n          const handlePlyrOnResize = () => {\n            const isSmall = mediaQueries.is_small_only();\n            const isMedium = mediaQueries.is_medium_only();\n\n            if (isSmall || isMedium) {\n              videoBanner.removeEventListener('mouseenter', handlePlyrControlVisibility);\n              videoBanner.addEventListener('click', handlePlyrControlVisibility);\n            } else {\n              videoBanner.removeEventListener('click', handlePlyrControlVisibility);\n              videoBanner.addEventListener('mouseenter', handlePlyrControlVisibility);\n            }\n          };\n\n          const handlePlyrControlOnResize = handlePlyrOnResize;\n          handlePlyrControlOnResize();\n\n          window.addEventListener('resize', handlePlyrControlOnResize);\n        }\n        const autoplay = options.autoplay && isElementVisibleWithinParent(videoElement);\n        videoBannerComponentsInitialized.push({\n          player: new window.Plyr(videoElement, {\n            ...options,\n            autoplay,\n            hideControls: false,\n          }),\n          autoplay: options.autoplay,\n          id: videoId,\n        });\n      } catch (err) {\n        console.error(err);\n      }\n    });\n    const handleVideosByVisibility = () => {\n      let isSmallOnly = mediaQueries.is_small_only();\n      let isMediumOnly = mediaQueries.is_medium_only();\n\n      return () => {\n        if (isSmallOnly !== mediaQueries.is_small_only() || isMediumOnly !== mediaQueries.is_medium_only()) {\n          isSmallOnly = mediaQueries.is_small_only();\n          isMediumOnly = mediaQueries.is_medium_only();\n          videoBannerComponentsInitialized.forEach(video => {\n            /* eslint-disable no-param-reassign */\n            if (video.player.playing && !isElementVisibleWithinParent(document.querySelector(`#${video.id}`))) {\n              video.player.pause();\n              video.wasPlaying = true;\n            } else if (!video.player.playing && (video.wasPlaying || video.autoplay)) {\n              video.player.play();\n              video.autoplay = false;\n              video.wasPlaying = false;\n            }\n          });\n        }\n      };\n    };\n\n    const handleViewportChanges = handleVideosByVisibility();\n    handleViewportChanges();\n\n    window.addEventListener('resize', handleViewportChanges);\n  });\n}\n"],"names":["plyr","window","inlineGlobalConfig","hashedPaths","videoBannerComponents","document","querySelectorAll","filter","videoBanner","findAncestorBySelector","length","loadAsyncScript","then","videoBannerComponentsInitialized","forEach","videoId","id","videoElement","querySelector","_videoBanner$dataset","dataset","videoOptions","ctaBanner","url","target","linkName","classList","contains","Error","setClickableArea","entireVideoBanner","eventListenerFunc","event","toUpperCase","location","href","open","stopPropagation","addOnClickFunc","el","addEventListener","setTimeout","videoBannerWrapper","add","realEstateCta","Array","prototype","slice","call","children","options","JSON","parse","replace","shadow","controls","duration","displayTime","handlePlyrControlVisibility","plyrEl","preventDefault","remove","handlePlyrControlOnResize","isSmall","mediaQueries","isMedium","removeEventListener","autoplay","isElementVisibleWithinParent","push","player","Plyr","_objectSpread","hideControls","err","console","error","isSmallOnly","isMediumOnly","handleViewportChanges","video","playing","concat","pause","wasPlaying","play"],"sourceRoot":""}