From 8aed1e11c34a063b7c8a19934e147118db0709d1 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 13 Jan 2022 22:20:10 +0100 Subject: [PATCH] Add JS to focus search box on '/' --- assets/js/handlers.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/assets/js/handlers.js b/assets/js/handlers.js index 1498f39aa..a417fccae 100644 --- a/assets/js/handlers.js +++ b/assets/js/handlers.js @@ -142,4 +142,16 @@ var csrf_token = target.parentNode.querySelector('input[name="csrf_token"]').value; xhr.send('csrf_token=' + csrf_token); } + + // Handle keypresses + window.addEventListener('keydown', (event) => { + // Ignore modifier keys + if (event.ctrlKey || event.metaKey) { return; } + + // Focus search bar on '/' + if (event.key == "/") { + document.getElementById('searchbox').focus(); + event.preventDefault(); + } + }); })();