1 line
2.4 KiB
JavaScript
1 line
2.4 KiB
JavaScript
|
!function(){"use strict";if("querySelector"in document&&"addEventListener"in window){var c=document.body,t=function(e,t){e.preventDefault(),e.stopPropagation();var n=(t=t||this).closest("li"),o=t.closest("nav").querySelectorAll("ul.toggled-on");if(o&&!t.closest("ul").classList.contains("toggled-on")&&!t.closest("li").classList.contains("sfHover"))for(var l=0;l<o.length;l++)o[l].classList.remove("toggled-on"),o[l].closest("li").classList.remove("sfHover");n.classList.toggle("sfHover");var r,i=n.querySelector(".dropdown-menu-toggle");"false"!==i.getAttribute("aria-expanded")&&i.getAttribute("aria-expanded")?i.setAttribute("aria-expanded","false"):i.setAttribute("aria-expanded","true"),r=n.querySelector(".sub-menu")?".sub-menu":".children",c.classList.contains("dropdown-click-menu-item")?t.parentNode.querySelector(r).classList.toggle("toggled-on"):c.classList.contains("dropdown-click-arrow")&&n.querySelector(r).classList.toggle("toggled-on")},e=document.querySelectorAll(".main-nav .menu-item-has-children > a");if(c.classList.contains("dropdown-click-menu-item"))for(var n=0;n<e.length;n++)e[n].addEventListener("click",t,!0);if(c.classList.contains("dropdown-click-arrow")){for(n=0;n<document.querySelectorAll(".main-nav .menu-item-has-children > a").length;n++)"#"==document.querySelectorAll(".main-nav .menu-item-has-children > a")[n].getAttribute("href")&&document.querySelectorAll(".main-nav .menu-item-has-children > a")[n].classList.add("menu-item-dropdown-click");for(var o=document.querySelectorAll(".main-nav .menu-item-has-children > a .dropdown-menu-toggle"),n=0;n<o.length;n++)o[n].addEventListener("click",t,!1),o[n].addEventListener("keydown",function(e){13===(e.which||e.keyCode)&&t(e,this)},!1);for(n=0;n<document.querySelectorAll(".main-nav .menu-item-has-children > a.menu-item-dropdown-click").length;n++)document.querySelectorAll(".main-nav .menu-item-has-children > a.menu-item-dropdown-click")[n].addEventListener("click",t,!1)}var l=function(){if(document.querySelector("nav ul .toggled-on")){for(var e=document.querySelectorAll("nav ul .toggled-on"),t=document.querySelectorAll("nav .dropdown-menu-toggle"),n=0;n<e.length;n++)e[n].classList.remove("toggled-on"),e[n].closest(".sfHover").classList.remove("sfHover");for(n=0;n<t.length;n++)t[n].setAttribute("aria-expanded","false")}};document.addEventListener("click",function(e){e.target.closest(".sfHover")||l()},!1),document.addEventListener("keydown",function(e){27===(e.which||e.keyCode)&&l()},!1)}}();
|