/* global window */ (function (w) { 'use strict'; const document = w.document, console = w.console, run = () => { const mobileNavContainer = document.querySelector('[data-role="mobileNavContainer"]'); if (!mobileNavContainer || !w.mainNav || !w.topNav) { console.warn('Menu container/items not found'); return; } const findChildren = (parentItem, navItem) => { if (parseInt(navItem.menu_item_parent) === parentItem.ID) { if (!parentItem.children) { parentItem.children = []; } parentItem.children.push(navItem); } }, organizeMenuItems = (menuItems) => { let navItems = {}; navItems.l2 = []; menuItems .forEach( (item) => { if (parseInt(item.menu_item_parent) === 0) { navItems.l2.push(item); } } ) ; navItems .l2 .forEach( (l2Item) => { menuItems .forEach(( item) => { findChildren(l2Item, item); } ) ; if (!l2Item.children) { return; } l2Item .children .forEach( (child) => { menuItems .forEach( (item) => { findChildren(child, item); } ) ; if (child.children) { child.children.forEach( (child2) => { menuItems.forEach( (item) => { findChildren(child2, item); } ); } ); } } ) ; } ); return navItems; }, mainNavItems = organizeMenuItems(w.mainNav), topNavItems = organizeMenuItems(w.topNav), buildMobileNav = () => { //create dialog let dialog = document.createElement('dialog'); dialog.classList.add('mobile-nav'); dialog.setAttribute('data-role', 'mobileNav'); dialog.open = false; //remove active classes function const removeActiveClasses = (breakAfterFirstIteration = true) => { //MUST be in descending order because loop will break after its first successful iteration const activeMenuItemClasses = ['.l4-menu-item.active', '.l3-menu-item.active', '.l2-container.active']; for (let i = 0; i < activeMenuItemClasses.length; i++) { let activeClass = activeMenuItemClasses[i]; if (dialog.querySelectorAll(activeClass) && dialog.querySelectorAll(activeClass).length > 0) { dialog.querySelectorAll(activeClass).forEach((activeItem) => { activeItem.classList.remove('active'); }); if (breakAfterFirstIteration) { break; } } } }; //create close button let closeBtn = document.createElement('button'); closeBtn.classList.add('close-button'); closeBtn.innerHTML = ``; closeBtn.addEventListener('click', () => { dialog.close(); removeActiveClasses(false); }); //append close button dialog.appendChild(closeBtn); //create back button const backButton = document.createElement('button'); backButton.classList.add('back-button'); backButton.innerHTML = ``; backButton.addEventListener('click', () => { removeActiveClasses(); }); //append back button dialog.appendChild(backButton); //expand button function const createExpandButton = (container, className) => { const expandButton = document.createElement('button'); expandButton.classList.add(className); expandButton.setAttribute('data-role', 'expandButton'); expandButton.innerHTML = ``; expandButton.addEventListener('click', () => { container.classList.add('active'); }); container.appendChild(expandButton); }; const createLink = (item, classNames, topLevelBool, parentDiv = null, level, childrenDiv = null) => { const container = document.createElement('div'); const link = document.createElement('a'); classNames.forEach((className) => { container.classList.add(className); }); link.classList.add('expand-link'); link.href = item.url; link.innerHTML = item.title; container.appendChild(link); //Run the function again one level deeper if there are children if (item.children) { level = parseInt(level); level++; createExpandButton(container, 'expand-arrow'); const childrenContainer = document.createElement('div'); childrenContainer.classList.add('mobile-menu-children', 'l' + level + '-container'); item.children.forEach((child) => { createLink(child, ['l' + level + '-menu-item', 'mobile-menu-item'], false, container, level, childrenContainer); }); } if (topLevelBool) { dialog.appendChild(container); } else if (childrenDiv) { childrenDiv.appendChild(container); parentDiv.appendChild(childrenDiv); } else { //TODO: add error handling console.warn('something went wrong'); } }; //Main Nav mainNavItems.l2.forEach((l2) => { (createLink(l2, ['l2-container', 'mobile-menu-item'], true, null, 2, null)); }); //Top Nav mobileNavContainer.appendChild(dialog); const mobileTopNavContainer = document.createElement('div'); mobileTopNavContainer.classList.add('mobile-top-nav-container'); topNavItems.l2.forEach((topNavL2) => { const topNavl2Container = document.createElement('div'); const topNavl2Link = document.createElement('a'); topNavl2Container.classList.add('l2-container', 'mobile-menu-item', 'top-nav-menu-item'); topNavl2Link.classList.add('l2-link'); topNavl2Link.href = topNavL2.url; topNavl2Link.innerHTML = topNavL2.title; topNavl2Container.appendChild(topNavl2Link); mobileTopNavContainer.appendChild(topNavl2Container); }); dialog.appendChild(mobileTopNavContainer); }, //Start:open mobile nav button mobileNavButton = document.querySelector('[data-role="mobileNavButton"]') ; if (!mobileNavButton) { console.warn('Mobile Nav Button not found'); return; } // build the nav upon click mobileNavButton.addEventListener('click', () => { buildMobileNav(); const dialog = document.querySelector('[data-role="mobileNav"]'); if (!dialog) { console.warn('Mobile Nav Dialog not found'); return; } dialog.showModal(); }); w .addEventListener( 'resize', () => { if (w.screen.width < 720) { return; } const dialog = document.querySelector('[data-role="mobileNav"]'); if (dialog && dialog.open) { dialog.close(); } } ) ; }, init = () => { if (['complete', 'interactive'].includes(document.readyState)) { run(); } else { document.addEventListener('DOMContentLoaded', run); } }; init(); })(window); ; /*! This file is auto-generated */ (()=>{"use strict";var e={d:(t,d)=>{for(var o in d)e.o(d,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:d[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function d(e){"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",e):e())}e.d(t,{default:()=>d}),(window.wp=window.wp||{}).domReady=t.default})();; /*! This file is auto-generated */ (()=>{var t={507:(t,e,r)=>{"use strict";r.d(e,{A:()=>A});var n=function(t){return"string"!=typeof t||""===t?(console.error("The namespace must be a non-empty string."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(t)||(console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."),!1)};var i=function(t){return"string"!=typeof t||""===t?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(t)?(console.error("The hook name cannot begin with `__`."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(t)||(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)};var o=function(t,e){return function(r,o,s,c=10){const l=t[e];if(!i(r))return;if(!n(o))return;if("function"!=typeof s)return void console.error("The hook callback must be a function.");if("number"!=typeof c)return void console.error("If specified, the hook priority must be a number.");const a={callback:s,priority:c,namespace:o};if(l[r]){const t=l[r].handlers;let e;for(e=t.length;e>0&&!(c>=t[e-1].priority);e--);e===t.length?t[e]=a:t.splice(e,0,a),l.__current.forEach((t=>{t.name===r&&t.currentIndex>=e&&t.currentIndex++}))}else l[r]={handlers:[a],runs:0};"hookAdded"!==r&&t.doAction("hookAdded",r,o,s,c)}};var s=function(t,e,r=!1){return function(o,s){const c=t[e];if(!i(o))return;if(!r&&!n(s))return;if(!c[o])return 0;let l=0;if(r)l=c[o].handlers.length,c[o]={runs:c[o].runs,handlers:[]};else{const t=c[o].handlers;for(let e=t.length-1;e>=0;e--)t[e].namespace===s&&(t.splice(e,1),l++,c.__current.forEach((t=>{t.name===o&&t.currentIndex>=e&&t.currentIndex--})))}return"hookRemoved"!==o&&t.doAction("hookRemoved",o,s),l}};var c=function(t,e){return function(r,n){const i=t[e];return void 0!==n?r in i&&i[r].handlers.some((t=>t.namespace===n)):r in i}};var l=function(t,e,r,n){return function(i,...o){const s=t[e];s[i]||(s[i]={handlers:[],runs:0}),s[i].runs++;const c=s[i].handlers;if(!c||!c.length)return r?o[0]:void 0;const l={name:i,currentIndex:0};return(n?async function(){try{s.__current.add(l);let t=r?o[0]:void 0;for(;l.currentIndex0:Array.from(n.__current).some((t=>t.name===r))}};var u=function(t,e){return function(r){const n=t[e];if(i(r))return n[r]&&n[r].runs?n[r].runs:0}};class h{actions;filters;addAction;addFilter;removeAction;removeFilter;hasAction;hasFilter;removeAllActions;removeAllFilters;doAction;doActionAsync;applyFilters;applyFiltersAsync;currentAction;currentFilter;doingAction;doingFilter;didAction;didFilter;constructor(){this.actions=Object.create(null),this.actions.__current=new Set,this.filters=Object.create(null),this.filters.__current=new Set,this.addAction=o(this,"actions"),this.addFilter=o(this,"filters"),this.removeAction=s(this,"actions"),this.removeFilter=s(this,"filters"),this.hasAction=c(this,"actions"),this.hasFilter=c(this,"filters"),this.removeAllActions=s(this,"actions",!0),this.removeAllFilters=s(this,"filters",!0),this.doAction=l(this,"actions",!1,!1),this.doActionAsync=l(this,"actions",!1,!0),this.applyFilters=l(this,"filters",!0,!1),this.applyFiltersAsync=l(this,"filters",!0,!0),this.currentAction=a(this,"actions"),this.currentFilter=a(this,"filters"),this.doingAction=d(this,"actions"),this.doingFilter=d(this,"filters"),this.didAction=u(this,"actions"),this.didFilter=u(this,"filters")}}var A=function(){return new h}},8770:()=>{}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,r),o.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};(()=>{"use strict";r.r(n),r.d(n,{actions:()=>x,addAction:()=>s,addFilter:()=>c,applyFilters:()=>m,applyFiltersAsync:()=>v,createHooks:()=>t.A,currentAction:()=>y,currentFilter:()=>F,defaultHooks:()=>o,didAction:()=>b,didFilter:()=>k,doAction:()=>f,doActionAsync:()=>p,doingAction:()=>_,doingFilter:()=>g,filters:()=>w,hasAction:()=>d,hasFilter:()=>u,removeAction:()=>l,removeAllActions:()=>h,removeAllFilters:()=>A,removeFilter:()=>a});var t=r(507),e=r(8770),i={};for(const t in e)["default","actions","addAction","addFilter","applyFilters","applyFiltersAsync","createHooks","currentAction","currentFilter","defaultHooks","didAction","didFilter","doAction","doActionAsync","doingAction","doingFilter","filters","hasAction","hasFilter","removeAction","removeAllActions","removeAllFilters","removeFilter"].indexOf(t)<0&&(i[t]=()=>e[t]);r.d(n,i);const o=(0,t.A)(),{addAction:s,addFilter:c,removeAction:l,removeFilter:a,hasAction:d,hasFilter:u,removeAllActions:h,removeAllFilters:A,doAction:f,doActionAsync:p,applyFilters:m,applyFiltersAsync:v,currentAction:y,currentFilter:F,doingAction:_,doingFilter:g,didAction:b,didFilter:k,actions:x,filters:w}=o})(),(window.wp=window.wp||{}).hooks=n})();;