mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +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
|
// 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
|
// doesn't fire in case of pushState, so we have to do the same thing
|
||||||
// here, too
|
// here, too
|
||||||
state.contentScrollTop = elc.scrollTop;
|
state.contentScrollTop = +elc.scrollTop;
|
||||||
window.history.pushState( state, '', url );
|
window.history.pushState( state, '', url );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,9 +239,9 @@ function searchDetail( value ) {
|
||||||
// by a browser history operation, it simply does nothing
|
// by a browser history operation, it simply does nothing
|
||||||
var state = window.history.state || {};
|
var state = window.history.state || {};
|
||||||
state = Object.assign( {}, ( typeof state === 'object' ) ? state : {} );
|
state = Object.assign( {}, ( typeof state === 'object' ) ? state : {} );
|
||||||
if( state.contentScrollTop ){
|
if( state.hasOwnProperty( 'contentScrollTop' ) ){
|
||||||
window.setTimeout( function(){
|
window.setTimeout( function(){
|
||||||
elc.scrollTop = state.contentScrollTop;
|
elc.scrollTop = +state.contentScrollTop;
|
||||||
}, 10 );
|
}, 10 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -819,7 +819,7 @@ function initScrollPositionSaver(){
|
||||||
function savePosition( event ){
|
function savePosition( event ){
|
||||||
var state = window.history.state || {};
|
var state = window.history.state || {};
|
||||||
state = Object.assign( {}, ( typeof state === 'object' ) ? state : {} );
|
state = Object.assign( {}, ( typeof state === 'object' ) ? state : {} );
|
||||||
state.contentScrollTop = elc.scrollTop;
|
state.contentScrollTop = +elc.scrollTop;
|
||||||
window.history.replaceState( state, '', window.location );
|
window.history.replaceState( state, '', window.location );
|
||||||
};
|
};
|
||||||
window.addEventListener( 'pagehide', savePosition );
|
window.addEventListener( 'pagehide', savePosition );
|
||||||
|
@ -846,15 +846,16 @@ function scrollToPositions() {
|
||||||
|
|
||||||
var state = window.history.state || {};
|
var state = window.history.state || {};
|
||||||
state = ( typeof state === 'object') ? state : {};
|
state = ( typeof state === 'object') ? state : {};
|
||||||
if( state.contentScrollTop !== undefined ){
|
if( state.hasOwnProperty( 'contentScrollTop' ) ){
|
||||||
window.setTimeout( function(){
|
window.setTimeout( function(){
|
||||||
elc.scrollTop = state.contentScrollTop;
|
elc.scrollTop = +state.contentScrollTop;
|
||||||
}, 10 );
|
}, 10 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var searchValue = sessionStorage.getItem( baseUriFull+'search-value' );
|
var search = sessionStorage.getItem( baseUriFull+'search-value' );
|
||||||
var found = elementContains( searchValue, elc );
|
if( search && search.length ){
|
||||||
|
var found = elementContains( search, elc );
|
||||||
var searchedElem = found.length && found[ 0 ];
|
var searchedElem = found.length && found[ 0 ];
|
||||||
if( searchedElem ){
|
if( searchedElem ){
|
||||||
searchedElem.scrollIntoView( true );
|
searchedElem.scrollIntoView( true );
|
||||||
|
@ -862,6 +863,7 @@ function scrollToPositions() {
|
||||||
if( scrolledY ){
|
if( scrolledY ){
|
||||||
window.scroll( 0, scrolledY - 125 );
|
window.scroll( 0, scrolledY - 125 );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue