diff --git a/src/main/webapp/resources/js/base/base.js b/src/main/webapp/resources/js/base/base.js index b2a1eef..4052364 100644 --- a/src/main/webapp/resources/js/base/base.js +++ b/src/main/webapp/resources/js/base/base.js @@ -115,12 +115,21 @@ var dialog = { }); } }, + getLast: function() { + let modals = $("div.modal.show"); + return modals.last()[0]; + }, + refocus: function() { + let last = dialog.getLast(); + if (last) + last.focus(); + }, close:function(id) { $("#close" + id).click(); }, create:function(conf) { let last = { - dlg: $("div.modal.show").last()[0], + dlg: dialog.getLast(), setZIndex: (obj, offset) => { if (!last.dlg) return; @@ -144,11 +153,18 @@ var dialog = { dlg.find(".modal-body").html(conf.content || "").fadeIn(); - dlg.on("hidden.bs.modal", function() {// on dialog close + dlg.on("shown.bs.modal", function() {// after dialog show + dialog.refocus(); + dlg.find("[autofocus]").first().focus(); + if (conf.init) + conf.init(); + }) + .on("hidden.bs.modal", function() {// on dialog close $("#" + id +",#" + backdropID).remove(); // removes the dialog and its backdrop if (conf.onClose) conf.onClose(); - }); + dialog.refocus(); + }); if (conf.onOK) { let footer = dlg.find(".modal-footer"); @@ -179,9 +195,11 @@ var dialog = { if (!backdrop.prop("id")) backdrop.prop("id", backdropID); }); - - if (conf.init) - conf.init(); +/* setTimeout(function(){ + if (conf.init) + conf.init(); + }, 100); +*/ }, alert:function(conf) { var container = "