Question

I have a web application that uses a mousetrap API for keyboard shortcuts. I am facing difficulties in the following scenario: I'm in a modal (jQueryUI) and this modal having a second modal alert. When the alert is closed, the focus does not return to main modal, making the shortcuts do not work, you need a mouse click in the modal div for the shortcut working again. My question is: is there any way to make the mousetrap ignore the focus on div and assume a global behavior?
If not, is there any way to work around this?

Was it helpful?

Solution

One way to solve this problem is, when the second modal is closed, forcing the mouse click on the current modal using javascript.
How can you not know what the current modal, use the position (center of screen) to find the active field.
Something like this

function ClickCenterScreen() {
    x = $(document).width() / 2;
    y = $(document).height() / 2;
    element = $(document.elementFromPoint(x, y));           
    element = $(element).contents().find("form").find("input[type=text]").first();

    // you need to set focus on element first.
    $(element).focus();
    $(element).click();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top