mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 02:45:54 +01:00
bootstrap backed replacements for JS prompt and alert
This commit is contained in:
37
src/public/javascripts/dialogs/prompt.js
Normal file
37
src/public/javascripts/dialogs/prompt.js
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user