auto-open the saved open section

This commit is contained in:
Zvonimir Rudinski
2024-07-07 05:01:33 +02:00
parent d88e152ba6
commit da8202208d
2 changed files with 18 additions and 0 deletions

View File

@@ -71,11 +71,13 @@ const { title, hasBorder } = Astro.props;
extend(section: Element, container: HTMLElement) { extend(section: Element, container: HTMLElement) {
container.style.maxHeight = "1000vh"; container.style.maxHeight = "1000vh";
section.classList.add("open"); section.classList.add("open");
sessionStorage.setItem("openSection", this.id);
} }
collapse(section: Element, container: HTMLElement) { collapse(section: Element, container: HTMLElement) {
container.style.maxHeight = "0"; container.style.maxHeight = "0";
section.classList.remove("open"); section.classList.remove("open");
sessionStorage.removeItem("openSection");
} }
} }

View File

@@ -111,5 +111,21 @@ import { projects } from "../projects";
<footer class="mt-12"> <footer class="mt-12">
<p class="text-secondary text-center">&copy; 2024 Zvonimir Rudinski</p> <p class="text-secondary text-center">&copy; 2024 Zvonimir Rudinski</p>
</footer> </footer>
<script>
function onMount() {
const openSection = sessionStorage.getItem("openSection");
if (!openSection) return;
const section = document.querySelector<HTMLElement>(
`#${openSection} > abbr > h2`
);
if (!section) return;
section.click();
}
window.addEventListener("DOMContentLoaded", onMount);
</script>
</body> </body>
</html> </html>