2023-06-15 09:18:46 +00:00
|
|
|
filterSelection("all")
|
|
|
|
function filterSelection(c) {
|
2023-06-22 18:05:23 +00:00
|
|
|
let x, i;
|
|
|
|
x = document.getElementsByClassName("filter-div");
|
|
|
|
if (c == "all") c = "";
|
|
|
|
// Add the "show-items" class (display:block) to the filtered elements, and remove the "show-items" class from the elements that are not selected
|
|
|
|
for (i = 0; i < x.length; i++) {
|
|
|
|
w3RemoveClass(x[i], "show-items");
|
|
|
|
if (x[i].className.indexOf(c) > -1) w3AddClass(x[i], "show-items");
|
|
|
|
}
|
2023-06-15 09:18:46 +00:00
|
|
|
}
|
|
|
|
|
2023-06-22 18:05:23 +00:00
|
|
|
// show-items filtered elements
|
2023-06-15 09:18:46 +00:00
|
|
|
function w3AddClass(element, name) {
|
2023-06-22 18:05:23 +00:00
|
|
|
let i, arr1, arr2;
|
|
|
|
arr1 = element.className.split(" ");
|
|
|
|
arr2 = name.split(" ");
|
|
|
|
for (i = 0; i < arr2.length; i++) {
|
|
|
|
if (arr1.indexOf(arr2[i]) == -1) {
|
|
|
|
element.className += " " + arr2[i];
|
|
|
|
}
|
2023-06-15 09:18:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide elements that are not selected
|
|
|
|
function w3RemoveClass(element, name) {
|
2023-06-22 18:05:23 +00:00
|
|
|
let i, arr1, arr2;
|
|
|
|
arr1 = element.className.split(" ");
|
|
|
|
arr2 = name.split(" ");
|
|
|
|
for (i = 0; i < arr2.length; i++) {
|
|
|
|
while (arr1.indexOf(arr2[i]) > -1) {
|
|
|
|
arr1.splice(arr1.indexOf(arr2[i]), 1);
|
|
|
|
}
|
2023-06-15 09:18:46 +00:00
|
|
|
}
|
2023-06-22 18:05:23 +00:00
|
|
|
element.className = arr1.join(" ");
|
2023-06-15 09:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add active class to the current control button (highlight it)
|
2023-06-22 18:05:23 +00:00
|
|
|
let btnContainer = document.getElementById("myBtnContainer");
|
|
|
|
let btns = btnContainer.getElementsByClassName("filter-btn");
|
|
|
|
for (let i = 0; i < btns.length; i++) {
|
|
|
|
btns[i].addEventListener("click", function() {
|
|
|
|
let current = document.getElementsByClassName("active");
|
|
|
|
current[0].className = current[0].className.replace(" active", "");
|
|
|
|
this.className += " active";
|
|
|
|
});
|
2023-06-15 09:18:46 +00:00
|
|
|
}
|