Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 5b32d91

Browse files
authored
Remove global SEARCH_MODAL_STATE (#75)
1 parent 1d2df4d commit 5b32d91

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

sphinx_search/static/js/rtd_sphinx_search.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ const ANIMATION_TIME = 200;
55
const FETCH_RESULTS_DELAY = 250;
66
const CLEAR_RESULTS_DELAY = 300;
77

8-
// Possible states of search modal
9-
const SEARCH_MODAL_OPENED = "opened";
10-
const SEARCH_MODAL_CLOSED = "closed";
11-
12-
let SEARCH_MODAL_STATE = SEARCH_MODAL_CLOSED;
13-
148
// this is used to store the total result counts,
159
// which includes all the sections and domains of all the pages.
1610
let COUNT = 0;
@@ -124,6 +118,18 @@ const updateSearchBar = () => {
124118
};
125119

126120

121+
/*
122+
* Returns true if the modal window is visible.
123+
*/
124+
const isModalVisible = () => {
125+
let modal = document.querySelector(".search__outer__wrapper");
126+
if (modal !== null && modal.style !== null && modal.style.display !== null) {
127+
return modal.style.display === 'block';
128+
}
129+
return false;
130+
};
131+
132+
127133
/**
128134
* Create and return DOM nodes
129135
* with passed attributes.
@@ -570,8 +576,6 @@ const showSearchModal = custom_query => {
570576
// removes previous results (if there are any).
571577
removeResults();
572578

573-
SEARCH_MODAL_STATE = SEARCH_MODAL_OPENED;
574-
575579
// removes the focus from the initial input field
576580
// which as already present in the docs.
577581
let search_bar = getInputField();
@@ -606,8 +610,6 @@ const removeSearchModal = () => {
606610

607611
updateSearchBar();
608612

609-
SEARCH_MODAL_STATE = SEARCH_MODAL_CLOSED;
610-
611613
// sets the value of input field to empty string and remove the focus.
612614
let search_outer_input = document.querySelector(".search__outer__input");
613615
if (search_outer_input !== null) {
@@ -761,8 +763,7 @@ window.addEventListener("DOMContentLoaded", evt => {
761763

762764
// open search modal if "forward slash" button is pressed
763765
document.addEventListener("keydown", e => {
764-
if (e.keyCode === 191 && SEARCH_MODAL_STATE !== SEARCH_MODAL_OPENED) {
765-
766+
if (e.keyCode === 191 && !isModalVisible()) {
766767
// prevent opening "Quick Find" in Firefox
767768
e.preventDefault();
768769
showSearchModal();

0 commit comments

Comments
 (0)