Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add forward slash as hotkey for search UI #31

Merged
merged 1 commit into from Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions sphinx_search/_static/js/rtd_sphinx_search.js
Expand Up @@ -2,6 +2,11 @@ const MAX_SUGGESTIONS = 50;
const MAX_SECTION_RESULTS = 3;
const MAX_SUBSTRING_LIMIT = 100;

// Possible states of search modal
const SEARCH_MODAL_OPENED = "opened";
const SEARCH_MODAL_CLOSED = "closed";

let SEARCH_MODAL_STATE = SEARCH_MODAL_CLOSED;
let TOTAL_PAGE_RESULTS = 0;
let SEARCH_QUERY = "";

Expand Down Expand Up @@ -603,6 +608,8 @@ const showSearchModal = custom_query => {
// removes previous results (if there are any).
removeResults();

SEARCH_MODAL_STATE = SEARCH_MODAL_OPENED;

// removes the focus from the initial input field
// which as already present in the docs.
let search_bar = getInputField();
Expand Down Expand Up @@ -634,6 +641,8 @@ const removeSearchModal = () => {
// removes previous results before closing
removeResults();

SEARCH_MODAL_STATE = SEARCH_MODAL_CLOSED;

// sets the value of input field to empty string and remove the focus.
let search_outer_input = document.querySelector(".search__outer__input");
if (search_outer_input !== null) {
Expand Down Expand Up @@ -786,6 +795,15 @@ window.addEventListener("DOMContentLoaded", evt => {
}
});

// open search modal if "forward slash" button is pressed
document.addEventListener("keydown", e => {
if (e.keyCode === 191) {
if (SEARCH_MODAL_STATE !== SEARCH_MODAL_OPENED) {
showSearchModal();
}
}
});

// if "rtd_search" is present in URL parameters,
// then open the search modal and show the results
// for the value of "rtd_search"
Expand Down
2 changes: 1 addition & 1 deletion sphinx_search/_static/js/rtd_sphinx_search.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.