Skip to main content

GABCO Online

(function(){ var roots = document.querySelectorAll(".cmp-gabco-header"); for (var r = 0; r < roots.length; r++) { (function(root, index){ if (root.getAttribute("data-nav-ready") === "true") return; root.setAttribute("data-nav-ready", "true"); var nav = root.querySelector(".cmp-gabco-header__nav"); var toggle = root.querySelector('[data-action="toggle-navigation"]'); var logo = root.querySelector(".cmp-gabco-header__brand-logo"); var items = root.querySelectorAll(".cmp-gabco-header__item"); var menuButtons = root.querySelectorAll('[data-action="toggle-submenu"]'); var mobileQuery = window.matchMedia("(max-width: 1120px)"); var navId = "cmp-gabco-nav-" + index + "-" + Math.random().toString(36).slice(2, 8); nav.id = navId; toggle.setAttribute("aria-controls", navId); function closeSubmenus(focusButton) { var focused = null; for (var i = 0; i < items.length; i++) { if (items[i].classList.contains("cmp-gabco-header__item--open")) { focused = items[i].querySelector(".cmp-gabco-header__item-head"); } items[i].classList.remove("cmp-gabco-header__item--open"); items[i].querySelector(".cmp-gabco-header__item-head").setAttribute("aria-expanded", "false"); } nav.classList.remove("cmp-gabco-header__nav--submenu-open"); if (focusButton && focused) focused.focus(); } function closeNavigation(focusToggle) { closeSubmenus(false); root.classList.remove("cmp-gabco-header--open"); toggle.setAttribute("aria-expanded", "false"); toggle.setAttribute("aria-label", "Open navigation"); if (focusToggle) toggle.focus(); } toggle.addEventListener("click", function(){ var willOpen = !root.classList.contains("cmp-gabco-header--open"); if (!willOpen) { closeNavigation(false); return; } root.classList.add("cmp-gabco-header--open"); toggle.setAttribute("aria-expanded", "true"); toggle.setAttribute("aria-label", "Close navigation"); }); for (var i = 0; i < menuButtons.length; i++) { menuButtons[i].addEventListener("click", function(){ var item = this.closest(".cmp-gabco-header__item"); var willOpen = !item.classList.contains("cmp-gabco-header__item--open"); closeSubmenus(false); if (willOpen) { item.classList.add("cmp-gabco-header__item--open"); this.setAttribute("aria-expanded", "true"); if (mobileQuery.matches) { nav.classList.add("cmp-gabco-header__nav--submenu-open"); item.querySelector(".cmp-gabco-header__submenu-back").focus(); } } }); } var backButtons = root.querySelectorAll('[data-action="back-to-navigation"]'); for (var b = 0; b < backButtons.length; b++) { backButtons[b].addEventListener("click", function(){ closeSubmenus(true); }); } var destinationLinks = nav.querySelectorAll("a"); for (var a = 0; a < destinationLinks.length; a++) { destinationLinks[a].addEventListener("click", function(){ if (mobileQuery.matches) closeNavigation(false); }); } document.addEventListener("click", function(event){ if (!root.contains(event.target)) closeNavigation(false); }); root.addEventListener("keydown", function(event){ if (event.key !== "Escape") return; if (nav.classList.contains("cmp-gabco-header__nav--submenu-open")) { closeSubmenus(true); } else if (root.classList.contains("cmp-gabco-header--open")) { closeNavigation(true); } else { closeSubmenus(true); } }); function resetForViewport() { closeNavigation(false); } if (mobileQuery.addEventListener) mobileQuery.addEventListener("change", resetForViewport); else mobileQuery.addListener(resetForViewport); function checkLogo() { root.classList.toggle("cmp-gabco-header--logo-failed", !logo.complete || logo.naturalWidth < 1); } logo.addEventListener("load", checkLogo); logo.addEventListener("error", checkLogo); if (logo.complete) checkLogo(); })(roots[r], r); } })();