laipower/wp-content/themes/generatepress/js/navigation-search.min.js
2020-04-07 13:03:04 +00:00

2 lines
2.2 KiB
JavaScript

!function(){"use strict";if("querySelector"in document&&"addEventListener"in window){var s=function(e,t){if(e.preventDefault(),!t)t=this;var a=t.closest("nav"),s=t.querySelector("a");t.getAttribute("data-nav")&&(a=document.querySelector(this.getAttribute("data-nav")));var c=a.querySelector(".navigation-search"),i=document.querySelectorAll('a[href], area[href], input:not([disabled]):not(.navigation-search), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]');if(c.classList.contains("nav-search-active")){t.classList.remove("close-search"),t.classList.remove("active"),document.activeElement.blur(),t.classList.remove("sfHover"),c.classList.remove("nav-search-active"),s.setAttribute("aria-label",generatepressNavSearch.open),t.style.float="";for(var r=0;r<i.length;r++)i[r].closest(".navigation-search")||i[r].closest(".search-item")||i[r].removeAttribute("tabindex")}else{t.classList.add("active"),c.classList.add("nav-search-active"),s.setAttribute("aria-label",generatepressNavSearch.close),c.querySelector(".search-field").focus();for(r=0;r<i.length;r++)i[r].closest(".navigation-search")||i[r].closest(".search-item")||i[r].setAttribute("tabindex","-1");setTimeout(function(){t.classList.add("sfHover")},50),document.body.classList.contains("nav-aligned-center")?(t.style.opacity=0,setTimeout(function(){t.classList.add("close-search"),t.style.opacity=1,document.body.classList.contains("rtl")?t.style.float="left":t.style.float="right"},250)):t.classList.add("close-search")}};if(document.body.classList.contains("nav-search-enabled")){for(var e=document.querySelectorAll(".search-item"),t=0;t<e.length;t++)e[t].addEventListener("click",s,!1);document.addEventListener("click",function(e){if(document.querySelector(".navigation-search.nav-search-active")&&!e.target.closest(".navigation-search")&&!e.target.closest(".search-item"))for(var t=document.querySelectorAll(".search-item.active"),a=0;a<t.length;a++)s(e,t[a])},!1),document.addEventListener("keydown",function(e){if(document.querySelector(".navigation-search.nav-search-active")&&27===(e.which||e.keyCode))for(var t=document.querySelectorAll(".search-item.active"),a=0;a<t.length;a++)s(e,t[a])},!1)}}}();