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 = {
3838 */
3939export function initialize ( ) {
4040 setDefaultSidebarState ( )
41+ observeResizing ( )
4142 addEventListeners ( )
4243}
4344
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+
4466function setDefaultSidebarState ( ) {
4567 // check & set persistent session state
4668 const persistentSessionState = sessionStorage . getItem ( 'sidebar_state' )
@@ -204,11 +226,3 @@ function setPreference () {
204226 : ( state . sidebarPreference = userPref . CLOSED )
205227 }
206228}
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