Skip to content

Commit 8aeaae4

Browse files
Create customfilter.js
1 parent 1fd5590 commit 8aeaae4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

js/customfilter.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
filterSelection("all")
2+
function filterSelection(c) {
3+
var x, i;
4+
x = document.getElementsByClassName("filterDiv");
5+
if (c == "all") c = "";
6+
for (i = 0; i < x.length; i++) {
7+
w3RemoveClass(x[i], "show");
8+
if (x[i].className.indexOf(c) > -1) w3AddClass(x[i], "show");
9+
}
10+
}
11+
12+
function w3AddClass(element, name) {
13+
var i, arr1, arr2;
14+
arr1 = element.className.split(" ");
15+
arr2 = name.split(" ");
16+
for (i = 0; i < arr2.length; i++) {
17+
if (arr1.indexOf(arr2[i]) == -1) {element.className += " " + arr2[i];}
18+
}
19+
}
20+
21+
function w3RemoveClass(element, name) {
22+
var i, arr1, arr2;
23+
arr1 = element.className.split(" ");
24+
arr2 = name.split(" ");
25+
for (i = 0; i < arr2.length; i++) {
26+
while (arr1.indexOf(arr2[i]) > -1) {
27+
arr1.splice(arr1.indexOf(arr2[i]), 1);
28+
}
29+
}
30+
element.className = arr1.join(" ");
31+
}
32+
33+
// Add active class to the current button (highlight it)
34+
var btnContainer = document.getElementById("myBtnContainer");
35+
var btns = btnContainer.getElementsByClassName("btn");
36+
for (var i = 0; i < btns.length; i++) {
37+
btns[i].addEventListener("click", function(){
38+
var current = document.getElementsByClassName("active");
39+
current[0].className = current[0].className.replace(" active", "");
40+
this.className += " active";
41+
});
42+
}

0 commit comments

Comments
 (0)