File: search-focus.js

package info (click to toggle)
python-docs-theme 2025.4.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 192 kB
  • sloc: javascript: 150; python: 114; makefile: 25
file content (21 lines) | stat: -rw-r--r-- 559 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function isInputFocused() {
  const activeElement = document.activeElement;
  return (
    activeElement.tagName === 'INPUT' ||
    activeElement.tagName === 'TEXTAREA' ||
    activeElement.isContentEditable
  );
}

document.addEventListener('keydown', function(event) {
  if (event.key === '/') {
    if (!isInputFocused()) {
      // Prevent "/" from being entered in the search box
      event.preventDefault();

      // Set the focus on the search box
      const searchBox = document.getElementById('search-box');
      searchBox.focus();
    }
  }
});