-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.js
94 lines (80 loc) · 3.11 KB
/
filters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Add event listener to coresponding item selected by its id and do something on change
document.querySelector("#filter-marketing").addEventListener("change", filterMarketing);
document.querySelector("#filter-programming").addEventListener("change", filterProgramming);
document.querySelector("#filter-design").addEventListener("change", filterDesign);
// Function to hide all cards
function hideAllProjects() {
var allProjects = document.querySelectorAll(".cards");
allProjects.forEach((project) => {
project.style.display = "none";
});
}
// Function to show all cards
function showAllProjects() {
var allProjects = document.querySelectorAll(".cards");
allProjects.forEach((project) => {
project.style.display = "block";
});
}
// Function to remove active class
function removeActive() {
document.querySelector(".filter-marketing").classList.remove("active");
document.querySelector(".filter-programming").classList.remove("active");
document.querySelector(".filter-design").classList.remove("active");
}
// Function to filter only marketing cards
function filterMarketing() {
// First hide all projects
hideAllProjects();
// if the filter marketing checkbox is checked display marketing cards
if (document.querySelector("#filter-marketing").checked) {
var marketingProjects = document.querySelectorAll(".marketing");
marketingProjects.forEach((marketingProject) => {
marketingProject.style.display = "block";
});
// removes active class if something else is checked
removeActive();
// then adds active class just to the marketing checkbox
document.querySelector(".filter-marketing").classList.add("active");
// and we make sure other checkboxes are off
document.querySelector("#filter-programming").checked = false;
document.querySelector("#filter-design").checked = false;
} else {
// remove classes and shows all cards
removeActive();
showAllProjects();
}
}
// Same goes here as the function for filtering marketing (same concept)
function filterProgramming() {
hideAllProjects();
if (document.querySelector("#filter-programming").checked) {
var programmingProjects = document.querySelectorAll(".programming");
programmingProjects.forEach((programmingProject) => {
programmingProject.style.display = "block";
});
removeActive();
document.querySelector(".filter-programming").classList.add("active");
document.querySelector("#filter-marketing").checked = false;
document.querySelector("#filter-design").checked = false;
} else {
removeActive();
showAllProjects();
}
}
function filterDesign() {
hideAllProjects();
if (document.querySelector("#filter-design").checked) {
var designProjects = document.querySelectorAll(".design");
designProjects.forEach((designProject) => {
designProject.style.display = "block";
});
removeActive();
document.querySelector(".filter-design").classList.add("active");
document.querySelector("#filter-marketing").checked = false;
document.querySelector("#filter-programming").checked = false;
} else {
removeActive();
showAllProjects();
}
}