Fixes #8633: Recheck sidenav state on window resize

* Recheck sidenav state on window resize
* Remove `data-sidenav-pinned` attribute when hiding sidenav
* Remove `data-sidenav-hidden` attribute when showing sidenav
This commit is contained in:
thatmattlove 2022-02-25 11:14:43 -07:00
parent 6fe0f4cd7d
commit c88db77814

View File

@ -139,7 +139,7 @@
<body> <body>
<script type="text/javascript"> <script type="text/javascript">
(function() { function checkSideNav() {
// Check localStorage to see if the sidebar should be pinned. // Check localStorage to see if the sidebar should be pinned.
var sideNavRaw = localStorage.getItem('netbox-sidenav'); var sideNavRaw = localStorage.getItem('netbox-sidenav');
// Determine if the device has a small screeen. This media query is equivalent to // Determine if the device has a small screeen. This media query is equivalent to
@ -154,11 +154,15 @@
// jumpy/glitchy behavior on page reloads. // jumpy/glitchy behavior on page reloads.
document.body.setAttribute('data-sidenav-pinned', ''); document.body.setAttribute('data-sidenav-pinned', '');
document.body.setAttribute('data-sidenav-show', ''); document.body.setAttribute('data-sidenav-show', '');
document.body.removeAttribute('data-sidenav-hidden');
} else { } else {
document.body.removeAttribute('data-sidenav-pinned');
document.body.setAttribute('data-sidenav-hidden', ''); document.body.setAttribute('data-sidenav-hidden', '');
} }
} }
})(); }
window.addEventListener('resize', function(){ checkSideNav() });
checkSideNav();
</script> </script>
{# Page layout #} {# Page layout #}