WordPress/wp-includes/blocks/search/view.min.js

1 line
1.2 KiB
JavaScript

window.addEventListener("DOMContentLoaded",(()=>{const e="wp-block-search__searchfield-hidden";Array.from(document.getElementsByClassName("wp-block-search__button-behavior-expand")).forEach((t=>{const r=t.querySelector(".wp-block-search__input"),a=t.querySelector(".wp-block-search__button"),i=t.querySelector(".wp-block-search__label"),s=a.getAttribute("aria-label"),o=r.getAttribute("id"),c=i=>i?(r.removeAttribute("aria-hidden"),r.removeAttribute("tabindex"),a.removeAttribute("aria-expanded"),a.removeAttribute("aria-controls"),a.setAttribute("type","submit"),a.setAttribute("aria-label","Submit Search"),t.classList.remove(e)):(a.removeAttribute("type"),r.setAttribute("aria-hidden","true"),r.setAttribute("tabindex","-1"),a.setAttribute("aria-expanded","false"),a.setAttribute("aria-controls",o),a.setAttribute("aria-label",s),t.classList.add(e)),d=e=>e.target.closest(".wp-block-search")?"Escape"===e.key?(a.focus(),c(!1)):void 0:c(!1),n=a=>{t.classList.contains(e)&&(a.preventDefault(),r.focus(),c(!0))};a.removeAttribute("type"),r.addEventListener("keydown",(e=>{d(e)})),a.addEventListener("click",n),a.addEventListener("keydown",(e=>{d(e)})),i&&i.addEventListener("click",n),document.body.addEventListener("click",d)}))}));