|
2 | 2 | * This JS is only included when the RTD Sphinx search is active.
|
3 | 3 | */
|
4 | 4 |
|
5 |
| -setTimeout(overrideSearchButton, 0) |
6 |
| - |
7 |
| -function overrideSearchButton() { |
8 |
| - /** @type {HTMLDivElement} */ |
9 |
| - const search_backdrop = document.querySelector(".search__backdrop") |
10 |
| - if (!search_backdrop) { |
11 |
| - setTimeout(overrideSearchButton, 500) |
12 |
| - return |
| 5 | +// wire up the search key combination |
| 6 | +addEventListener("keydown", ({ key, metaKey, ctrlKey }) => { |
| 7 | + if (key === "k" && (metaKey || ctrlKey)) { |
| 8 | + showSearchModal() |
13 | 9 | }
|
14 |
| - search_backdrop.style.zIndex = "1020" |
| 10 | +}) |
| 11 | + |
| 12 | +// start attempting to override the search popup and to wire up the search button |
| 13 | +setTimeout(overrideSearch, 0) |
15 | 14 |
|
| 15 | +function overrideSearch() { |
| 16 | + /** @type {HTMLDivElement} */ |
| 17 | + const theme_popup = document.querySelector(".search-button__wrapper") |
16 | 18 | /** @type {HTMLButtonElement} */
|
17 | 19 | const search_button = document.querySelector("button[aria-label='Search']")
|
18 |
| - search_button.addEventListener("click", () => { |
19 |
| - showSearchModal() |
20 |
| - |
21 |
| - // hide the theme’s search popup |
22 |
| - /** @type {HTMLDivElement} */ |
23 |
| - const theme_popup = document.querySelector(".search-button__wrapper") |
24 |
| - theme_popup.style.display = "none" |
25 |
| - }) |
| 20 | + if (!theme_popup || !search_button) { |
| 21 | + // try again later |
| 22 | + setTimeout(overrideSearch, 500) |
| 23 | + return |
| 24 | + } |
| 25 | + // Hide the pydata theme’s search popup. |
| 26 | + theme_popup.style.display = "none" |
| 27 | + // wire up the search button |
| 28 | + search_button.addEventListener("click", () => showSearchModal()) |
26 | 29 | }
|
0 commit comments