Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions assets/layout/admin-shell.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
const STORAGE_KEY = 'sfs-components:admin-sidebar-collapsed';
const COLLAPSED_CLASS = 'sfs-admin-sidebar-collapsed';

function getClassTargets() {
return [document.documentElement, document.body].filter(Boolean);
}

function setCollapsed(collapsed) {
document.body.classList.toggle(COLLAPSED_CLASS, collapsed);
getClassTargets().forEach((target) => {
target.classList.toggle(COLLAPSED_CLASS, collapsed);
});
}

function isDesktop() {
return window.matchMedia('(min-width: 992px)').matches;
}

function readStoredState() {
return window.localStorage.getItem(STORAGE_KEY) === '1';
try {
return window.localStorage.getItem(STORAGE_KEY) === '1';
} catch (error) {
return false;
}
}

function writeStoredState(collapsed) {
window.localStorage.setItem(STORAGE_KEY, collapsed ? '1' : '0');
try {
window.localStorage.setItem(STORAGE_KEY, collapsed ? '1' : '0');
} catch (error) {

Check failure on line 29 in assets/layout/admin-shell.js

View workflow job for this annotation

GitHub Actions / frontend (20, 10)

Empty block statement
}
}

function syncState() {
if (!isDesktop()) {
document.body.classList.remove(COLLAPSED_CLASS);
setCollapsed(false);
return;
}

Expand All @@ -31,12 +44,21 @@
return;
}

const collapsed = !document.body.classList.contains(COLLAPSED_CLASS);
const collapsed = !document.documentElement.classList.contains(COLLAPSED_CLASS);
setCollapsed(collapsed);
writeStoredState(collapsed);
}

syncState();

function initSidebarToggles() {
if (window.sfsAdminSidebarInitialized) {
syncState();
return;
}

window.sfsAdminSidebarInitialized = true;

document.querySelectorAll('[data-sfs-admin-sidebar-toggle="desktop"]').forEach((button) => {
if (button.dataset.sfsAdminSidebarBound === '1') {
return;
Expand Down
16 changes: 16 additions & 0 deletions templates/layout/admin.bootstrap5.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
{% endblock %}

{% block body_begin %}
<script>
(function () {
try {
if (
window.matchMedia('(min-width: 992px)').matches
&& window.localStorage.getItem('sfs-components:admin-sidebar-collapsed') === '1'
) {
document.body.classList.add('sfs-admin-sidebar-collapsed');
}
} catch (error) {
}
})();
</script>
{% endblock body_begin %}

{% block body %}
<div class="sfs-admin-shell d-flex vh-100 overflow-hidden">
<aside id="sfs-admin-sidebar" class="sfs-admin-sidebar offcanvas-lg offcanvas-start border-end flex-shrink-0 h-100" tabindex="-1" aria-labelledby="sfs-admin-sidebar-title">
Expand Down
Loading