Unverified Commit bfa14db2 authored by unknown's avatar unknown
Browse files

enable gallery scrolling functionality for horizontal scroll and gamepads

parent 501d4e9c
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -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);
            }

        }, 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);
        }

        }, 350);
        setTimeout(() => {
            isScrolling = false;
        }, delay);
    });

    const modalControls = document.createElement('div')