website/static/src/js/search.js

16 lines
591 B
JavaScript
Raw Normal View History

2022-08-02 21:11:35 +01:00
window.addEventListener("DOMContentLoaded", () => {
2022-08-02 09:27:43 +01:00
const searchResults = document.getElementById("search-results");
2022-08-02 21:11:35 +01:00
const resultsCountDisplay = document.getElementById("result-count");
2022-08-02 09:27:43 +01:00
function handleSearchResults(event) {
2022-08-02 21:11:35 +01:00
const resultsCount = event.target.querySelectorAll(".listing-item").length;
if (resultsCount) {
resultsCountDisplay.textContent =
`Found ${resultsCount} result` + (resultsCount > 1 ? "s" : "");
} else {
resultsCountDisplay.textContent = "";
}
2022-08-02 09:27:43 +01:00
}
2022-08-02 21:11:35 +01:00
searchResults.addEventListener("htmx:afterSwap", handleSearchResults);
2022-08-02 09:27:43 +01:00
});