forked from ShimilSAbraham/Hacktoberfest-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
65 lines (52 loc) · 1.85 KB
/
main.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
let members = document.querySelectorAll(".team .card-container .card"); // so store all the cards
let num = document.querySelector(".team .title .num"); // number of contributors div
num.textContent = members.length;
// add all the contributor's name in the names array
let names = [];
for (let i = 0; i < members.length; i++) {
let name = members[i].querySelector(".name").textContent;
names.push(name);
}
// searches for the name with the search value, which gets added to the result array
function looking(name, searchkey) {
searchkey = searchkey.toLowerCase();
name = name.toLowerCase();
//search returns -1 in case the string is not found
if(name.search(searchkey) >= 0)
return name;
}
let result = []; // holds the filtered names after search
const search_input = document.getElementById("search");
let searchValue = "";
search_input.addEventListener("input", (e) => {
// saving the input value
searchValue = e.target.value;
showCards();
});
// figures out which card should be displayed while searching
const showCards = async () => {
// clear the results
result = [];
//updates the result array
for (let i = 0; i < names.length; i++) {
let name = names[i];
if(looking(name, searchValue))
result.push(name);
}
// goes through each card to check if it should be display or not
members.forEach((member) => {
let name = member.querySelector(".name").textContent;
if(result.includes(name))
member.style.display = "flex";
else
member.style.display = "none";
});
};
// Scrolling on menu item's click
let page = document.querySelectorAll(".page");
let item = document.querySelectorAll(".landing .menu .items");
for (let i = 0; i < item.length; i++) {
item[i].addEventListener("click", function () {
page[i].scrollIntoView();
});
}