website/_src/assets/js/nav-details.js

26 lines
768 B
JavaScript
Raw Normal View History

2025-06-11 09:36:54 +03:00
const detailsElements = document.getElementsByTagName('details');
2025-06-25 13:08:50 +03:00
const dropdown = Array.from(detailsElements);
2025-06-16 16:31:53 +03:00
2025-06-11 09:36:54 +03:00
const save = () => {
2025-06-25 13:08:50 +03:00
dropdown.forEach((details, i) => {
2025-06-11 09:36:54 +03:00
localStorage.setItem(`details${i}`, details.hasAttribute('open'));
});
};
2025-06-16 16:31:53 +03:00
2025-06-25 13:08:50 +03:00
dropdown.forEach((details, i) => {
2025-06-16 16:31:53 +03:00
const isOpen = JSON.parse(localStorage.getItem(`details${i}`)) || false;
details.toggleAttribute('open', isOpen);
2025-06-11 09:36:54 +03:00
details.addEventListener('toggle', save);
2025-06-16 16:31:53 +03:00
const svg = details.querySelector('summary svg');
if (svg) {
svg.style.transition = isOpen ? 'none' : '';
}
});
setTimeout(() => {
2025-06-25 13:08:50 +03:00
dropdown.forEach(details => {
2025-06-16 16:31:53 +03:00
const svg = details.querySelector('summary svg');
if (svg) svg.style.transition = '';
});
}, 100);