Wednesday, August 24, 2011

Exit on ESC in Wicket ModalWindow


//Every modal dialog will extend this class
public class ModalPanelContainer extends ModalWindow implements IHeaderContributor {

//the magic is in this method
@Override
public void show(final AjaxRequestTarget target) {
if (!isShown()) {
final AppendingStringBuffer buffer = new AppendingStringBuffer(500);
buffer.append("function mwClose(ev) {\n" +
"var code = ev.keyCode || ev.which;\n" +
"if (code == 27) { " +
getCloseJavacript() +
"};" +
"}");
buffer.append("jQuery(document).keypress(mwClose);\n");
target.appendJavascript(buffer.toString());
}
super.show(target);
}



}

No comments:

Post a Comment