
$(() => {
    let closePopinsRequestedHandlers = [];
    window.lastKeyboardEvent = null;

    document.addEventListener("keyup", evt => {
        window.lastKeyboardEvent = evt;
    });

    function triggerClosePopinsRequestHandlers() {
        for (let i of closePopinsRequestedHandlers)
            i();
    }

    document.addEventListener("keydown", evt => {
        window.lastKeyboardEvent = evt;
        if (evt.keyCode === 27)
            triggerClosePopinsRequestHandlers();
    });

    document.getElementById("pch-navbar-reload").addEventListener("click", () => reloadServerDb());
    document.getElementById("pch-navbar-share").addEventListener("click", () => showShareUi());
    document.getElementById("fullScreenOverlay").addEventListener("click", triggerClosePopinsRequestHandlers);
    document.onClosePopinRequested = (hndl) => closePopinsRequestedHandlers.push(hndl);
});

