Hi,
I actually use this in my project :

    /**
     * Behavior allowing to close the window on esc, requires jQuery
     * Slighlty modified from
http://stackoverflow.com/questions/5042426/wicket-close-modalwindow-on-keypress
     */
    private class CloseOnESCBehavior extends AbstractDefaultAjaxBehavior {

        @NonNls
        private static final String PRE_JS = "$(document).ready(function()
{\n" +
                                             "  $(document).bind('keyup',
function(evt) {\n" +
                                             "    if (evt.keyCode == 27)
{\n";
        @NonNls
        private static final String POST_JS = "\n evt.preventDefault();\n" +
                                              "    }\n" +
                                              "  });\n" +
                                              "});";

        /**
         * {@inheritDoc}
         */
        @Override
        protected void respond(AjaxRequestTarget target) {
            close(target);
        }

        /**
         * {@inheritDoc}
         *
         * @return always null to hide the indicator (it does not flicker)
         */
        @Override
        protected String findIndicatorId() {
            return null;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void renderHead(Component component, IHeaderResponse
response) {
            response.renderJavaScript(new
StringBuilder(PRE_JS).append(getCallbackScript())
                                              .append(POST_JS).toString(),
"closeModalOnEsc");
        }
    }

You'll need to adapt it if you're not using JQuery in your project. All you
have to do is add this behavior on your modal window.

Regards,
__
Cedric Gatay
http://www.bloggure.info | http://cedric.gatay.fr |
@Cedric_Gatay<http://twitter.com/Cedric_Gatay>


On Fri, Aug 17, 2012 at 12:05 PM, Marco Di Sabatino Di Diodoro <
[email protected]> wrote:

> Hi,
>
> I need close the ModalWindows of my application when I press ESC on the
> keyboard.
>
> Suggestions?
>
> Regards
> M
>
> --
>
> Dott. Marco Di Sabatino Di Diodoro
> Tel. +39 3939065570
>
> Tirasa S.r.l.
> Viale D'Annunzio 267 - 65127 Pescara
> Tel +39 0859116307 / FAX +39 0859111173
> http://www.tirasa.net
>
> Apache Syncope PPMC Member
> http://people.apache.org/~mdisabatino
>
>
>
>
>

Reply via email to