aboutsummaryrefslogtreecommitdiff
path: root/javascript
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2023-05-31 19:15:21 +0300
committerGitHub <noreply@github.com>2023-05-31 19:15:21 +0300
commit52b8752e6201e24c783f674f8dc0681027e10ea9 (patch)
tree30470f64d84cadc4140023c0bf34c35bb68f79b0 /javascript
parent00dfe27f59727407c5b408a80ff2a262934df495 (diff)
parent78a602ae8c006077ca93913576335a3a33dba7cb (diff)
Merge branch 'dev' into report-error
Diffstat (limited to 'javascript')
-rw-r--r--javascript/imageviewerGamepad.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/javascript/imageviewerGamepad.js b/javascript/imageviewerGamepad.js
index 31d226de..a22c7e6e 100644
--- a/javascript/imageviewerGamepad.js
+++ b/javascript/imageviewerGamepad.js
@@ -1,7 +1,9 @@
+let gamepads = [];
+
window.addEventListener('gamepadconnected', (e) => {
const index = e.gamepad.index;
let isWaiting = false;
- setInterval(async() => {
+ gamepads[index] = setInterval(async() => {
if (!opts.js_modal_lightbox_gamepad || isWaiting) return;
const gamepad = navigator.getGamepads()[index];
const xValue = gamepad.axes[0];
@@ -24,6 +26,10 @@ window.addEventListener('gamepadconnected', (e) => {
}, 10);
});
+window.addEventListener('gamepaddisconnected', (e) => {
+ clearInterval(gamepads[e.gamepad.index]);
+});
+
/*
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.