Display item counter next to search form.
All checks were successful
deployment-on-pull-request / deployment (pull_request) Successful in 1m16s

This commit is contained in:
Shy 2024-05-04 20:38:32 +02:00
parent b9e87f09d5
commit 3d91fe8f3a
2 changed files with 30 additions and 1 deletions

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();
}
}