Searchtools: don't assume that all themes define some elements

When retrieving a non-existent element, jQuery would still return an
object (kind of empty one, so method calls won't raise a null
exception), but now `getElementById` will return null and raise an
exception when trying to call a method on that value.

This mainly affects the rtd theme,
which completely overrides the search page
d64dadf1ce/sphinx_rtd_theme/search.html
This commit is contained in:
Santos Gallegos 2022-01-31 19:07:51 -05:00
parent 3b01fbe2ad
commit 6605bfbf7c
No known key found for this signature in database
GPG Key ID: 811173C303342045

View File

@ -48,7 +48,7 @@ if (!Scorer) {
}
const _removeChildren = (element) => {
while (element.lastChild) element.removeChild(element.lastChild);
while (element && element.lastChild) element.removeChild(element.lastChild);
};
/**
@ -208,9 +208,11 @@ const Search = {
Search.status = out.appendChild(searchSummary);
Search.output = out.appendChild(searchList);
document.getElementById("search-progress").innerText = _(
"Preparing search..."
);
const searchProgress = document.getElementById("search-progress");
// Not all themes may have this element.
if (searchProgress) {
searchProgress.innerText = _("Preparing search...");
}
Search.startPulse();
// index already loaded, the browser was quick!