1
0
mirror of synced 2025-12-22 03:16:52 -05:00
Files
docs/javascripts/dev-toc.js
Sarah Schneider 9143e5d413 lint
2020-11-16 16:21:28 -05:00

24 lines
720 B
JavaScript

const expandText = 'Expand All'
const closeText = 'Close All'
export default function devToc () {
const expandButton = document.querySelector('.js-expand')
if (!expandButton) return
expandButton.addEventListener('click', () => {
// on click, toggle the button text
expandButton.textContent === expandText
? expandButton.textContent = closeText
: expandButton.textContent = expandText
// on click, toggle all the details elements open or closed
const detailsElements = document.querySelectorAll('details')
for (const detailsElement of detailsElements) {
detailsElement.open
? detailsElement.removeAttribute('open')
: detailsElement.open = true
}
})
}