From f322e58ddd916a965e848fd9be3dca2c1fa30b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sun, 29 Jan 2023 16:47:34 +0100 Subject: [PATCH] nav: remove jQuery #452 --- static/js/theme.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/static/js/theme.js b/static/js/theme.js index acfbcab711..bedce01da2 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -365,14 +365,10 @@ function initArrowNav(){ } // button navigation - jQuery(function() { - jQuery('a.nav-prev').click(function(){ - location.href = jQuery(this).attr('href'); - }); - jQuery('a.nav-next').click(function() { - location.href = jQuery(this).attr('href'); - }); - }); + var e = document.querySelector( 'a.nav-prev' ); + e && e.addEventListener( 'click', navPrev ); + e = document.querySelector( 'a.nav-next' ); + e && e.addEventListener( 'click', navNext ); // keyboard navigation // avoid prev/next navigation if we are not at the start/end of the @@ -384,7 +380,7 @@ function initArrowNav(){ if( !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey ){ if( event.which == '37' ){ if( !scrollLeft && el.scrollLeft <= 0 ){ - jQuery('a.nav-prev').click(); + navPrev(); } else if( scrollLeft != -1 ){ clearTimeout( scrollLeft ); @@ -393,7 +389,7 @@ function initArrowNav(){ } if( event.which == '39' ){ if( !scrollRight && el.scrollLeft + el.clientWidth >= el.scrollWidth ){ - jQuery('a.nav-next').click(); + navNext(); } else if( scrollRight != -1 ){ clearTimeout( scrollRight ); @@ -419,10 +415,12 @@ function initArrowNav(){ }); // avoid keyboard navigation for input fields - jQuery(formelements).keydown(function (e) { - if (e.which == '37' || e.which == '39') { - e.stopPropagation(); - } + document.querySelectorAll( formelements ).forEach( function( e ){ + e.addEventListener( 'keydown', function( event ){ + if( event.which == 37 || event.which == 39 ){ + event.stopPropagation(); + } + }); }); } @@ -630,6 +628,16 @@ function showPrint(){ } } +function navPrev(){ + var e = document.querySelector( 'a.nav-prev' ); + location.href = e && e.getAttribute( 'href' ); +}; + +function navNext(){ + var e = document.querySelector( 'a.nav-next' ); + location.href = e && e.getAttribute( 'href' ); +}; + function initToc(){ if( isPrint ){ return;