| 1 |
function isInputFocused() { |
| 2 |
const activeElement = document.activeElement; |
| 3 |
return ( |
| 4 |
activeElement.tagName === 'INPUT' || |
| 5 |
activeElement.tagName === 'TEXTAREA' || |
| 6 |
activeElement.isContentEditable |
| 7 |
); |
| 8 |
} |
| 9 |
|
| 10 |
document.addEventListener('keydown', function(event) { |
| 11 |
if (event.key === '/') { |
| 12 |
if (!isInputFocused()) { |
| 13 |
// Prevent "/" from being entered in the search box |
| 14 |
event.preventDefault(); |
| 15 |
|
| 16 |
// Set the focus on the search box |
| 17 |
const searchBox = document.getElementById('search-box'); |
| 18 |
searchBox.focus(); |
| 19 |
} |
| 20 |
} |
| 21 |
}); |