improved searchBar functionality:
on page reload, it now displays the query fitting to the entered string
This commit is contained in:
@@ -41,16 +41,7 @@ searchButton.addEventListener("click", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
searchBar.addEventListener("input", () => {
|
searchBar.addEventListener("input", () => {
|
||||||
if (searchBar.value === "") {
|
updateSections();
|
||||||
searchSection.classList.add("hidden");
|
|
||||||
recentSection.classList.remove("hidden");
|
|
||||||
mostLikedSection.classList.remove("hidden");
|
|
||||||
} else {
|
|
||||||
searchSection.classList.remove("hidden");
|
|
||||||
recentSection.classList.add("hidden");
|
|
||||||
mostLikedSection.classList.add("hidden");
|
|
||||||
}
|
|
||||||
|
|
||||||
clearTimeout(searchBarTimeout);
|
clearTimeout(searchBarTimeout);
|
||||||
searchBarTimeout = setTimeout(() => {
|
searchBarTimeout = setTimeout(() => {
|
||||||
const searchString = searchBar.value;
|
const searchString = searchBar.value;
|
||||||
@@ -137,6 +128,21 @@ function incrementPageCount() {
|
|||||||
lastQuery.currentPage++;
|
lastQuery.currentPage++;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = function () {
|
function updateSections() {
|
||||||
document.getElementById("search-entry").value = "";
|
if (searchBar.value === "") {
|
||||||
|
searchSection.classList.add("hidden");
|
||||||
|
recentSection.classList.remove("hidden");
|
||||||
|
mostLikedSection.classList.remove("hidden");
|
||||||
|
} else {
|
||||||
|
searchSection.classList.remove("hidden");
|
||||||
|
recentSection.classList.add("hidden");
|
||||||
|
mostLikedSection.classList.add("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.onload = function () {
|
||||||
|
updateSections();
|
||||||
|
if (searchBar.value !== "") {
|
||||||
|
search(searchBar.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user