auto-open the saved open section
This commit is contained in:
@@ -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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,5 +111,21 @@ import { projects } from "../projects";
|
|||||||
<footer class="mt-12">
|
<footer class="mt-12">
|
||||||
<p class="text-secondary text-center">© 2024 Zvonimir Rudinski</p>
|
<p class="text-secondary text-center">© 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>
|
||||||
|
|||||||
Reference in New Issue
Block a user