-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
133 lines (116 loc) · 4.51 KB
/
script.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// toggle nav menu open and closed
const primaryNav = document.getElementById('primary-navigation');
const navToggle = document.getElementById('nav-toggle');
navToggle.addEventListener('click', function () {
primaryNav.classList.toggle('active');
})
// toggles accordion menus open and closed on click
const accordionItemHeaders = document.querySelectorAll('.accordion-item-header');
accordionItemHeaders.forEach(accordionItemHeader => {
accordionItemHeader.addEventListener('click', function () {
accordionItemHeader.classList.toggle('active-accordion');
const accordionItemBody = accordionItemHeader.nextElementSibling;
if (accordionItemHeader.classList.contains('active-accordion')) {
accordionItemBody.style.maxHeight = accordionItemBody.scrollHeight + 'px';
}
else {
accordionItemBody.style.maxHeight = '0';
}
});
});
// get button elements
const seeAllBtn = document.getElementById('seeAllBtn');
const seeSunBtn = document.getElementById('seeSunBtn');
const seeShadeBtn = document.getElementById('seeShadeBtn');
const seeHumidBtn = document.getElementById('seeHumidBtn');
const seeEasyBtn = document.getElementById('seeEasyBtn');
// get array of buttons
const buttons = document.getElementsByClassName('btn-sort');
// get array of plant cards
const plantCards = document.getElementsByClassName('card');
// removes the hidden class from all elements upon click of 'see all'
seeAllBtn.addEventListener('click', function () {
for (i=0; i < buttons.length; i++) {
buttons[i].classList.remove('clicked');
}
seeAllBtn.classList.add('clicked');
for (i=0; i < plantCards.length; i++){
plantCards[i].classList.remove('hidden');
}
});
// sets all elements without the 'sun' class to hidden
seeSunBtn.addEventListener('click', function () {
for (i=0; i < buttons.length; i++) {
buttons[i].classList.remove('clicked');
}
seeSunBtn.classList.add('clicked');
for (i=0; i < plantCards.length; i++){
if (plantCards[i].classList.contains('sun')) {
if (plantCards[i].classList.contains('hidden')) {
plantCards[i].classList.remove('hidden');
}
}
if (plantCards[i].classList.contains('sun') == false) {
if (plantCards[i].classList.contains('hidden') == false) {
plantCards[i].classList.add('hidden');
}
}
}
});
// sets all elements without the 'shade' class to hidden
seeShadeBtn.addEventListener('click', function () {
for (i=0; i < buttons.length; i++) {
buttons[i].classList.remove('clicked');
}
seeShadeBtn.classList.add('clicked');
for (i=0; i < plantCards.length; i++){
if (plantCards[i].classList.contains('shade')) {
if (plantCards[i].classList.contains('hidden')) {
plantCards[i].classList.remove('hidden');
}
}
if (plantCards[i].classList.contains('shade') == false) {
if (plantCards[i].classList.contains('hidden') == false) {
plantCards[i].classList.add('hidden');
}
}
}
});
// sets all elements without the 'humid' class to hidden
seeHumidBtn.addEventListener('click', function () {
for (i=0; i < buttons.length; i++) {
buttons[i].classList.remove('clicked');
}
seeHumidBtn.classList.add('clicked');
for (i=0; i < plantCards.length; i++){
if (plantCards[i].classList.contains('humid')) {
if (plantCards[i].classList.contains('hidden')) {
plantCards[i].classList.remove('hidden');
}
}
if (plantCards[i].classList.contains('humid') == false) {
if (plantCards[i].classList.contains('hidden') == false) {
plantCards[i].classList.add('hidden');
}
}
}
});
// sets all elements without the 'easy' class to hidden
seeEasyBtn.addEventListener('click', function () {
for (i=0; i < buttons.length; i++) {
buttons[i].classList.remove('clicked');
}
seeEasyBtn.classList.add('clicked');
for (i=0; i < plantCards.length; i++){
if (plantCards[i].classList.contains('easy')) {
if (plantCards[i].classList.contains('hidden')) {
plantCards[i].classList.remove('hidden');
}
}
if (plantCards[i].classList.contains('easy') == false) {
if (plantCards[i].classList.contains('hidden') == false) {
plantCards[i].classList.add('hidden');
}
}
}
});