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EAAiB1B,EAAO2B,mBAAmBF,IAEzB,IAApBC,GACH1B,EAAO4B,oBAAoBF,EAE7B,EASAE,oBAAmB,SAACC,GACnB,IAAMC,EAAgB9B,EAAO+B,mBACvBC,EAAapC,EAAQiC,GAE3B7B,EAAOiC,mBAAmBH,GAAe,GACzC9B,EAAOiC,mBAAmBD,GAAY,EACvC,EASAL,mBAAkB,SAACF,GAClB,IAAMK,EAAgB9B,EAAO+B,mBACvBG,EAAoBC,MAAMC,KAAKxC,GAASyC,QAAQP,GAEtD,IAA2B,IAAvBI,EAKH,OAFwBA,EAAoBT,EAAO3B,GAAaA,CAIlE,EAOAiC,iBAAgB,WAIf,OAFsBI,MAAMC,KAAKxC,GAAS0C,KAAKtC,EAAOuC,mBAGvD,EASAN,mBAAkB,SAACO,EAAQC,GACtBD,KACwD,IAAvDA,EAAOE,UAAUC,SAASrD,EAAQC,kBACrCiD,EAAOE,UAAUE,IAAItD,EAAQC,iBAE9BiD,EAAOK,aAAa,eAAgBJ,GAEtC,EASAF,mBAAkB,SAACC,GAGlB,MAF2D,SAAxCA,EAAOM,aAAa,eAGxC,E","sources":["webpack://BellGully/../http/content/scripts/src/app/ui/hero/rotator.js"],"sourcesContent":["import { listen } from 'Util/core';\r\n\r\nconst selectors = Object.freeze({\r\n\thero: '.js-hero-rotator',\r\n\r\n\tslideList: '.js-hero-rotator__slide-list',\r\n\tslide: '.js-hero-rotator__slide',\r\n\r\n\tprev: '.js-hero-rotator__prev',\r\n\tnext: '.js-hero-rotator__next',\r\n});\r\n\r\nconst classes = Object.freeze({\r\n\tallowAnimations: 'allow-animations',\r\n});\r\n\r\n/**\r\n * The duration for which each slide will be displayed,\r\n * if the user doesn't interact with the rotator\r\n *\r\n * @type {number}\r\n */\r\nconst autorotationDelay = 5000; // ms\r\n\r\n/** @type {null | number} */\r\nlet autorotationTimeout = null;\r\n\r\n// Assumptions:\r\n// Only one hero rotator/slidelist on the page\r\n// Number of slides does not change\r\n\r\n/** @type {HTMLElement} */\r\nconst $slideList = document.querySelector(selectors.slideList);\r\n\r\n/** @type {NodeListOf} */\r\nconst $slides = $slideList.querySelectorAll(selectors.slide);\r\n\r\nconst numSlides = $slides.length;\r\n\r\nconst module = {\r\n\t/**\r\n\t * init - Initialise this module\r\n\t *\r\n\t * @return {void}\r\n\t */\r\n\tinit() {\r\n\t\tmodule._initEvents();\r\n\r\n\t\tmodule._startAutorotation();\r\n\t},\r\n\r\n\t/**\r\n\t * _initEvents - Initialise all DOM events for this module\r\n\t *\r\n\t * @return {void}\r\n\t */\r\n\t_initEvents() {\r\n\t\tlisten(selectors.prev, 'click', module._prevEvent);\r\n\t\tlisten(selectors.next, 'click', module._nextEvent);\r\n\r\n\t\t$slideList.addEventListener('mouseover', module._pauseAutorotation);\r\n\t\t$slideList.addEventListener('focus', module._pauseAutorotation);\r\n\r\n\t\t$slideList.addEventListener('mouseout', module._startAutorotation);\r\n\t\t$slideList.addEventListener('focusout', module._startAutorotation, );\r\n\t},\r\n\r\n\t/**\r\n\t * _prevEvent - Function bound to \"Previous\" button click\r\n\t *\r\n\t * @param {Event} e\r\n\t *\r\n\t * @return {void}\r\n\t */\r\n\t_prevEvent(e) {\r\n\t\te?.preventDefault();\r\n\t\tmodule._selectSlideByIncr(-1);\r\n\t},\r\n\r\n\t/**\r\n\t * _nextEvent - Function bound to \"Next\" button click\r\n\t *\r\n\t * @param {Event} e\r\n\t *\r\n\t * @return {void}\r\n\t */\r\n\t_nextEvent(e) {\r\n\t\te?.preventDefault();\r\n\t\tmodule._selectSlideByIncr(+1);\r\n\t},\r\n\r\n\t/**\r\n\t * _startAutorotation - Begin the autorotation timeout if the slide list\r\n\t * doesn't currently have keyboard focus or the mouse cursor over it.\r\n\t *\r\n\t * @param {MouseEvent | FocusEvent} [event] - An event from a mouseout or blur\r\n\t *\r\n\t * @return {void}\r\n\t */\r\n\t_startAutorotation(event) {\r\n\t\tvar shouldStart;\r\n\t\tvar hasHover;\r\n\t\tvar $focusEl;\r\n\t\tvar hasFocus;\r\n\r\n\t\tif (autorotationTimeout) {\r\n\t\t\t// If autorotation is already running, do nothing\r\n\t\t\treturn;\r\n\t\t} else {\r\n\t\t\thasHover = $slideList.matches(':hover');\r\n\r\n\t\t\tif (event instanceof FocusEvent) {\r\n\t\t\t\t$focusEl = event.relatedTarget;\r\n\t\t\t} else {\r\n\t\t\t\t$focusEl = document.activeElement;\r\n\t\t\t}\r\n\t\t\thasFocus = !!($focusEl && $focusEl.closest(selectors.slideList));\r\n\r\n\t\t\tshouldStart = !(hasHover || hasFocus);\r\n\r\n\t\t\tif (shouldStart) {\r\n\t\t\t\tautorotationTimeout = window.setTimeout(module._autorotate, autorotationDelay);\r\n\t\t\t}\r\n\t\t}\r\n\t},\r\n\r\n\t/**\r\n\t * _pauseAutorotation - Clear the autorotation timeout\r\n\t *\r\n\t * @return {void}\r\n\t */\r\n\t_pauseAutorotation() {\r\n\t\tif (autorotationTimeout) {\r\n\t\t\twindow.clearTimeout(autorotationTimeout);\r\n\t\t\tautorotationTimeout = null;\r\n\t\t}\r\n\t},\r\n\r\n\t/**\r\n\t * _autorotate - Move to the next slide, then queue another autorotation\r\n\t *\r\n\t * @return {void}\r\n\t */\r\n\t_autorotate() {\r\n\t\tmodule._selectSlideByIncr(+1);\r\n\r\n\t\tautorotationTimeout = window.setTimeout(module._autorotate, autorotationDelay);\r\n\t},\r\n\r\n\t/**\r\n\t * _selectSlideByIncr - Select a new slide based on an increment\r\n\t *\r\n\t * @param {number} incr - A positive or negative integer saying how many slides to move from the current slide\r\n\t *\r\n\t * @return {void}\r\n\t */\r\n\t_selectSlideByIncr(incr) {\r\n\t\tconst nextSlideIndex = module._getNextSlideIndex(incr);\r\n\r\n\t\tif (nextSlideIndex !== -1) {\r\n\t\t\tmodule._selectSlideByIndex(nextSlideIndex);\r\n\t\t}\r\n\t},\r\n\r\n\t/**\r\n\t * _selectSlideByIndex - Select a new slide based on a given index\r\n\t *\r\n\t * @param {index} index - The index of the slide to be selected\r\n\t *\r\n\t * @return {void}\r\n\t */\r\n\t_selectSlideByIndex(index) {\r\n\t\tconst $currentSlide = module._getCurrentSlide();\r\n\t\tconst $nextSlide = $slides[index];\r\n\r\n\t\tmodule._setSlideIsCurrent($currentSlide, false);\r\n\t\tmodule._setSlideIsCurrent($nextSlide, true);\r\n\t},\r\n\r\n\t/**\r\n\t * _getNextSlideIndex - Get the index of the next slide, based on an increment\r\n\t *\r\n\t * @param {number} incr - A positive or negative integer saying how many slides to move from the current slide\r\n\t *\r\n\t * @return {number | undefined}\r\n\t */\r\n\t_getNextSlideIndex(incr) {\r\n\t\tconst $currentSlide = module._getCurrentSlide();\r\n\t\tconst currentSlideIndex = Array.from($slides).indexOf($currentSlide);\r\n\r\n\t\tif (currentSlideIndex === -1) {\r\n\t\t\t// Something went wrong, abandon the attempt\r\n\t\t} else {\r\n\t\t\tconst nextSlideIndex = (currentSlideIndex + incr + numSlides) % numSlides;\r\n\r\n\t\t\treturn nextSlideIndex;\r\n\t\t}\r\n\t},\r\n\r\n\t/**\r\n\t * _getCurrentSlide - Get the currently selected slide\r\n\t *\r\n\t * @return {HTMLElement | undefined} - The currently selected slide, if any\r\n\t */\r\n\t_getCurrentSlide() {\r\n\t\t// If there are somehow multiple selected slides, only get the first one\r\n\t\tconst $currentSlide = Array.from($slides).find(module._getSlideIsCurrent);\r\n\r\n\t\treturn $currentSlide;\r\n\t},\r\n\r\n\t/**\r\n\t * _setSlideIsCurrent - Set a given slide as either current or not current\r\n\t *\r\n\t * @param {HTMLElement} $slide - The slide to affect\r\n\t *\r\n\t * @param {boolean} state - Whether or not the slide should be marked as current\r\n\t */\r\n\t_setSlideIsCurrent($slide, state) {\r\n\t\tif ($slide) {\r\n\t\t\tif ($slide.classList.contains(classes.allowAnimations) === false) {\r\n\t\t\t\t$slide.classList.add(classes.allowAnimations);\r\n\t\t\t}\r\n\t\t\t$slide.setAttribute('aria-current', state);\r\n\t\t}\r\n\t},\r\n\r\n\t/**\r\n\t * _getSlideIsCurrent - Check whether a given slide is selected\r\n\t *\r\n\t * @param {HTMLElement} $slide - The slide to check\r\n\t *\r\n\t * @return {boolean} - Whether or not the slide is selected\r\n\t */\r\n\t_getSlideIsCurrent($slide) {\r\n\t\tconst isSelected = $slide.getAttribute('aria-current') === 'true';\r\n\r\n\t\treturn isSelected;\r\n\t},\r\n};\r\n\r\nexport { module as heroRotator };\r\n"],"names":["selectors","Object","freeze","hero","slideList","slide","prev","next","classes","allowAnimations","autorotationTimeout","$slideList","document","querySelector","$slides","querySelectorAll","numSlides","length","module","init","_initEvents","_startAutorotation","listen","_prevEvent","_nextEvent","addEventListener","_pauseAutorotation","e","preventDefault","_selectSlideByIncr","event","hasHover","$focusEl","hasFocus","matches","FocusEvent","relatedTarget","activeElement","closest","window","setTimeout","_autorotate","clearTimeout","incr","nextSlideIndex","_getNextSlideIndex","_selectSlideByIndex","index","$currentSlide","_getCurrentSlide","$nextSlide","_setSlideIsCurrent","currentSlideIndex","Array","from","indexOf","find","_getSlideIsCurrent","$slide","state","classList","contains","add","setAttribute","getAttribute"],"sourceRoot":""}