Skip to content

Commit 1985313

Browse files
committed
Fix occasional librarySearchInput not initialised error
1 parent 8fb79d3 commit 1985313

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

js/index.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,21 @@ function showTab(tabname) {
427427
document.getElementById(tabname).style.display = "inherit";
428428
}
429429

430+
let librarySearchInput = document.querySelector("#searchform input");
431+
const searchInputChangedDebounced = debounce(function() {
432+
refreshLibrary({dontChangeSearchBox:true});
433+
}, 300);
434+
librarySearchInput.addEventListener('input', evt => {
435+
let searchValue = evt.target.value.toLowerCase();
436+
// Update window URL
437+
let c = "";
438+
let searchParams = new URLSearchParams(window.location.search);
439+
if (searchParams.has("c"))
440+
c = `c=${encodeURIComponent(searchParams.get("c").toLowerCase())}&`;
441+
window.history.replaceState(null, null, `?${c}q=${encodeURIComponent(searchValue)}`);
442+
searchInputChangedDebounced();
443+
});
444+
430445
// =========================================== App Info
431446

432447
function getAppHTML(app, appInstalled, forInterface) {
@@ -1174,21 +1189,6 @@ filtersContainer.addEventListener('click', ({ target }) => {
11741189
refreshLibrary();
11751190
});
11761191

1177-
let librarySearchInput = document.querySelector("#searchform input");
1178-
const searchInputChangedDebounced = debounce(function() {
1179-
refreshLibrary({dontChangeSearchBox:true});
1180-
}, 300);
1181-
librarySearchInput.addEventListener('input', evt => {
1182-
let searchValue = evt.target.value.toLowerCase();
1183-
// Update window URL
1184-
let c = "";
1185-
let searchParams = new URLSearchParams(window.location.search);
1186-
if (searchParams.has("c"))
1187-
c = `c=${encodeURIComponent(searchParams.get("c").toLowerCase())}&`;
1188-
window.history.replaceState(null, null, `?${c}q=${encodeURIComponent(searchValue)}`);
1189-
searchInputChangedDebounced();
1190-
});
1191-
11921192
let sortContainer = document.querySelector("#librarycontainer .sort-nav");
11931193
sortContainer.addEventListener('click', ({ target }) => {
11941194
if (target.classList.contains('active')) return;

0 commit comments

Comments
 (0)