Commit 40dc0132 authored by unknown's avatar unknown

modularize

parent bfa14db2
...@@ -220,37 +220,10 @@ document.addEventListener("DOMContentLoaded", function() { ...@@ -220,37 +220,10 @@ document.addEventListener("DOMContentLoaded", function() {
modal.tabIndex = 0 modal.tabIndex = 0
modal.addEventListener('keydown', modalKeyHandler, true) modal.addEventListener('keydown', modalKeyHandler, true)
let delay = 350//ms // detect gamepads and enable related functionality
window.addEventListener('gamepadconnected', (e) => { let gamepadScript = document.createElement('script');
console.log("Gamepad connected!") gamepadScript.src = 'imageviewerGamepad.js';
const gamepad = e.gamepad; document.body.appendChild(gamepadScript);
setInterval(() => {
const xValue = gamepad.axes[0].toFixed(2);
if (xValue < -0.3) {
modalPrevImage(e);
} else if (xValue > 0.3) {
modalNextImage(e);
}
}, 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') const modalControls = document.createElement('div')
modalControls.className = 'modalControls gradio-container'; modalControls.className = 'modalControls gradio-container';
......
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) {
modalPrevImage(e);
} else if (e.deltaX >= 0.6) {
modalNextImage(e);
}
setTimeout(() => {
isScrolling = false;
}, delay);
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment