From 3ff7a5ba91528508e251604048869e0ddfe52add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Fri, 1 Oct 2021 18:02:34 +0200 Subject: [PATCH] Add global search shortcut (#161) --- bookmarks/static/shared.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bookmarks/static/shared.js b/bookmarks/static/shared.js index dfd17e5..b613920 100644 --- a/bookmarks/static/shared.js +++ b/bookmarks/static/shared.js @@ -40,6 +40,28 @@ }); } + function initGlobalShortcuts() { + // Focus search button + document.addEventListener('keydown', function (event) { + // Filter for shortcut key + if (event.key !== 's') return; + // Skip if event occurred within an input element + const targetNodeName = event.target.nodeName; + const isInputTarget = targetNodeName === 'INPUT' + || targetNodeName === 'SELECT' + || targetNodeName === 'TEXTAREA'; - initConfirmationButtons() + if (isInputTarget) return; + + const searchInput = document.querySelector('input[type="search"]'); + + if (searchInput) { + searchInput.focus(); + event.preventDefault(); + } + }); + } + + initConfirmationButtons(); + initGlobalShortcuts(); })() \ No newline at end of file