Display item counter next to search form. #6
2 changed files with 30 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue