blob: cf284f676909904e2aad4f59055026b045423c93 [file] [log] [blame]
{
"version": 3,
"sources": ["header.ts"],
"sourcesContent": ["function registerHeaderListeners() {\n const header = document.querySelector('.js-header');\n const menuButtons = document.querySelectorAll('.js-headerMenuButton');\n menuButtons.forEach(button => {\n button.addEventListener('click', e => {\n e.preventDefault();\n header?.classList.toggle('is-active');\n button.setAttribute('aria-expanded', String(header?.classList.contains('is-active')));\n });\n });\n\n const scrim = document.querySelector('.js-scrim');\n scrim?.addEventListener('click', e => {\n e.preventDefault();\n header?.classList.remove('is-active');\n menuButtons.forEach(button => {\n button.setAttribute('aria-expanded', String(header?.classList.contains('is-active')));\n });\n });\n}\n\nfunction registerSearchFormListeners() {\n const BREAKPOINT = 512;\n const logo = document.querySelector('.js-headerLogo');\n const form = document.querySelector<HTMLFormElement>('.js-searchForm');\n const button = document.querySelector('.js-searchFormSubmit');\n const input = form?.querySelector('input');\n\n renderForm();\n\n window.addEventListener('resize', renderForm);\n\n function renderForm() {\n if (window.innerWidth > BREAKPOINT) {\n logo?.classList.remove('go-Header-logo--hidden');\n form?.classList.remove('go-SearchForm--open');\n input?.removeEventListener('focus', showSearchBox);\n input?.removeEventListener('keypress', handleKeypress);\n input?.removeEventListener('focusout', hideSearchBox);\n } else {\n button?.addEventListener('click', handleSearchClick);\n input?.addEventListener('focus', showSearchBox);\n input?.addEventListener('keypress', handleKeypress);\n input?.addEventListener('focusout', hideSearchBox);\n }\n }\n\n /**\n * Submits form if Enter key is pressed\n */\n function handleKeypress(e: KeyboardEvent) {\n if (e.key === 'Enter') form?.submit();\n }\n\n /**\n * Shows the search box when it receives focus (expands it from\n * just the spyglass if we're on mobile).\n */\n function showSearchBox() {\n logo?.classList.add('go-Header-logo--hidden');\n form?.classList.add('go-SearchForm--open');\n }\n\n /**\n * Hides the search box (shrinks to just the spyglass icon).\n */\n function hideSearchBox() {\n logo?.classList.remove('go-Header-logo--hidden');\n form?.classList.remove('go-SearchForm--open');\n }\n\n /**\n * Expands the searchbox so input is visible and gives\n * the input focus.\n */\n function handleSearchClick(e: Event) {\n e.preventDefault();\n\n showSearchBox();\n input?.focus();\n }\n}\n\nregisterHeaderListeners();\nregisterSearchFormListeners();\n"],
"mappings": "AAAA,kCAAmC,CACjC,KAAM,GAAS,SAAS,cAAc,cAChC,EAAc,SAAS,iBAAiB,wBAC9C,EAAY,QAAQ,GAAU,CAC5B,EAAO,iBAAiB,QAAS,GAAK,CACpC,EAAE,iBACF,GAAQ,UAAU,OAAO,aACzB,EAAO,aAAa,gBAAiB,OAAO,GAAQ,UAAU,SAAS,mBAK3E,AADc,SAAS,cAAc,cAC9B,iBAAiB,QAAS,GAAK,CACpC,EAAE,iBACF,GAAQ,UAAU,OAAO,aACzB,EAAY,QAAQ,GAAU,CAC5B,EAAO,aAAa,gBAAiB,OAAO,GAAQ,UAAU,SAAS,mBAK7E,sCAAuC,CACrC,KAAM,GAAa,IACb,EAAO,SAAS,cAAc,kBAC9B,EAAO,SAAS,cAA+B,kBAC/C,EAAS,SAAS,cAAc,wBAChC,EAAQ,GAAM,cAAc,SAElC,IAEA,OAAO,iBAAiB,SAAU,GAElC,YAAsB,CACpB,AAAI,OAAO,WAAa,EACtB,IAAM,UAAU,OAAO,0BACvB,GAAM,UAAU,OAAO,uBACvB,GAAO,oBAAoB,QAAS,GACpC,GAAO,oBAAoB,WAAY,GACvC,GAAO,oBAAoB,WAAY,IAEvC,IAAQ,iBAAiB,QAAS,GAClC,GAAO,iBAAiB,QAAS,GACjC,GAAO,iBAAiB,WAAY,GACpC,GAAO,iBAAiB,WAAY,IAOxC,WAAwB,EAAkB,CACxC,AAAI,EAAE,MAAQ,SAAS,GAAM,SAO/B,YAAyB,CACvB,GAAM,UAAU,IAAI,0BACpB,GAAM,UAAU,IAAI,uBAMtB,YAAyB,CACvB,GAAM,UAAU,OAAO,0BACvB,GAAM,UAAU,OAAO,uBAOzB,WAA2B,EAAU,CACnC,EAAE,iBAEF,IACA,GAAO,SAIX,0BACA",
"names": []
}