1
0
Fork 0
pyramidengarten-berlin/wp-themes/generatepress/js/dropdown-click.min.js

1 line
2.1 KiB
JavaScript

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