nav: browser back navigation does not jump to the correct position #509

This commit is contained in:
Sören Weber 2024-03-16 01:14:42 +01:00
parent 1c3ef135f0
commit dc6524200d
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
2 changed files with 24 additions and 2 deletions

View file

@ -26,6 +26,8 @@ This document shows you what's new in the latest release and flags it with one o
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme has updated its Mermaid dependency to 10.6.0. This adds support for [block diagrams](shortcodes/mermaid#block-diagram). - {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme has updated its Mermaid dependency to 10.6.0. This adds support for [block diagrams](shortcodes/mermaid#block-diagram).
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} This release fixes a long outstanding bug where the page wasn't repositioning correctly when going forward or backward in your browser history.
--- ---
## 5.25.0 (2024-02-29) {#5250} ## 5.25.0 (2024-02-29) {#5250}

View file

@ -1167,7 +1167,19 @@ function initScrollPositionSaver(){
state.contentScrollTop = +elc.scrollTop; state.contentScrollTop = +elc.scrollTop;
window.history.replaceState( state, '', window.location ); window.history.replaceState( state, '', window.location );
}; };
window.addEventListener( 'pagehide', savePosition );
var ticking = false;
elc.addEventListener( 'scroll', function( event ){
if( !ticking ){
window.requestAnimationFrame( function(){
savePosition();
ticking = false;
});
ticking = true;
}
});
document.addEventListener( "click", savePosition );
} }
function scrollToPositions() { function scrollToPositions() {
@ -1228,6 +1240,15 @@ function scrollToPositions() {
} }
} }
window.addEventListener( 'popstate', function ( event ){
scrollToPositions();
});
const observer = new PerformanceObserver( function(){
scrollToPositions();
});
observer.observe({ type: "navigation" });
function mark() { function mark() {
// mark some additional stuff as searchable // mark some additional stuff as searchable
var bodyInnerLinks = document.querySelectorAll( '#R-body-inner a:not(.lightbox-link):not(.btn):not(.lightbox-back)' ); var bodyInnerLinks = document.querySelectorAll( '#R-body-inner a:not(.lightbox-link):not(.btn):not(.lightbox-back)' );
@ -1525,7 +1546,6 @@ ready( function(){
initImage(); initImage();
initExpand(); initExpand();
initScrollPositionSaver(); initScrollPositionSaver();
scrollToPositions();
}); });
(function(){ (function(){