| | |
| | | const container = searchElement.querySelector(".search-container") as HTMLElement |
| | | if (!container) return |
| | | |
| | | const sidebar = container.closest(".sidebar") as HTMLElement |
| | | if (!sidebar) return |
| | | const sidebar = container.closest(".sidebar") as HTMLElement | null |
| | | |
| | | const searchButton = searchElement.querySelector(".search-button") as HTMLButtonElement |
| | | if (!searchButton) return |
| | |
| | | function hideSearch() { |
| | | container.classList.remove("active") |
| | | searchBar.value = "" // clear the input when we dismiss the search |
| | | sidebar.style.zIndex = "" |
| | | if (sidebar) sidebar.style.zIndex = "" |
| | | removeAllChildren(results) |
| | | if (preview) { |
| | | removeAllChildren(preview) |
| | |
| | | |
| | | function showSearch(searchTypeNew: SearchType) { |
| | | searchType = searchTypeNew |
| | | sidebar.style.zIndex = "1" |
| | | if (sidebar) sidebar.style.zIndex = "1" |
| | | container.classList.add("active") |
| | | searchBar.focus() |
| | | } |
| | |
| | | preview.replaceChildren(previewInner) |
| | | |
| | | // scroll to longest |
| | | const highlights = [...preview.querySelectorAll(".highlight")].sort( |
| | | const highlights = [...preview.getElementsByClassName("highlight")].sort( |
| | | (a, b) => b.innerHTML.length - a.innerHTML.length, |
| | | ) |
| | | highlights[0]?.scrollIntoView({ block: "start" }) |
| | |
| | | document.addEventListener("nav", async (e: CustomEventMap["nav"]) => { |
| | | const currentSlug = e.detail.url |
| | | const data = await fetchData |
| | | const searchElement = document.querySelectorAll(".search") |
| | | const searchElement = document.getElementsByClassName("search") |
| | | for (const element of searchElement) { |
| | | await setupSearch(element, currentSlug, data) |
| | | } |