From 984551227b5606e30cb60d2394425ed7d5866944 Mon Sep 17 00:00:00 2001 From: shadowninja55 <49539636+shadowninja55@users.noreply.github.com> Date: Sat, 19 Jun 2021 22:16:50 -0400 Subject: [PATCH] doc: allow pressing / to focus search bar (#10522) * type / to focus search; rename unused variables * use ev.preventDefault() instead of setTimeout() * delete doc.js_ --- cmd/tools/vdoc/resources/doc.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/tools/vdoc/resources/doc.js b/cmd/tools/vdoc/resources/doc.js index afc4b7f56b..c355d7ee0b 100644 --- a/cmd/tools/vdoc/resources/doc.js +++ b/cmd/tools/vdoc/resources/doc.js @@ -20,7 +20,7 @@ function setupScrollSpy() { sectionPositions.push(section.offsetTop); }); var scrollPos = 0; - window.addEventListener('scroll', function (e) { + window.addEventListener('scroll', function (_) { // Reset classes document.querySelectorAll('.doc-toc a[class="active"]').forEach(function (link) { link.classList.remove('active'); @@ -52,7 +52,7 @@ function setupScrollSpy() { function setupMobileToggle() { var toggle = document.getElementById('toggle-menu'); - toggle.addEventListener('click', function (ev) { + toggle.addEventListener('click', function (_) { var docNav = document.querySelector('.doc-nav'); var isHidden = docNav.classList.contains('hidden'); docNav.classList.toggle('hidden'); @@ -225,3 +225,11 @@ function debounce(func, timeout) { timer = setTimeout(next, timeout > 0 ? timeout : 300); } } + +document.addEventListener('keypress', (ev) => { + if (ev.key == '/') { + let search = document.getElementById('search'); + ev.preventDefault(); + search.focus(); + } +});