document.addEventListener("alpine:init", () => { Alpine.store('viewport', { mobileMenu: false }) Alpine.store('fitlerList', { results: [], }) Alpine.data("search", (locations) => ({ locations: Object.values(locations), locationsSelected: "All Regions", locationsOpen: false, searchQuery: "", updateSearchQuery(searchQuery, locationsSelected) { let items = []; document.querySelectorAll('.list-card').forEach(el => { let checkSearch = searchQuery === "" || el.innerText.toLowerCase().includes(searchQuery.toLowerCase()); let checkLocations = locationsSelected === "All Regions" || el.dataset.locations.toString().toLowerCase().includes(locationsSelected.toLowerCase()); if (checkSearch && checkLocations) { items.push(el); el.style.display = 'flex'; } else { el.style.display = 'none'; } }) Alpine.store('fitlerList').results = items; document.querySelectorAll('.wp-block-nlsn-accordion-tab').forEach(el => { let childCards = [].slice.call(el.querySelectorAll('.list-card')); let activeChildCards = childCards.filter(el => el.style.display === "flex"); if (activeChildCards.length > 0) { el.style.display = 'block' } else { el.style.display = 'none' } }) }, init() { this.locations.unshift({ name: "All Regions", slug: "all-regions", term_id: false }); this.updateSearchQuery(this.searchQuery, this.locationsSelected); this.$watch('searchQuery', (searchQuery) => { this.updateSearchQuery(searchQuery, this.locationsSelected); this.searchQuery = searchQuery; }) this.$watch('locationsSelected', (locationsSelected) => { this.updateSearchQuery(this.searchQuery, locationsSelected); this.locationsSelected = locationsSelected; }) } })); Alpine.data("accordion", (initialOpenState = false) => ({ isOpen: initialOpenState, init() { this.isOpen = ( encodeURIComponent(window.location.hash) === "%23" + this.$el.id) ? true : false; } })); /** * used by all nlsn popups & modals * parameters : * initialOpenState = false, initialGatedState = false, initialBackdropState = true, triggerType = 'button', timeoutSeconds = 5 */ Alpine.data("modal", (...modalArgs) => ({ isOpen: modalArgs[0] ?? false, isGated: modalArgs[1] ?? false, isDisabled: false, hasBackdrop: modalArgs[2] ?? true, timerID: null, triggerType : modalArgs[3] ?? 'button', // default trigger type is onClick of button timeoutSeconds : modalArgs[4] ?? 5, // The pop up will close after '5 seconds'(default). buttonPosition: 'N/A', init() { this.isOpen = ( encodeURIComponent(window.location.hash) === "%23" + this.$el.id) ? true : this.isOpen; if (this.isOpen) { this.open(); } const pop_up_cookies = document.cookie.split('; ').filter((cookie_string) => cookie_string.startsWith('nlsn-pop-up')); let form_ids = pop_up_cookies?.map((cookie) => cookie.split('=')[0]?.split('|')[1]); let modal_form_id = this.$el.querySelector('.nf-form-cont')?.getAttribute('id')?.split('-')[2]; let hasFormCookie = form_ids.some(form_id => form_id === (modal_form_id)); if (hasFormCookie) { this.isGated = false; if (this.triggerType !== 'button') { this.isDisabled = true; // this should be enabled only for scroll and onload } let form_div = this.$el.querySelector('.nf-form-cont'); if (form_div) { let thankYouMessage = nfForms?.find(nfForm => nfForm.id === modal_form_id)?.fields?.find(field => field.key.includes('message'))?.value; let div_thank_you_msg = document.createElement('div'); div_thank_you_msg.innerHTML = DOMPurify.sanitize(thankYouMessage ?? 'Thank you'); //fallback thank you message if custom thank you message/NF thank you message is empty form_div.parentNode.insertBefore(div_thank_you_msg, form_div); form_div.classList.add('hidden'); } } }, open(eventDetails=null) { if (this.isDisabled) { this.$el.classList.toggle("animate-shake"); return; } this.isOpen = true; //pop up open datalayer let formID = this.$el.querySelector('.nf-form-cont')?.getAttribute('id')?.split('-')[2]; let buttonPosition; // for datalayer trigger if (eventDetails === null || (Object.keys(eventDetails).length === 0)) { buttonPosition = this.$el.querySelector('[btnPosition]')?.getAttribute('btnPosition'); } else{ buttonPosition = eventDetails.buttonPosition; } this.buttonPosition = buttonPosition; popup_datalayer(formID, 'open', buttonPosition);//Data layer event popup_open if (this.hasBackdrop) { document.body.classList.add('overflow-hidden'); window.dispatchEvent(new CustomEvent('backdrop', { detail: { open: true } })); } //keyboard accessibility let firstFocusableElement = this.$el.querySelector('button'); let lastFocusableElement = this.$el.querySelector('input[type="submit"]'); //focus the first element when the pop up opens setTimeout(() => { firstFocusableElement.focus(); },500); //A nominal delay for stability //accessibility for screen reader let wp_blocks = document.querySelector('.wp-site-blocks'); if(wp_blocks) { wp_blocks.setAttribute('aria-hidden',true); } if(!lastFocusableElement && (firstFocusableElement.getAttribute('listener-present') === null)){ firstFocusableElement.setAttribute('listener-present','true') firstFocusableElement.addEventListener('keydown', (e)=>{ let tabPressed = (e.key == "Tab" || e.key == 9); if (tabPressed) { e.preventDefault(); } }); } if(lastFocusableElement) { let lastElementID = lastFocusableElement.getAttribute('id'); let focusableElements = this.$el.querySelectorAll('input:not([type="hidden"]),textarea,a'); let elPrevSubmitButton = focusableElements[focusableElements.length-3]; firstFocusableElement.addEventListener('keydown', (e)=>{ if ( firstFocusableElement.getAttribute('listener-added') === true) return; firstFocusableElement.setAttribute('listener-added',true); let submitButton = document.getElementById(lastElementID); let isDisabled = submitButton.getAttribute('disabled'); let tabPressed = (e.key == "Tab" || e.key == 9); let shiftPressed = (e.shiftKey); if (tabPressed && shiftPressed) { e.preventDefault(); (isDisabled === 'true') ? elPrevSubmitButton.focus() : submitButton.focus(); } }) lastFocusableElement.addEventListener('keydown', (e)=>{ if ( e.target.getAttribute('listener-added') === true) return; e.target.setAttribute('listener-added',true); let tabPressed = (e.key == "Tab" || e.key == 9); let shiftPressed = (e.shiftKey); if (tabPressed && !shiftPressed) { e.preventDefault(); firstFocusableElement.focus(); } }) elPrevSubmitButton.addEventListener('keydown', (e) => { if ( elPrevSubmitButton.getAttribute('listener-added') === true) return; elPrevSubmitButton.setAttribute('listener-added',true); let submitButton = document.getElementById(lastElementID); let isDisabled = submitButton.getAttribute('disabled'); let tabPressed = (e.key == "Tab" || e.key == 9); let shiftPressed = (e.shiftKey); if (tabPressed && !shiftPressed) { e.preventDefault(); if (isDisabled === 'true') { firstFocusableElement.focus() } else { submitButton.focus(); document.getElementById(lastElementID).addEventListener('keydown',(e)=>{ if ( e.target.getAttribute('listener-added') === true) return; e.target.setAttribute('listener-added',true); let tabPressed = (e.key == "Tab" || e.key == 9); let shiftPressed = (e.shiftKey); if (tabPressed && !shiftPressed) { e.preventDefault(); firstFocusableElement.focus(); } }) } } }) //add checks for submitButton and elPrevSubmitButton } }, disableGate() { let popUpContainer = this.$el.firstElementChild.firstElementChild; if (popUpContainer !== null) { let timerBar = document.createElement('div'); timerBar.classList.add('timer-bar','h-2','bg-blurple-300','relative','w-[96%]','left-[2%]','rounded-large'); timerBar.setAttribute('style', '--duration:'+this.timeoutSeconds); popUpContainer?.prepend(timerBar); } this.isGated = false; if (String(this.timeoutSeconds) === '0') { this.close(); } else { this.timerID = setTimeout(() => { this.close(); let timerBar = this.$el.querySelector('.timer-bar') timerBar && timerBar.remove(); }, parseInt(this.timeoutSeconds) * 1000); } }, close(buttonTriggered = false) { if (this.isGated) { this.$root.classList.add("animate-shake"); setInterval(() => { this.$root.classList.remove("animate-shake"); }, 800) return; } if (this.hasBackdrop) { window.dispatchEvent(new CustomEvent('backdrop', { detail: { open: false } })); } this.isOpen = false; //pop up exit datalayer if (buttonTriggered) { let formID = this.$el.parentNode.querySelector('.nf-form-cont')?.getAttribute('id')?.split('-')[2]; // data layer event popup_exit // buttonPosition is set, when the popup opens. popup_datalayer(formID, 'exit' , this.buttonPosition); } document.body.classList.remove('overflow-hidden'); if (this.timerID) { clearTimeout(this.timerID); // clear timeout for gated content if pop-up is closed manually let timerBar = this.$el.parentNode.querySelector('.timer-bar') timerBar && timerBar.remove(); } //accessibility for screen reader let wp_blocks = document.querySelector('.wp-site-blocks'); if(wp_blocks) { wp_blocks.setAttribute('aria-hidden',false); } } })); Alpine.data("menubar", () => ({ activeNavDropdown: null, trianglePosition: false, triangleColor: false, openSubmenu(navLink) { this.activeNavDropdown = navLink; this.$el.setAttribute('aria-expanded', true); this.trianglePosition = (this.$el.getBoundingClientRect().left + this.$el.getBoundingClientRect().right) / 2; this.triangleColor = (this.$el.dataset.color); const next = this.$el.parentElement.querySelector('.nav-link-dropdown-container') next.querySelector('a').focus() }, closeSubmenu() { this.$el.setAttribute('aria-expanded', false); this.activeNavDropdown = null; }, focusNextItem() { const allMenuItems = [...document.querySelectorAll('.wp-block-nlsn-nav-link > .top-level-nav')]; const currentIndex = allMenuItems.indexOf(document.activeElement); const nextIndex = (currentIndex + 1) % allMenuItems.length; allMenuItems[nextIndex].focus(); }, focusPrevItem() { const allMenuItems = [...document.querySelectorAll('.wp-block-nlsn-nav-link > .top-level-nav')]; const currentIndex = allMenuItems.indexOf(document.activeElement); const prevIndex = (currentIndex - 1 + allMenuItems.length) % allMenuItems.length; allMenuItems[prevIndex].style.display = "inline"; allMenuItems[prevIndex].focus(); }, handleKeyDownSubItem(event) { switch (event.key) { case "ArrowDown": event.preventDefault(); this.focusDownSubItem(); break; case "ArrowUp": event.preventDefault(); this.focusUpSubItem(); break; case "ArrowLeft": event.preventDefault(); this.focusLeftSubItem(); break; case "ArrowRight": event.preventDefault(); this.focusRightSubItem(); break; case "Escape": event.preventDefault(); this.closeSubmenu(); break; default: return null; } }, focusDownSubItem() { const allMenuItems = [...document.querySelectorAll('.nav-link-dropdown-container a')]; const currentIndex = allMenuItems.indexOf(document.activeElement); const nextIndex = (currentIndex + 1) % allMenuItems.length; allMenuItems[nextIndex].focus(); }, focusUpSubItem() { const allMenuItems = [...document.querySelectorAll('.nav-link-dropdown-container a')]; const currentIndex = allMenuItems.indexOf(document.activeElement); const prevIndex = (currentIndex - 1 + allMenuItems.length) % allMenuItems.length; allMenuItems[prevIndex].focus(); }, focusRightSubItem() { const allMenuItems = [...document.querySelectorAll('.wp-block-nlsn-nav-link > .top-level-nav')]; const nextIndex = (this.activeNavDropdown.slice(-1) * 2) % allMenuItems.length; allMenuItems[nextIndex].focus(); }, focusLeftSubItem() { const allMenuItems = [...document.querySelectorAll('.wp-block-nlsn-nav-link > .top-level-nav')]; const prevIndex = (this.activeNavDropdown.slice(-1) * 2 - 1 + allMenuItems.length) % allMenuItems.length; allMenuItems[prevIndex].focus(); }, })) Alpine.data("carousel", () => ({ slideCount: 0, activeIndex: 0, childWidth: 0, gapWidth: 24, init() { this.slideCount = this.$refs.carouselInner.childElementCount; this.childWidth = this.$refs.carouselInner.getElementsByClassName('flex-col')[0].offsetWidth; }, prev(carouselInner) { if (this.activeIndex > 0) { carouselInner.scrollLeft = (this.childWidth + this.gapWidth) * (this.activeIndex - 1); this.activeIndex--; } }, next(carouselInner) { if (this.activeIndex < this.slideCount - 1) { carouselInner.scrollLeft = (this.childWidth + this.gapWidth) * (this.activeIndex + 1); this.activeIndex++; } }, updateIndex(target) { this.activeIndex = Math.round(target.scrollLeft / this.childWidth); }, })); Alpine.data("listCollapse", () => ({ open: false, othersOpen: false, buttonElement: null, init() { this.buttonElement = this.$el; const label = this.buttonElement.querySelector('button').innerText this.buttonElement.setAttribute('aria-label',`open ${label} menu`); window.addEventListener('list-collapse-close', () => { this.buttonElement.classList.remove('opacity-60'); }); window.addEventListener('list-collapse-open', () => { this.open = false; this.buttonElement.classList.add('opacity-60'); }); }, handleKeyDown(event) { switch (event.key) { case "ArrowDown": case "Enter": case "Space": event.preventDefault(); this.toggleMenu(); break; default: return null; } }, toggleMenu() { if(!this.open){ this.$dispatch('list-collapse-open'); } else { this.$dispatch('list-collapse-close'); } this.open = ! this.open; } })); function findParent(startingElement, classSearch) { let currentElement = startingElement.parentElement; while (currentElement) { if (currentElement.classList.contains(classSearch)) { return currentElement; } currentElement = currentElement.parentElement; } return null; } }); ; /** * what-input - A global utility for tracking the current input method (mouse, keyboard or touch). * @version v5.2.12 * @link https://github.com/ten1seven/what-input * @license MIT */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("whatInput",[],t):"object"==typeof exports?exports.whatInput=t():e.whatInput=t()}(this,function(){return i={},n.m=o=[function(e,t){"use strict";e.exports=function(){if("undefined"==typeof document||"undefined"==typeof window)return{ask:function(){return"initial"},element:function(){return null},ignoreKeys:function(){},specificKeys:function(){},registerOnChange:function(){},unRegisterOnChange:function(){}};var t=document.documentElement,n=null,u="initial",s=u,o=Date.now(),i=!1,d=["button","input","select","textarea"],r=[],c=[16,17,18,91,93],w=[],p={keydown:"keyboard",keyup:"keyboard",mousedown:"mouse",mousemove:"mouse",MSPointerDown:"pointer",MSPointerMove:"pointer",pointerdown:"pointer",pointermove:"pointer",touchstart:"touch",touchend:"touch"},a=!1,f={x:null,y:null},l={2:"touch",3:"touch",4:"mouse"},m=!1;try{var e=Object.defineProperty({},"passive",{get:function(){m=!0}});window.addEventListener("test",null,e)}catch(e){}var h=function(){var e=!m||{passive:!0,capture:!0};document.addEventListener("DOMContentLoaded",v,!0),window.PointerEvent?(window.addEventListener("pointerdown",y,!0),window.addEventListener("pointermove",E,!0)):window.MSPointerEvent?(window.addEventListener("MSPointerDown",y,!0),window.addEventListener("MSPointerMove",E,!0)):(window.addEventListener("mousedown",y,!0),window.addEventListener("mousemove",E,!0),"ontouchstart"in window&&(window.addEventListener("touchstart",y,e),window.addEventListener("touchend",y,!0))),window.addEventListener(O(),E,e),window.addEventListener("keydown",y,!0),window.addEventListener("keyup",y,!0),window.addEventListener("focusin",L,!0),window.addEventListener("focusout",b,!0)},v=function(){if(i=!("false"===t.getAttribute("data-whatpersist")||"false"===document.body.getAttribute("data-whatpersist")))try{window.sessionStorage.getItem("what-input")&&(u=window.sessionStorage.getItem("what-input")),window.sessionStorage.getItem("what-intent")&&(s=window.sessionStorage.getItem("what-intent"))}catch(e){}g("input"),g("intent")},y=function(e){var t=e.which,n=p[e.type];"pointer"===n&&(n=S(e));var o=!w.length&&-1===c.indexOf(t),i=w.length&&-1!==w.indexOf(t),r="keyboard"===n&&t&&(o||i)||"mouse"===n||"touch"===n;if(M(n)&&(r=!1),r&&u!==n&&(x("input",u=n),g("input")),r&&s!==n){var a=document.activeElement;a&&a.nodeName&&(-1===d.indexOf(a.nodeName.toLowerCase())||"button"===a.nodeName.toLowerCase()&&!C(a,"form"))&&(x("intent",s=n),g("intent"))}},g=function(e){t.setAttribute("data-what"+e,"input"===e?u:s),k(e)},E=function(e){var t=p[e.type];"pointer"===t&&(t=S(e)),A(e),(!a&&!M(t)||a&&"wheel"===e.type||"mousewheel"===e.type||"DOMMouseScroll"===e.type)&&s!==t&&(x("intent",s=t),g("intent"))},L=function(e){e.target.nodeName?(n=e.target.nodeName.toLowerCase(),t.setAttribute("data-whatelement",n),e.target.classList&&e.target.classList.length&&t.setAttribute("data-whatclasses",e.target.classList.toString().replace(" ",","))):b()},b=function(){n=null,t.removeAttribute("data-whatelement"),t.removeAttribute("data-whatclasses")},x=function(e,t){if(i)try{window.sessionStorage.setItem("what-"+e,t)}catch(e){}},S=function(e){return"number"==typeof e.pointerType?l[e.pointerType]:"pen"===e.pointerType?"touch":e.pointerType},M=function(e){var t=Date.now(),n="mouse"===e&&"touch"===u&&t-o<200;return o=t,n},O=function(){return"onwheel"in document.createElement("div")?"wheel":void 0!==document.onmousewheel?"mousewheel":"DOMMouseScroll"},k=function(e){for(var t=0,n=r.length;t