laipower/wp-content/themes/generatepress/assets/js/menu.min.js

1 line
5.2 KiB
JavaScript
Raw Normal View History

!function(){"use strict";if("querySelector"in document&&"addEventListener"in window){Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(e){var t=this;if(!document.documentElement.contains(this))return null;do{if(t.matches(e))return t;t=t.parentElement}while(null!==t);return null});for(var e=document.querySelectorAll(".menu-toggle"),t=document.querySelectorAll("nav .dropdown-menu-toggle"),o=document.querySelectorAll("nav ul a"),c=document.querySelector(".mobile-menu-control-wrapper"),a=document.body,u=document.documentElement,d=function(e){if(a.classList.contains("dropdown-hover"))for(var t=e.querySelectorAll("li.menu-item-has-children"),o=0;o<t.length;o++)t[o].querySelector(".dropdown-menu-toggle").removeAttribute("tabindex"),t[o].querySelector(".dropdown-menu-toggle").setAttribute("role","presentation"),t[o].querySelector(".dropdown-menu-toggle").removeAttribute("aria-expanded"),t[o].querySelector(".dropdown-menu-toggle").removeAttribute("aria-label")},i=function(e){"false"!==e.getAttribute("aria-expanded")&&e.getAttribute("aria-expanded")?(e.setAttribute("aria-expanded","false"),e.setAttribute("aria-label",generatepressMenu.openSubMenuLabel)):(e.setAttribute("aria-expanded","true"),e.setAttribute("aria-label",generatepressMenu.closeSubMenuLabel))},n=function(e,t){var o,n,r="";(r=(t=t||this).getAttribute("data-nav")?document.getElementById(t.getAttribute("data-nav")):document.getElementById(t.closest("nav").getAttribute("id")))&&(o=!1,t.closest(".mobile-menu-control-wrapper")&&(o=!0),n=r.getElementsByTagName("ul")[0],r.classList.contains("toggled")?(r.classList.remove("toggled"),u.classList.remove("mobile-menu-open"),n.setAttribute("aria-hidden","true"),t.setAttribute("aria-expanded","false"),(o||c&&r.classList.contains("main-navigation"))&&c.classList.remove("toggled"),d(n)):(r.classList.add("toggled"),u.classList.add("mobile-menu-open"),n.setAttribute("aria-hidden","false"),t.setAttribute("aria-expanded","true"),o?(c.classList.add("toggled"),c.querySelector(".search-item")&&c.querySelector(".search-item").classList.contains("active")&&c.querySelector(".search-item").click()):c&&r.classList.contains("main-navigation")&&c.classList.add("toggled"),function(e){if(a.classList.contains("dropdown-hover"))for(var t=e.querySelectorAll("li.menu-item-has-children"),o=0;o<t.length;o++)t[o].querySelector(".dropdown-menu-toggle").setAttribute("tabindex","0"),t[o].querySelector(".dropdown-menu-toggle").setAttribute("role","button"),t[o].querySelector(".dropdown-menu-toggle").setAttribute("aria-expanded","false"),t[o].querySelector(".dropdown-menu-toggle").setAttribute("aria-label",generatepressMenu.openSubMenuLabel)}(n)))},r=0;r<e.length;r++)e[r].addEventListener("click",n,!1);for(var s=function(e,t){var o;if(((t=t||this).closest("nav").classList.contains("toggled")||u.classList.contains("slide-opened"))&&!a.classList.contains("dropdown-click")){e.preventDefault();var n,r=t.closest("li");if(i(r.querySelector(".dropdown-menu-toggle")),n=r.querySelector(".sub-menu")?r.querySelector(".sub-menu"):r.querySelector(".children"),generatepressMenu.toggleOpenedSubMenus)for(var s=(o=r,Array.prototype.filter.call(o.parentNode.children,function(e){return e!==o})),l=0;l<s.length;l++)s[l].classList.contains("sfHover")&&(s[l].classList.remove("sfHover"),s[l].querySelector(".toggled-on").classList.remove("toggled-on"),i(s[l].querySelector(".dropdown-menu-toggle")));r.classList.toggle("sfHover"),n.classList.toggle("toggled-on")}e.stopPropagation()},r=0;r<t.length;r++)t[r].addEventListener("click",s,!1),t[r].addEventListener("keypress",function(e){13===(e.which||e.keyCode)&&s(e,this)},!1);var l=function(){for(var e=document.querySelectorAll(".toggled, .has-active-search"),t=0;t<e.length;t++){var o=e[t].querySelector(".menu-toggle");if(c&&!o.closest("nav").classList.contains("mobile-menu-control-wrapper")&&(o=c.querySelector(".menu-toggle")),o&&null===o.offsetParent){if(e[t].classList.contains("toggled")){var