|
@@ -37,12 +37,16 @@ const SELECTOR_APP_WRAPPER = '.app-wrapper'
|
|
|
const SELECTOR_SIDEBAR_EXPAND = `[class*="${CLASS_NAME_SIDEBAR_EXPAND}"]`
|
|
const SELECTOR_SIDEBAR_EXPAND = `[class*="${CLASS_NAME_SIDEBAR_EXPAND}"]`
|
|
|
const SELECTOR_SIDEBAR_TOGGLE = '[data-lte-toggle="sidebar"]'
|
|
const SELECTOR_SIDEBAR_TOGGLE = '[data-lte-toggle="sidebar"]'
|
|
|
|
|
|
|
|
|
|
+const STORAGE_KEY_SIDEBAR_STATE = 'lte.sidebar.state'
|
|
|
|
|
+
|
|
|
type Config = {
|
|
type Config = {
|
|
|
sidebarBreakpoint: number;
|
|
sidebarBreakpoint: number;
|
|
|
|
|
+ enablePersistence: boolean;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const Defaults = {
|
|
|
|
|
- sidebarBreakpoint: 992
|
|
|
|
|
|
|
+const Defaults: Config = {
|
|
|
|
|
+ sidebarBreakpoint: 992,
|
|
|
|
|
+ enablePersistence: true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -128,10 +132,69 @@ class PushMenu {
|
|
|
} else {
|
|
} else {
|
|
|
this.collapse()
|
|
this.collapse()
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ this.saveSidebarState()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Save sidebar state to localStorage
|
|
|
|
|
+ */
|
|
|
|
|
+ saveSidebarState(): void {
|
|
|
|
|
+ if (!this._config.enablePersistence) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Check for SSR environment
|
|
|
|
|
+ if (typeof window === 'undefined' || typeof localStorage === 'undefined') {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const state = document.body.classList.contains(CLASS_NAME_SIDEBAR_COLLAPSE)
|
|
|
|
|
+ ? CLASS_NAME_SIDEBAR_COLLAPSE
|
|
|
|
|
+ : CLASS_NAME_SIDEBAR_OPEN
|
|
|
|
|
+ localStorage.setItem(STORAGE_KEY_SIDEBAR_STATE, state)
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ // localStorage may be unavailable (private browsing, quota exceeded, etc.)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Load sidebar state from localStorage
|
|
|
|
|
+ * Only applies on desktop; mobile always starts collapsed
|
|
|
|
|
+ */
|
|
|
|
|
+ loadSidebarState(): void {
|
|
|
|
|
+ if (!this._config.enablePersistence) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Check for SSR environment
|
|
|
|
|
+ if (typeof window === 'undefined' || typeof localStorage === 'undefined') {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Don't restore state on mobile - let responsive behavior handle it
|
|
|
|
|
+ if (window.innerWidth <= this._config.sidebarBreakpoint) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const storedState = localStorage.getItem(STORAGE_KEY_SIDEBAR_STATE)
|
|
|
|
|
+
|
|
|
|
|
+ if (storedState === CLASS_NAME_SIDEBAR_COLLAPSE) {
|
|
|
|
|
+ this.collapse()
|
|
|
|
|
+ } else if (storedState === CLASS_NAME_SIDEBAR_OPEN) {
|
|
|
|
|
+ this.expand()
|
|
|
|
|
+ }
|
|
|
|
|
+ // If null (never saved), let default behavior apply
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ // localStorage may be unavailable
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
init() {
|
|
|
this.addSidebarBreakPoint()
|
|
this.addSidebarBreakPoint()
|
|
|
|
|
+ this.loadSidebarState()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|