From a46c23b10f972ee235e282e7d79de2e9e7a91d68 Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Fri, 5 May 2023 22:48:27 -0600 Subject: Make gamepad navigation optional --- javascript/imageviewerGamepad.js | 61 +++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 32 deletions(-) (limited to 'javascript/imageviewerGamepad.js') diff --git a/javascript/imageviewerGamepad.js b/javascript/imageviewerGamepad.js index 29bd7140..db932bca 100644 --- a/javascript/imageviewerGamepad.js +++ b/javascript/imageviewerGamepad.js @@ -1,36 +1,33 @@ - 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(e); - } else if (xValue > 0.3) { - modalNextImage(e); - } - - }, delay); - }); - - - /* - Primarily for vr controller type pointer devices. - I use the wheel event because there's currently no way to do it properly with web xr. - */ - - let isScrolling = false; - window.addEventListener('wheel', (e) => { - if (isScrolling) return; - isScrolling = true; - - if (e.deltaX <= -0.6) { +const delay = 250//ms +window.addEventListener('gamepadconnected', (e) => { + setInterval(() => { + if (!opts.js_modal_lightbox_gamepad) return; + const gamepad = navigator.getGamepads()[0]; + const xValue = gamepad.axes[0]; + if (xValue < -0.3) { modalPrevImage(e); - } else if (e.deltaX >= 0.6) { + } else if (xValue > 0.3) { modalNextImage(e); } + }, delay); +}); + +/* +Primarily for vr controller type pointer devices. +I use the wheel event because there's currently no way to do it properly with web xr. + */ +let isScrolling = false; +window.addEventListener('wheel', (e) => { + if (!opts.js_modal_lightbox_gamepad || isScrolling) return; + isScrolling = true; + + if (e.deltaX <= -0.6) { + modalPrevImage(e); + } else if (e.deltaX >= 0.6) { + modalNextImage(e); + } - setTimeout(() => { - isScrolling = false; - }, delay); - }); \ No newline at end of file + setTimeout(() => { + isScrolling = false; + }, delay); +}); -- cgit v1.2.1