From 515d9b4036f537eb038d83938f6e88d13ecdc335 Mon Sep 17 00:00:00 2001 From: thephez Date: Tue, 8 Oct 2024 10:49:26 -0400 Subject: [PATCH] feat: show search --- _static/js/pydata-search-close.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/_static/js/pydata-search-close.js b/_static/js/pydata-search-close.js index 738cc817..f46b131a 100644 --- a/_static/js/pydata-search-close.js +++ b/_static/js/pydata-search-close.js @@ -44,6 +44,23 @@ var hideSearchField = () => { } }; +function showSearchModal() { + // Remove previous search results + removeResults(); + + // Focus the search input field + const searchInput = document.querySelector(".search__outer__input"); + const modalWrapper = document.querySelector(".search__outer__wrapper"); + + if (searchInput !== null && modalWrapper !== null) { + searchInput.focus(); // Focus the input field + + // Display the search modal + modalWrapper.style.display = "block"; // Show the modal + } +} + + /** Add an event listener for hideSearchField() for Escape*/ var addEventListenerForSearchKeyboard = () => { window.addEventListener( @@ -55,6 +72,12 @@ var addEventListenerForSearchKeyboard = () => { hideSearchField(); } + // Original listener for "/" + if (e.keyCode === 191 && !isModalVisible()) { + e.preventDefault(); + showSearchModal(); + } + // Open the new search modal by simulating "/" keypress when Ctrl+K is pressed if (event.ctrlKey && event.key === 'k') { console.log('ctrl+k was pressed')