Skip to content

Commit

Permalink
Fix occasional librarySearchInput not initialised error
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Dec 6, 2024
1 parent 8fb79d3 commit 1985313
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,21 @@ function showTab(tabname) {
document.getElementById(tabname).style.display = "inherit";
}

let librarySearchInput = document.querySelector("#searchform input");
const searchInputChangedDebounced = debounce(function() {
refreshLibrary({dontChangeSearchBox:true});
}, 300);
librarySearchInput.addEventListener('input', evt => {
let searchValue = evt.target.value.toLowerCase();
// Update window URL
let c = "";
let searchParams = new URLSearchParams(window.location.search);
if (searchParams.has("c"))
c = `c=${encodeURIComponent(searchParams.get("c").toLowerCase())}&`;
window.history.replaceState(null, null, `?${c}q=${encodeURIComponent(searchValue)}`);
searchInputChangedDebounced();
});

// =========================================== App Info

function getAppHTML(app, appInstalled, forInterface) {
Expand Down Expand Up @@ -1174,21 +1189,6 @@ filtersContainer.addEventListener('click', ({ target }) => {
refreshLibrary();
});

let librarySearchInput = document.querySelector("#searchform input");
const searchInputChangedDebounced = debounce(function() {
refreshLibrary({dontChangeSearchBox:true});
}, 300);
librarySearchInput.addEventListener('input', evt => {
let searchValue = evt.target.value.toLowerCase();
// Update window URL
let c = "";
let searchParams = new URLSearchParams(window.location.search);
if (searchParams.has("c"))
c = `c=${encodeURIComponent(searchParams.get("c").toLowerCase())}&`;
window.history.replaceState(null, null, `?${c}q=${encodeURIComponent(searchValue)}`);
searchInputChangedDebounced();
});

let sortContainer = document.querySelector("#librarycontainer .sort-nav");
sortContainer.addEventListener('click', ({ target }) => {
if (target.classList.contains('active')) return;
Expand Down

0 comments on commit 1985313

Please sign in to comment.