dialog 포커스 제어 수정

master
mjkhan21 6 months ago
parent 8f3f388413
commit 535f230500

@ -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:function(id) {
$("#close" + id).click(); $("#close" + id).click();
}, },
create:function(conf) { create:function(conf) {
let last = { let last = {
dlg: $("div.modal.show").last()[0], dlg: dialog.getLast(),
setZIndex: (obj, offset) => { setZIndex: (obj, offset) => {
if (!last.dlg) return; if (!last.dlg) return;
@ -144,11 +153,18 @@ var dialog = {
dlg.find(".modal-body").html(conf.content || "").fadeIn(); 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 $("#" + id +",#" + backdropID).remove(); // removes the dialog and its backdrop
if (conf.onClose) if (conf.onClose)
conf.onClose(); conf.onClose();
}); dialog.refocus();
});
if (conf.onOK) { if (conf.onOK) {
let footer = dlg.find(".modal-footer"); let footer = dlg.find(".modal-footer");
@ -179,9 +195,11 @@ var dialog = {
if (!backdrop.prop("id")) if (!backdrop.prop("id"))
backdrop.prop("id", backdropID); backdrop.prop("id", backdropID);
}); });
/* setTimeout(function(){
if (conf.init) if (conf.init)
conf.init(); conf.init();
}, 100);
*/
}, },
alert:function(conf) { alert:function(conf) {
var container = "<div class='container-fluid text-center' style='font-size:1.4em;'>{content}</div>"; var container = "<div class='container-fluid text-center' style='font-size:1.4em;'>{content}</div>";

Loading…
Cancel
Save