forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-toc.js
More file actions
23 lines (19 loc) · 720 Bytes
/
dev-toc.js
File metadata and controls
23 lines (19 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
}
})
}