
$(() => {
    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("fullScreenOverlay").addEventListener("click", triggerClosePopinsRequestHandlers);
    document.onClosePopinRequested = (hndl) => closePopinsRequestedHandlers.push(hndl);
});

