From 03c2bf52a902847f6fb155a2a8f657575d7a7ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sat, 4 Feb 2023 01:42:21 +0100 Subject: [PATCH] nav: fix nav on last project page and horizontal scrolling detection #452 --- static/js/theme.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/static/js/theme.js b/static/js/theme.js index ea4ee4cfb3..43d04b5f26 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -394,10 +394,10 @@ function initArrowNav(){ } // button navigation - var e = document.querySelector( 'a.nav-prev' ); - e && e.addEventListener( 'click', navPrev ); - e = document.querySelector( 'a.nav-next' ); - e && e.addEventListener( 'click', navNext ); + var prev = document.querySelector( 'a.nav-prev' ); + prev && prev.addEventListener( 'click', navPrev ); + var next = document.querySelector( 'a.nav-next' ); + next && next.addEventListener( 'click', navNext ); // keyboard navigation // avoid prev/next navigation if we are not at the start/end of the @@ -408,8 +408,8 @@ function initArrowNav(){ document.addEventListener('keydown', function(event){ if( !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey ){ if( event.which == '37' ){ - if( !scrollLeft && el.scrollLeft <= 0 ){ - navPrev(); + if( !scrollLeft && +el.scrollLeft.toFixed() <= 0 ){ + prev && prev.click(); } else if( scrollLeft != -1 ){ clearTimeout( scrollLeft ); @@ -417,8 +417,8 @@ function initArrowNav(){ scrollLeft = -1; } if( event.which == '39' ){ - if( !scrollRight && el.scrollLeft + el.clientWidth >= el.scrollWidth ){ - navNext(); + if( !scrollRight && +el.scrollLeft.toFixed() + +el.clientWidth.toFixed() >= +el.scrollWidth.toFixed() ){ + next && next.click(); } else if( scrollRight != -1 ){ clearTimeout( scrollRight );