diff options
Diffstat (limited to 'vendor/mdbook/src/theme/index.hbs')
-rw-r--r-- | vendor/mdbook/src/theme/index.hbs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/vendor/mdbook/src/theme/index.hbs b/vendor/mdbook/src/theme/index.hbs index 6f3948c65..80315c48f 100644 --- a/vendor/mdbook/src/theme/index.hbs +++ b/vendor/mdbook/src/theme/index.hbs @@ -110,12 +110,34 @@ <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div> </nav> + <!-- Track and set sidebar scroll position --> + <script> + var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox'); + sidebarScrollbox.addEventListener('click', function(e) { + if (e.target.tagName === 'A') { + sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop); + } + }, { passive: true }); + var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll'); + sessionStorage.removeItem('sidebar-scroll'); + if (sidebarScrollTop) { + // preserve sidebar scroll position when navigating via links within sidebar + sidebarScrollbox.scrollTop = sidebarScrollTop; + } else { + // scroll sidebar to current active section when navigating via "next/previous chapter" buttons + var activeSection = document.querySelector('#sidebar .active'); + if (activeSection) { + activeSection.scrollIntoView({ block: 'center' }); + } + } + </script> + <div id="page-wrapper" class="page-wrapper"> <div class="page"> {{> header}} <div id="menu-bar-hover-placeholder"></div> - <div id="menu-bar" class="menu-bar sticky bordered"> + <div id="menu-bar" class="menu-bar sticky"> <div class="left-buttons"> <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar"> <i class="fa fa-bars"></i> |