File tree Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -38,9 +38,31 @@ const state = {
38
38
*/
39
39
export function initialize ( ) {
40
40
setDefaultSidebarState ( )
41
+ observeResizing ( )
41
42
addEventListeners ( )
42
43
}
43
44
45
+ function observeResizing ( ) {
46
+ const sidebarWidth = sessionStorage . getItem ( 'sidebar_width' )
47
+
48
+ if ( sidebarWidth ) {
49
+ setSidebarWidth ( sidebarWidth )
50
+ }
51
+
52
+ const resizeObserver = new ResizeObserver ( ( entries ) => {
53
+ for ( const entry of entries ) {
54
+ setSidebarWidth ( entry . contentRect . width ) ;
55
+ }
56
+ } ) ;
57
+
58
+ resizeObserver . observe ( document . getElementById ( 'sidebar' ) ) ;
59
+ }
60
+
61
+ function setSidebarWidth ( width ) {
62
+ sessionStorage . setItem ( 'sidebar_width' , width )
63
+ document . body . style . setProperty ( '--sidebarWidth' , `${ width } px` ) ;
64
+ }
65
+
44
66
function setDefaultSidebarState ( ) {
45
67
// check & set persistent session state
46
68
const persistentSessionState = sessionStorage . getItem ( 'sidebar_state' )
@@ -204,11 +226,3 @@ function setPreference () {
204
226
: ( state . sidebarPreference = userPref . CLOSED )
205
227
}
206
228
}
207
-
208
- const resizeObserver = new ResizeObserver ( ( entries ) => {
209
- for ( const entry of entries ) {
210
- document . body . style . setProperty ( '--sidebarWidth' , `${ entry . contentRect . width } px` ) ;
211
- }
212
- } ) ;
213
-
214
- resizeObserver . observe ( document . getElementById ( 'sidebar' ) ) ;
You can’t perform that action at this time.
0 commit comments