diff --git a/_static/js/pydata-search-close.js b/_static/js/pydata-search-close.js index b7147eaf..6aa16fbd 100644 --- a/_static/js/pydata-search-close.js +++ b/_static/js/pydata-search-close.js @@ -1,5 +1,4 @@ -// Script to allow use of readthedocs-sphinx-search extension with the pydata -// theme +// Script to allow use of readthedocs-sphinx-search extension with the pydata theme // // Based in part on: // https://github.com/pydata/pydata-sphinx-theme/blob/v0.13.3/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js#L167-L272 @@ -28,9 +27,8 @@ var findSearchInput = () => { } }; -/** Function to hide the search field */ -var hideSearchField = () => { - +// Hide Pydata theme's search +var hidePydataSearch = () => { let input = findSearchInput(); let searchPopupWrapper = document.querySelector(".search-button__wrapper"); let hiddenInput = searchPopupWrapper.querySelector("input"); @@ -44,38 +42,65 @@ var hideSearchField = () => { } }; -/** Add an event listener for hideSearchField() for Escape*/ +// Hide the ReadTheDocs search (addon version) +function hideRtdSearch() { + // Grab the search element from the DOM + const searchElement = document.querySelector('readthedocs-search'); + searchElement.closeModal(); +} + +// Hide any open search screens +function hideSearch() { + hidePydataSearch(); + hideRtdSearch(); +} + +// Show the ReadTheDocs search (addon version) +function showRtDSearch() { + const searchElement = document.querySelector('readthedocs-search'); + searchElement.showModal(); + + // If we're displaying ReadTheDocs search, make sure to hide the Pydata theme's search + hidePydataSearch(); +} + +// Add event listeners for key strokes var addEventListenerForSearchKeyboard = () => { window.addEventListener( "keydown", (event) => { // Allow Escape key to hide the search field if (event.code == "Escape") { - hideSearchField(); + hidePydataSearch(); + } + + // Open the ReadTheDocs search modal when Ctrl+K is pressed + if (event.ctrlKey && event.key === 'k') { + event.preventDefault(); // Prevent default behavior of Ctrl+K + showRtDSearch() } }, true ); }; -/** Activate callbacks for search button popup */ +// Activate callbacks for search button popup var setupSearchButtons = () => { addEventListenerForSearchKeyboard(); + + // Add event listeners to elements with class "search-button__button" + const searchButtons = document.querySelectorAll('.search-button__button'); + searchButtons.forEach(button => { + button.addEventListener('click', showRtDSearch); + }); }; // Custom code to manage closing the RtD search dialog properly $(document).ready(function(){ - $(".search__cross").click(function(){ - hideSearchField(); - }); - $(".search__outer__wrapper.search__backdrop").click(function(){ - hideSearchField(); - }); $(".search-button__overlay").click(function(){ - // Shouldn't be necessary since it's currently hidden by CSS, but just in - // case + // Shouldn't be necessary since it's currently hidden by CSS, but just in case console.log("Close by search-button__overlay"); - hideSearchField(); + hidePydataSearch(); }); }); diff --git a/conf.py b/conf.py index 1212cfd5..1a7dc6b6 100644 --- a/conf.py +++ b/conf.py @@ -40,7 +40,6 @@ 'sphinx.ext.autodoc', 'sphinx_copybutton', 'sphinx_design', - 'sphinx_search.extension', 'sphinx.ext.intersphinx', ]