blob: 3cc9da2a7fedafe2bfc6c4f9970a9272844a328d [file] [log] [blame]
{
"version": 3,
"sources": ["keyboard.ts"],
"sourcesContent": ["/*!\n * @license\n * Copyright 2019-2020 The Go Authors. All rights reserved.\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file.\n */\n\n// Keyboard shortcuts:\n// - Pressing '/' focuses the search box\n// - Pressing 'y' changes the browser URL to the canonical URL\n// without triggering a reload.\n\nconst searchInput = document.querySelector<HTMLInputElement>('.js-searchFocus');\nconst canonicalURLPath = document.querySelector<HTMLDivElement>('.js-canonicalURLPath')?.dataset[\n 'canonicalUrlPath'\n];\n\ndocument.addEventListener('keydown', e => {\n // TODO(golang.org/issue/40246): consolidate keyboard shortcut behavior across the site.\n const t = (e.target as HTMLElement)?.tagName;\n if (t === 'INPUT' || t === 'SELECT' || t === 'TEXTAREA') {\n return;\n }\n if ((e.target as HTMLElement)?.isContentEditable) {\n return;\n }\n if (e.metaKey || e.ctrlKey) {\n return;\n }\n switch (e.key) {\n case 'y':\n if (canonicalURLPath && canonicalURLPath !== '') {\n window.history.replaceState(null, '', canonicalURLPath);\n }\n break;\n case '/':\n // Favoring the Firefox quick find feature over search input\n // focus. See: https://github.com/golang/go/issues/41093.\n if (searchInput && !window.navigator.userAgent.includes('Firefox')) {\n e.preventDefault();\n searchInput.focus();\n }\n break;\n }\n});\n"],
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAYA,KAAM,aAAc,SAAS,cAAgC,mBACvD,iBAAmB,SAAS,cAA8B,yBAAyB,QACvF,iBAGF,SAAS,iBAAiB,UAAW,GAAK,CAExC,KAAM,GAAK,EAAE,QAAwB,QACrC,GAAI,MAAM,SAAW,IAAM,UAAY,IAAM,aAGxC,GAAE,QAAwB,mBAG3B,IAAE,SAAW,EAAE,SAGnB,OAAQ,EAAE,SACH,IACH,AAAI,kBAAoB,mBAAqB,IAC3C,OAAO,QAAQ,aAAa,KAAM,GAAI,kBAExC,UACG,IAGH,AAAI,aAAe,CAAC,OAAO,UAAU,UAAU,SAAS,YACtD,GAAE,iBACF,YAAY,SAEd",
"names": []
}