|
1 | 1 | ; (function () { |
2 | 2 | 'use strict' |
3 | 3 |
|
4 | | - var searchButton = document.getElementById('search-button') |
5 | | - if (!searchButton) return |
6 | | - searchButton.addEventListener('click', toggleNavbarMenu.bind(searchButton)) |
7 | | - |
8 | | - function toggleNavbarMenu (e) { |
9 | | - e.stopPropagation() // trap event |
| 4 | + function openSearchPopover () { |
10 | 5 | document.getElementById('search-background').style.display = 'block' |
11 | 6 | document.getElementById('search').style.display = 'block' |
12 | 7 | var searchInput = document.querySelector('.pagefind-modular-input') |
13 | 8 | if (!searchInput) return |
14 | 9 | searchInput.focus() |
15 | 10 | } |
16 | | -})() |
17 | 11 |
|
18 | | -; (function () { |
19 | | - 'use strict' |
| 12 | + // open the popover when clicking the magnifying glass search icon |
| 13 | + var searchButton = document.getElementById('search-button') |
| 14 | + if (!searchButton) return |
| 15 | + searchButton.addEventListener('click', function (event) { |
| 16 | + event.stopPropagation() |
| 17 | + openSearchPopover() |
| 18 | + }) |
20 | 19 |
|
| 20 | + // open the popover with ctrl+k |
| 21 | + document.addEventListener('keydown', function (event) { |
| 22 | + if (event.ctrlKey && event.key === 'k') { |
| 23 | + event.preventDefault() // prevent focussing the URL bar in the browser |
| 24 | + openSearchPopover() |
| 25 | + } |
| 26 | + }) |
| 27 | + |
| 28 | + // close functionality when clicking the background |
21 | 29 | var searchBackground = document.getElementById('search-background') |
22 | 30 | if (!searchBackground) return |
23 | | - searchBackground.addEventListener('click', toggleNavbarMenu.bind(searchBackground)) |
24 | | - |
25 | | - function toggleNavbarMenu (e) { |
| 31 | + searchBackground.addEventListener('click', function (e) { |
26 | 32 | e.stopPropagation() // trap event |
27 | 33 | document.getElementById('search-background').style.display = 'none' |
28 | 34 | document.getElementById('search').style.display = 'none' |
29 | | - } |
| 35 | + }) |
30 | 36 | })() |
0 commit comments