Save sidebar state in local storage
So it stays the way I set it.
This commit is contained in:
parent
9d2eee882a
commit
0e4ce01776
1 changed files with 18 additions and 1 deletions
|
|
@ -12,6 +12,17 @@
|
|||
<link rel="icon" href="/static/favicon-sync.ico" type="image/x-icon" />
|
||||
{{ block "extraheader" . }}{{ end }}
|
||||
<script>
|
||||
function restoreLocalStorage() {
|
||||
const expanded = localStorage.getItem("sidebar.expanded");
|
||||
if (expanded == "false") {
|
||||
document.getElementById("sidebar").classList.add("collapsed");
|
||||
document.getElementById("content").classList.add("expanded");
|
||||
} else {
|
||||
document.getElementById("sidebar").classList.remove("collapsed");
|
||||
document.getElementById("content").classList.remove("expanded");
|
||||
localStorage.setItem("sidebar.expanded", "true");
|
||||
}
|
||||
}
|
||||
function setTooltipsForSidebar() {
|
||||
const sidebarTooltips = document.querySelectorAll(
|
||||
'#sidebar [data-bs-toggle="tooltip"]',
|
||||
|
|
@ -45,6 +56,7 @@
|
|||
return t;
|
||||
});
|
||||
console.log("Initialized ", tooltipTriggerList.length, " tooltips");
|
||||
restoreLocalStorage();
|
||||
setTooltipsForSidebar();
|
||||
});
|
||||
</script>
|
||||
|
|
@ -67,9 +79,14 @@
|
|||
<script src="/static/vendor/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
document.getElementById("sidebarToggle").addEventListener("click", () => {
|
||||
document.getElementById("sidebar").classList.toggle("collapsed");
|
||||
const sidebar = document.getElementById("sidebar");
|
||||
sidebar.classList.toggle("collapsed");
|
||||
document.getElementById("content").classList.toggle("expanded");
|
||||
setTooltipsForSidebar();
|
||||
localStorage.setItem(
|
||||
"sidebar.expanded",
|
||||
(!sidebar.classList.contains("collapsed")).toString(),
|
||||
);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue