1/** 2 * Header magnifier: opens the search field, closes on Escape or a click 3 * outside. Below 992px the navbar collapses and the field is already in the 4 * flow of the hamburger menu, so the toggle is hidden by CSS and this does 5 * nothing there. 6 */ 7(function () { 8 document.addEventListener('DOMContentLoaded', function () { 9 var wrap = document.querySelector('.header-search'); 10 if (!wrap) { return; } 11 12 var toggle = wrap.querySelector('.header-search-toggle'); 13 var input = wrap.querySelector('input[type="search"]'); 14 if (!toggle || !input) { return; } 15 16 function open() { 17 wrap.classList.add('open'); 18 toggle.setAttribute('aria-expanded', 'true'); 19 input.focus(); 20 input.select(); 21 } 22 23 function close() { 24 wrap.classList.remove('open'); 25 toggle.setAttribute('aria-expanded', 'false'); 26 } 27 28 toggle.addEventListener('click', function (e) { 29 e.preventDefault(); 30 e.stopPropagation(); 31 wrap.classList.contains('open') ? close() : open(); 32 }); 33 34 // An empty query would land on the home page rather than results. 35 wrap.querySelector('form').addEventListener('submit', function (e) { 36 if (input.value.trim() === '') { 37 e.preventDefault(); 38 input.focus(); 39 } 40 }); 41 42 document.addEventListener('click', function (e) { 43 if (wrap.classList.contains('open') && !wrap.contains(e.target)) { close(); } 44 }); 45 46 document.addEventListener('keydown', function (e) { 47 if (e.key === 'Escape' && wrap.classList.contains('open')) { 48 close(); 49 toggle.focus(); 50 } 51 }); 52 }); 53})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.