feat: chart toggles
This commit is contained in:
parent
daf958c845
commit
f5036cbdf3
10 changed files with 153 additions and 40 deletions
30
src/assets/scripts/media-toggles.js
Normal file
30
src/assets/scripts/media-toggles.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
window.onload = () => {
|
||||
const initializeButtonSet = (buttonSet) => {
|
||||
const buttons = buttonSet.querySelectorAll('button')
|
||||
const buttonIds = Array.from(buttons).map(button => button.getAttribute('data-toggle'))
|
||||
|
||||
buttons.forEach(button => {
|
||||
button.addEventListener('click', function () {
|
||||
const targetId = this.getAttribute('data-toggle')
|
||||
const targetContent = document.getElementById(targetId)
|
||||
|
||||
buttons.forEach(btn => {
|
||||
btn.classList.remove('active')
|
||||
btn.classList.add('secondary')
|
||||
})
|
||||
|
||||
buttonIds.forEach(id => {
|
||||
document.getElementById(id).classList.add('hidden')
|
||||
})
|
||||
|
||||
this.classList.remove('secondary')
|
||||
this.classList.add('active')
|
||||
|
||||
targetContent.classList.remove('hidden')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const buttonSets = document.querySelectorAll('.now__section--header-buttons')
|
||||
buttonSets.forEach(initializeButtonSet)
|
||||
}
|
Reference in a new issue