nav: fix left/right navigation for horizontal scrolling #435

This commit is contained in:
Sören Weber 2023-01-22 23:46:56 +01:00
parent 1ee561fd77
commit 05b31c174a
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D

View file

@ -369,14 +369,46 @@ function initArrowNav(){
});
// keyboard navigation
jQuery(document).keydown(function(e) {
if(!e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey){
if(e.which == '37') {
// avoid prev/next navigation if we are not at the start/end of the
// horizontal area
var el = document.querySelector('#body-inner');
var scrollLeft = 0;
var scrollRight = 0;
document.addEventListener('keydown', function(event){
if( !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey ){
if( event.which == '37' ){
if( !scrollLeft && el.scrollLeft <= 0 ){
jQuery('a.nav-prev').click();
}
if(e.which == '39') {
else if( scrollLeft != -1 ){
clearTimeout( scrollLeft );
}
scrollLeft = -1;
}
if( event.which == '39' ){
if( !scrollRight && el.scrollLeft + el.clientWidth >= el.scrollWidth ){
jQuery('a.nav-next').click();
}
else if( scrollRight != -1 ){
clearTimeout( scrollRight );
}
scrollRight = -1;
}
}
});
document.addEventListener('keyup', function(event){
if( !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey ){
if( event.which == '37' ){
// check for false indication if keyup is delayed after navigation
if( scrollLeft == -1 ){
scrollLeft = setTimeout( function(){ scrollLeft = 0; }, 300 );
}
}
if( event.which == '39' ){
if( scrollRight == -1 ){
scrollRight = setTimeout( function(){ scrollRight = 0; }, 300 );
}
}
}
});