Display item counter next to search form. #6

Merged
snoopy merged 5 commits from item-counter into main 2024-05-07 22:36:49 +02:00
2 changed files with 30 additions and 1 deletions
Showing only changes of commit 5028b28952 - Show all commits

View file

@ -7,6 +7,11 @@ h1, h1 a {
color: #dfaa37; /* C4 Yellow */
}
#itemcount {
display: inline-block;
margin-right: 1ch;
}
#map {
border: 1px solid #202020;
background: #4d4d4d;

View file

@ -36,6 +36,7 @@ function renderItems() {
container.appendChild(clone);
};
loading.remove();
updateCounter();
}
function getLocString(items, item) {
@ -89,6 +90,29 @@ function search(e) {
elem.classList.add('filtered');
}
}
updateCounter();
}
function updateCounter(){
let count = 0;
for (const elem of document.getElementsByClassName('result')) {
if (!elem.matches('.filtered')) {
count++;
}
}
switch(count) {
case 0:
document.getElementById('itemcount').textContent = `No items found.`;
break;
case 1:
document.getElementById('itemcount').textContent = `${count} item found.`;
break;
default:
document.getElementById('itemcount').textContent = `${count} items found.`;
break;
}
}
function showhidden(e){
@ -118,4 +142,4 @@ function showItem(e) {
function hideItem(e) {
clearMap();
}
}