bootstrap backed replacements for JS prompt and alert

This commit is contained in:
azivner
2018-11-12 20:17:48 +01:00
parent c6e1ad5f15
commit 2523f81f3b
7 changed files with 119 additions and 39 deletions

View File

@@ -0,0 +1,37 @@
const $dialog = $("#prompt-dialog");
const $question = $("#prompt-dialog-question");
const $answer = $("#prompt-dialog-answer");
const $form = $("#prompt-dialog-form");
let resolve;
function ask(message, defaultValue = '') {
glob.activeDialog = $dialog;
$question.text(message);
$answer.val(defaultValue);
$dialog.modal();
return new Promise((res, rej) => {
resolve = res;
});
}
$dialog.on('shown.bs.modal', () => $answer.focus().select());
$dialog.on("hidden.bs.modal", () => {
if (resolve) {
resolve(null);
}
});
$form.submit(() => {
resolve($answer.val());
$dialog.modal('hide');
});
export default {
ask
}