33 lines
811 B
JavaScript
Raw Normal View History

import utils from "../services/utils.js";
const $dialog = $("#info-dialog");
const $infoContent = $("#info-dialog-content");
const $okButton = $("#info-dialog-ok-button");
let resolve;
let $originallyFocused; // element focused before the dialog was opened so we can return to it afterwards
export function info(message) {
$originallyFocused = $(':focus');
$infoContent.text(message);
utils.openDialog($dialog);
2018-11-12 21:18:22 +01:00
return new Promise((res, rej) => { resolve = res; });
}
$dialog.on('shown.bs.modal', () => $okButton.trigger("focus"));
$dialog.on("hidden.bs.modal", () => {
if (resolve) {
resolve();
}
if ($originallyFocused) {
2019-11-09 17:45:22 +01:00
$originallyFocused.trigger('focus');
$originallyFocused = null;
}
});
2019-11-09 17:39:48 +01:00
$okButton.on('click', () => $dialog.modal("hide"));