Hi all,

I configure into Apache Syncope the possibility to close ModalWindow with ESC 
key press event.

public class CloseOnESCBehavior extends AbstractDefaultAjaxBehavior {

    private static final long serialVersionUID = 5826308247642534260L;
    private ModalWindow modalWindow;

    public CloseOnESCBehavior(ModalWindow modalWindow) {
        this.modalWindow = modalWindow;
    }

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

    private static final String POST_JS = "\n evt.preventDefault();\n"
            + "evt.stopImmediatePropagation();\n"
            + "    }\n"
            + "  });\n"
            + "});";

    @Override
    protected void respond(final AjaxRequestTarget target) {
        modalWindow.close(target);
    }

    @Override
    protected String findIndicatorId() {
        return null;
    }

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

In the modal page:

add(new CloseOnESCBehavior(window));

It work correctly with Chrome and Safari. With Firefox, if I press the ESC key 
twice quickly before the window closes the console return an error:

ERROR: Wicket.Ajax.Call.failure: Error while parsing response: Could not find 
root <ajax-response> element

Regards
Marco


--

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