-
Notifications
You must be signed in to change notification settings - Fork 10
/
filter.js
38 lines (32 loc) · 1.11 KB
/
filter.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
const assetSections = document.getElementsByClassName('asset-section')
let assets = []
for (let i = 0; i < assetSections.length; i++) {
assets.push(assetSections[i])
}
let typeSelection = 'all'
let dateSelection = '2023'
const typeRadio = document.getElementsByName('type')
for (let i = 0; i < typeRadio.length; i++) {
typeRadio[i].onchange = () => { updateFilter(typeRadio[i].value) }
}
const dateRadio = document.getElementsByName('date')
for (let i = 0; i < dateRadio.length; i++) {
dateRadio[i].onchange = () => { updateFilter(undefined, dateRadio[i].value) }
}
const updateFilter = (type = typeSelection, date = dateSelection) => {
typeSelection = type
dateSelection = date
assets.forEach(asset => {
if (typeSelection === 'all' || asset.dataset.type === typeSelection) {
// We want to make sure that assets without a year are let through
if (asset.dataset.year === dateSelection || asset.dataset.type === 'league') {
asset.classList.add('show')
} else {
asset.classList.remove('show')
}
} else {
asset.classList.remove('show')
}
})
}
updateFilter()