Skip to content

Commit

Permalink
SAK-33744: focus and ESC for the modal have been repaired (sakaiproje…
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioJordan authored and Miguel Pellicer committed Sep 12, 2019
1 parent 930e9af commit 5bfc5c7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected CharSequence getShowJavaScript() {
StringBuilder extraJavascript = new StringBuilder();

// focus the first input field in the content pane
extraJavascript.append(String.format("setTimeout(function() {$('#%s :input:first:visible').focus();});",
extraJavascript.append(String.format("setTimeout(function() {$('#%s :input:visible:first').focus();});",
getContent().getMarkupId()));

// position at the top of the page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.Session;
import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
Expand Down Expand Up @@ -215,6 +217,8 @@ public GradebookPage() {
this.bulkEditItemsWindow.showUnloadConfirmation(false);
this.form.add(this.bulkEditItemsWindow);

add(new CloseOnESCBehavior(bulkEditItemsWindow));

// first get any settings data from the session
final GradebookUiSettings settings = getUiSettings();

Expand Down Expand Up @@ -656,4 +660,29 @@ public boolean isVisible() {
return businessService.isUserAbleToEditAssessments() && GradebookPage.this.hasGradebookItems;
}
}


private static class CloseOnESCBehavior extends AbstractDefaultAjaxBehavior {
private final ModalWindow modal;
public CloseOnESCBehavior(ModalWindow modal) {
this.modal = modal;
}
@Override
protected void respond(AjaxRequestTarget target) {
modal.close(target);
}
@Override
public void renderHead(Component component, IHeaderResponse response) {
String aux = "" +
"$(document).ready(function() {\n" +
" $(document).bind('keyup', function(evt) {\n" +
" if (evt.keyCode == 27) {\n" +
getCallbackScript() + "\n" +
" evt.preventDefault();\n" +
" }\n" +
" });\n" +
"});";
response.render(JavaScriptHeaderItem.forScript(aux, "closeModal"));
}
}
}

0 comments on commit 5bfc5c7

Please sign in to comment.