trilium/src/public/javascripts/dialogs/prompt.js

44 lines
806 B
JavaScript
Raw Normal View History

const $dialog = $("#prompt-dialog");
const $question = $("#prompt-dialog-question");
const $answer = $("#prompt-dialog-answer");
const $form = $("#prompt-dialog-form");
let resolve;
let shownCb;
function ask({ message, defaultValue, shown }) {
glob.activeDialog = $dialog;
shownCb = shown;
$question.text(message);
$answer.val(defaultValue || "");
$dialog.modal();
2018-11-13 04:18:22 +08:00
return new Promise((res, rej) => { resolve = res; });
}
$dialog.on('shown.bs.modal', () => {
if (shownCb) {
shownCb({ $dialog, $question, $answer, $form });
}
$answer.focus().select();
});
$dialog.on("hidden.bs.modal", () => {
if (resolve) {
resolve(null);
}
});
$form.submit(() => {
resolve($answer.val());
$dialog.modal('hide');
});
export default {
ask
}