t4t5/sweetalert — pull request #40 by nixta (2014-10-04 17:58:41+00:00)
Title: Add keyboard shortcuts

I was working on this for a day or so and then I saw PR #11. Gah!

Well, since I've done the work, I figured provide this too.

Note, there's a bug with explicitly dispatching a mouse event from the keyboard event in Chrome *IF* that mouse event opens an alert box (as far as I could tell, anyway) then the mouse-click event re-enters. The

The work-around is to let the browser handler SPACE or ENTER on a button (which they all appear to do) and only dispatch the event if SPACE or ENTER were pressed outside of a button (i.e. in the window.onkeydown event).

Also, ESC should only cancel the alert if there is a cancel button, like the main JavaScript alert dialog does. Can easily make this confgurable of course.

This also tries to ensure that where we modify event handlers on document and window that we restore them to their previous values when the modal alert is close.

Please give this a go and see if it's broken. I think this works pretty well though.

I do still need to add shift-tab.