Skip to content

Commit e449336

Browse files
committed
Implemented localStorage Key
1 parent 354577f commit e449336

File tree

9 files changed

+183
-10
lines changed

9 files changed

+183
-10
lines changed

dist/js/adminlte.js

Lines changed: 56 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/adminlte.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/adminlte.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/adminlte.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/html/public/js/adminlte.js

Lines changed: 56 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/html/public/js/adminlte.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/html/public/js/adminlte.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/html/public/js/adminlte.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ts/push-menu.ts

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ const SELECTOR_APP_WRAPPER = '.app-wrapper'
3737
const SELECTOR_SIDEBAR_EXPAND = `[class*="${CLASS_NAME_SIDEBAR_EXPAND}"]`
3838
const SELECTOR_SIDEBAR_TOGGLE = '[data-lte-toggle="sidebar"]'
3939

40+
const STORAGE_KEY_SIDEBAR_STATE = 'lte.sidebar.state'
41+
4042
type Config = {
4143
sidebarBreakpoint: number;
44+
enablePersistence: boolean;
4245
}
4346

44-
const Defaults = {
45-
sidebarBreakpoint: 992
47+
const Defaults: Config = {
48+
sidebarBreakpoint: 992,
49+
enablePersistence: true
4650
}
4751

4852
/**
@@ -128,10 +132,69 @@ class PushMenu {
128132
} else {
129133
this.collapse()
130134
}
135+
136+
this.saveSidebarState()
137+
}
138+
139+
/**
140+
* Save sidebar state to localStorage
141+
*/
142+
saveSidebarState(): void {
143+
if (!this._config.enablePersistence) {
144+
return
145+
}
146+
147+
// Check for SSR environment
148+
if (typeof window === 'undefined' || typeof localStorage === 'undefined') {
149+
return
150+
}
151+
152+
try {
153+
const state = document.body.classList.contains(CLASS_NAME_SIDEBAR_COLLAPSE)
154+
? CLASS_NAME_SIDEBAR_COLLAPSE
155+
: CLASS_NAME_SIDEBAR_OPEN
156+
localStorage.setItem(STORAGE_KEY_SIDEBAR_STATE, state)
157+
} catch {
158+
// localStorage may be unavailable (private browsing, quota exceeded, etc.)
159+
}
160+
}
161+
162+
/**
163+
* Load sidebar state from localStorage
164+
* Only applies on desktop; mobile always starts collapsed
165+
*/
166+
loadSidebarState(): void {
167+
if (!this._config.enablePersistence) {
168+
return
169+
}
170+
171+
// Check for SSR environment
172+
if (typeof window === 'undefined' || typeof localStorage === 'undefined') {
173+
return
174+
}
175+
176+
// Don't restore state on mobile - let responsive behavior handle it
177+
if (window.innerWidth <= this._config.sidebarBreakpoint) {
178+
return
179+
}
180+
181+
try {
182+
const storedState = localStorage.getItem(STORAGE_KEY_SIDEBAR_STATE)
183+
184+
if (storedState === CLASS_NAME_SIDEBAR_COLLAPSE) {
185+
this.collapse()
186+
} else if (storedState === CLASS_NAME_SIDEBAR_OPEN) {
187+
this.expand()
188+
}
189+
// If null (never saved), let default behavior apply
190+
} catch {
191+
// localStorage may be unavailable
192+
}
131193
}
132194

133195
init() {
134196
this.addSidebarBreakPoint()
197+
this.loadSidebarState()
135198
}
136199
}
137200

0 commit comments

Comments
 (0)