Skip to content

Commit

Permalink
Store resizing in session
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 10, 2024
1 parent dade0f6 commit 7964edf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
30 changes: 22 additions & 8 deletions assets/js/sidebar/sidebar-drawer.js
Expand Up @@ -38,9 +38,31 @@ const state = {
*/
export function initialize () {
setDefaultSidebarState()
observeResizing()
addEventListeners()
}

function observeResizing() {

Check failure on line 45 in assets/js/sidebar/sidebar-drawer.js

View workflow job for this annotation

GitHub Actions / Check JS

Missing space before function parentheses
const sidebarWidth = sessionStorage.getItem('sidebar_width')

if(sidebarWidth) {

Check failure on line 48 in assets/js/sidebar/sidebar-drawer.js

View workflow job for this annotation

GitHub Actions / Check JS

Expected space(s) after "if"
setSidebarWidth(sidebarWidth)
}

const resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
setSidebarWidth(entry.contentRect.width);

Check failure on line 54 in assets/js/sidebar/sidebar-drawer.js

View workflow job for this annotation

GitHub Actions / Check JS

Extra semicolon
}
});

Check failure on line 56 in assets/js/sidebar/sidebar-drawer.js

View workflow job for this annotation

GitHub Actions / Check JS

Extra semicolon

resizeObserver.observe(document.getElementById('sidebar'));

Check failure on line 58 in assets/js/sidebar/sidebar-drawer.js

View workflow job for this annotation

GitHub Actions / Check JS

Extra semicolon
}

function setSidebarWidth(width) {

Check failure on line 61 in assets/js/sidebar/sidebar-drawer.js

View workflow job for this annotation

GitHub Actions / Check JS

Missing space before function parentheses
sessionStorage.setItem('sidebar_width', width)
document.body.style.setProperty('--sidebarWidth', `${width}px`);

Check failure on line 63 in assets/js/sidebar/sidebar-drawer.js

View workflow job for this annotation

GitHub Actions / Check JS

Extra semicolon
}

function setDefaultSidebarState () {
// check & set persistent session state
const persistentSessionState = sessionStorage.getItem('sidebar_state')
Expand Down Expand Up @@ -204,11 +226,3 @@ function setPreference () {
: (state.sidebarPreference = userPref.CLOSED)
}
}

const resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
document.body.style.setProperty('--sidebarWidth', `${entry.contentRect.width}px`);
}
});

resizeObserver.observe(document.getElementById('sidebar'));

Large diffs are not rendered by default.

0 comments on commit 7964edf

Please sign in to comment.