From bfa14db2cb0e266121317e3624b93708b29f2e88 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Feb 2023 16:54:12 -0600 Subject: [PATCH] enable gallery scrolling functionality for horizontal scroll and gamepads --- javascript/imageviewer.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/javascript/imageviewer.js b/javascript/imageviewer.js index 3f7b1289..e5355d0b 100644 --- a/javascript/imageviewer.js +++ b/javascript/imageviewer.js @@ -219,18 +219,37 @@ document.addEventListener("DOMContentLoaded", function() { modal.id = "lightboxModal"; modal.tabIndex = 0 modal.addEventListener('keydown', modalKeyHandler, true) + + let delay = 350//ms window.addEventListener('gamepadconnected', (e) => { console.log("Gamepad connected!") const gamepad = e.gamepad; setInterval(() => { const xValue = gamepad.axes[0].toFixed(2); if (xValue < -0.3) { - modalPrevImage(); + modalPrevImage(e); } else if (xValue > 0.3) { - modalNextImage(); + modalNextImage(e); } - }, 350); + }, delay); + }); + + + let isScrolling = false; + window.addEventListener('wheel', (e) => { + if (isScrolling) return; + isScrolling = true; + + if (e.deltaX <= -0.6) { + modalPrevImage(e); + } else if (e.deltaX >= 0.6) { + modalNextImage(e); + } + + setTimeout(() => { + isScrolling = false; + }, delay); }); const modalControls = document.createElement('div')