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

Commit 93f35aa

Browse files
committed
update
1 parent 79bc347 commit 93f35aa

File tree

3 files changed

+74
-16
lines changed

3 files changed

+74
-16
lines changed

sphinx_search/_static/js/rtd_sphinx_search.js

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,26 @@ const debounce = (func, wait) => {
5353
* @return {String|Array} object in url params form
5454
*/
5555
const convertObjToUrlParams = obj => {
56-
const params = Object.keys(obj)
57-
.map(function(key) {
58-
if (_is_string(key)) {
59-
const s = key + "=" + encodeURI(obj[key]);
60-
return s;
61-
}
62-
})
63-
.join("&");
64-
return params;
56+
let params = Object.keys(obj).map(function(key) {
57+
if (_is_string(key)) {
58+
const s = key + "=" + encodeURI(obj[key]);
59+
return s;
60+
}
61+
});
62+
63+
// removing empty strings from the 'params' array
64+
let final_params = [];
65+
for (let i = 0; i < params.length; ++i) {
66+
if (_is_string(params[i])) {
67+
final_params.push(params[i]);
68+
}
69+
}
70+
if (final_params.length === 1) {
71+
return final_params[0];
72+
} else {
73+
let final_url_params = final_params.join("&");
74+
return final_url_params;
75+
}
6576
};
6677

6778
/**
@@ -84,8 +95,8 @@ const updateUrl = () => {
8495
// when window.location.origin is "null" in Firefox
8596
// then correct URL is contained by window.location.pathname
8697
// which starts with "file://"
87-
let url = path + "?" + window_location_search
88-
if (origin.substring(0, 4) === 'http'){
98+
let url = path + "?" + window_location_search;
99+
if (origin.substring(0, 4) === "http") {
89100
url = origin + url;
90101
}
91102

@@ -583,7 +594,7 @@ const generateAndReturnInitialHtml = () => {
583594

584595
/**
585596
* Opens the search modal.
586-
*
597+
*
587598
* @param {String} custom_query if a custom query is provided, initialise the value of input field with it
588599
*/
589600
const showSearchModal = custom_query => {
@@ -628,6 +639,12 @@ const removeSearchModal = () => {
628639
search_outer_input.blur();
629640
}
630641

642+
// reset SEARCH_QUERY
643+
SEARCH_QUERY = "";
644+
645+
// update url (remove 'rtd_search' param)
646+
updateUrl();
647+
631648
$(".search__outer__wrapper").fadeOut(400);
632649
};
633650

@@ -643,9 +660,13 @@ window.addEventListener("DOMContentLoaded", evt => {
643660
let initialHtml = generateAndReturnInitialHtml();
644661
document.body.innerHTML += initialHtml;
645662

646-
let search_outer_wrapper = document.querySelector('.search__outer__wrapper');
647-
let search_outer_input = document.querySelector('.search__outer__input');
648-
let cross_icon = document.querySelector('.search__cross');
663+
let search_outer_wrapper = document.querySelector(
664+
".search__outer__wrapper"
665+
);
666+
let search_outer_input = document.querySelector(
667+
".search__outer__input"
668+
);
669+
let cross_icon = document.querySelector(".search__cross");
649670

650671
// this denotes the search suggestion which is currently selected
651672
// via tha ArrowUp/ArrowDown keys.

0 commit comments

Comments
 (0)