mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
nav: fix initial positioning on content pages #476
This commit is contained in:
parent
a40e3685d4
commit
09e7aebcd8
2 changed files with 16 additions and 14 deletions
|
@ -65,7 +65,7 @@ function triggerSearch(){
|
|||
// with normal pages, this is handled by the 'pagehide' event, but this
|
||||
// doesn't fire in case of pushState, so we have to do the same thing
|
||||
// here, too
|
||||
state.contentScrollTop = elc.scrollTop;
|
||||
state.contentScrollTop = +elc.scrollTop;
|
||||
window.history.pushState( state, '', url );
|
||||
}
|
||||
}
|
||||
|
@ -239,9 +239,9 @@ function searchDetail( value ) {
|
|||
// by a browser history operation, it simply does nothing
|
||||
var state = window.history.state || {};
|
||||
state = Object.assign( {}, ( typeof state === 'object' ) ? state : {} );
|
||||
if( state.contentScrollTop ){
|
||||
if( state.hasOwnProperty( 'contentScrollTop' ) ){
|
||||
window.setTimeout( function(){
|
||||
elc.scrollTop = state.contentScrollTop;
|
||||
elc.scrollTop = +state.contentScrollTop;
|
||||
}, 10 );
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -819,7 +819,7 @@ function initScrollPositionSaver(){
|
|||
function savePosition( event ){
|
||||
var state = window.history.state || {};
|
||||
state = Object.assign( {}, ( typeof state === 'object' ) ? state : {} );
|
||||
state.contentScrollTop = elc.scrollTop;
|
||||
state.contentScrollTop = +elc.scrollTop;
|
||||
window.history.replaceState( state, '', window.location );
|
||||
};
|
||||
window.addEventListener( 'pagehide', savePosition );
|
||||
|
@ -846,21 +846,23 @@ function scrollToPositions() {
|
|||
|
||||
var state = window.history.state || {};
|
||||
state = ( typeof state === 'object') ? state : {};
|
||||
if( state.contentScrollTop !== undefined ){
|
||||
if( state.hasOwnProperty( 'contentScrollTop' ) ){
|
||||
window.setTimeout( function(){
|
||||
elc.scrollTop = state.contentScrollTop;
|
||||
elc.scrollTop = +state.contentScrollTop;
|
||||
}, 10 );
|
||||
return;
|
||||
}
|
||||
|
||||
var searchValue = sessionStorage.getItem( baseUriFull+'search-value' );
|
||||
var found = elementContains( searchValue, elc );
|
||||
var searchedElem = found.length && found[ 0 ];
|
||||
if( searchedElem ){
|
||||
searchedElem.scrollIntoView( true );
|
||||
var scrolledY = window.scrollY;
|
||||
if( scrolledY ){
|
||||
window.scroll( 0, scrolledY - 125 );
|
||||
var search = sessionStorage.getItem( baseUriFull+'search-value' );
|
||||
if( search && search.length ){
|
||||
var found = elementContains( search, elc );
|
||||
var searchedElem = found.length && found[ 0 ];
|
||||
if( searchedElem ){
|
||||
searchedElem.scrollIntoView( true );
|
||||
var scrolledY = window.scrollY;
|
||||
if( scrolledY ){
|
||||
window.scroll( 0, scrolledY - 125 );
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue