Files
webawesome/docs/assets/scripts/sidebar.js
Cory LaViska 23dc884678 Simplify sidebar (#989)
* remove test value

* remove animation to prevent page-to-page blips

* static sidebar

* manage open sections on page load and with turbo

* cleanup unused scripts

* Remove overlap between Style Utilities and Layout

---------

Co-authored-by: lindsaym-fa <dev@lindsaym.design>
2025-05-23 12:07:34 -04:00

27 lines
830 B
JavaScript

const sidebar = document.querySelector('#sidebar');
const allDetails = sidebar.querySelectorAll('wa-details');
const collapsibleSections = sidebar.querySelectorAll('h2 > a');
function ensureCurrentSectionIsOpen(root) {
const matchingDetails = root.querySelectorAll('wa-details:has(a.current)');
matchingDetails.forEach(details => {
details.setAttribute('open', '');
});
}
// Ensure current section is open on normal page load
window.addEventListener('DOMContentLoaded', () => {
ensureCurrentSectionIsOpen(sidebar);
});
// Ensure current section is open on Turbo page loads
document.addEventListener('turbo:before-render', event => {
if (!event?.detail?.newBody) return;
const newSidebar = event.detail.newBody.querySelector('#sidebar');
if (newSidebar) {
ensureCurrentSectionIsOpen(newSidebar);
}
});