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" />
|
<link rel="icon" href="/static/favicon-sync.ico" type="image/x-icon" />
|
||||||
{{ block "extraheader" . }}{{ end }}
|
{{ block "extraheader" . }}{{ end }}
|
||||||
<script>
|
<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() {
|
function setTooltipsForSidebar() {
|
||||||
const sidebarTooltips = document.querySelectorAll(
|
const sidebarTooltips = document.querySelectorAll(
|
||||||
'#sidebar [data-bs-toggle="tooltip"]',
|
'#sidebar [data-bs-toggle="tooltip"]',
|
||||||
|
|
@ -45,6 +56,7 @@
|
||||||
return t;
|
return t;
|
||||||
});
|
});
|
||||||
console.log("Initialized ", tooltipTriggerList.length, " tooltips");
|
console.log("Initialized ", tooltipTriggerList.length, " tooltips");
|
||||||
|
restoreLocalStorage();
|
||||||
setTooltipsForSidebar();
|
setTooltipsForSidebar();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -67,9 +79,14 @@
|
||||||
<script src="/static/vendor/js/bootstrap.bundle.min.js"></script>
|
<script src="/static/vendor/js/bootstrap.bundle.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
document.getElementById("sidebarToggle").addEventListener("click", () => {
|
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");
|
document.getElementById("content").classList.toggle("expanded");
|
||||||
setTooltipsForSidebar();
|
setTooltipsForSidebar();
|
||||||
|
localStorage.setItem(
|
||||||
|
"sidebar.expanded",
|
||||||
|
(!sidebar.classList.contains("collapsed")).toString(),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue