mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 12:09:26 +00:00
* 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>
27 lines
830 B
JavaScript
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);
|
|
}
|
|
});
|