1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/javascripts/dev-toc.ts
Kevin Heis 75f90c9487 Update current JavaScripts to use Typescript (#19824)
* Update index to make it clear what has hasn't updated to Next/React yet

* Typescriptify events and experiments

* Typescript the old JS for easier integration

* Update release-notes.ts

* Lint

* Run npm i

* Fix a few lint issues

* Update airgap-links.ts

* Update airgap-links.ts

* Update set-next-env to ts

* Update airgap-links.ts

* Update package-lock.json

* Update set-next-env.ts

* Update package-lock.json

* Revert "Update package-lock.json"

This reverts commit b45e8250beeb700719d3b44e1092b0bbd093baba.

* readd fsevents

* Revert "readd fsevents"

This reverts commit 419f3c35080ac4a9072f0b4e8e291e1712ce3639.

* Update openapi-schema-check.yml

* Revert "Update openapi-schema-check.yml"

This reverts commit 5e9f4a29ea11ee343ca17291a40a751920c5b923.

* Update package-lock.json

* Update package-lock.json
2021-06-14 18:07:39 +00:00

38 lines
1.2 KiB
TypeScript

const expandText = 'Expand All'
const closeText = 'Close All'
export default function devToc() {
const expandButton = document.querySelector('.js-expand')
if (!expandButton) return
const detailsElements = document.querySelectorAll('details')
expandButton.addEventListener('click', () => {
// on click, toggle all the details elements open or closed
const anyDetailsOpen = Array.from(detailsElements).find((details) => details.open)
detailsElements.forEach((detailsElement) => {
anyDetailsOpen ? detailsElement.removeAttribute('open') : (detailsElement.open = true)
})
// toggle the button text on click
anyDetailsOpen
? (expandButton.textContent = expandText)
: (expandButton.textContent = closeText)
})
// also toggle the button text on clicking any of the details elements
detailsElements.forEach((detailsElement) => {
detailsElement.addEventListener('click', () => {
expandButton.textContent = closeText
// we can only get an accurate count of the open details elements if we wait a fraction after click
setTimeout(() => {
if (!Array.from(detailsElements).find((details) => details.open)) {
expandButton.textContent = expandText
}
}, 50)
})
})
}