mirror of https://github.com/TriliumNext/Notes
bootstrap backed replacements for JS prompt and alert
parent
c6e1ad5f15
commit
2523f81f3b
@ -0,0 +1,31 @@
|
|||||||
|
const $dialog = $("#info-dialog");
|
||||||
|
const $infoContent = $("#info-dialog-content");
|
||||||
|
const $okButton = $("#info-dialog-ok-button");
|
||||||
|
|
||||||
|
let resolve;
|
||||||
|
|
||||||
|
function info(message) {
|
||||||
|
glob.activeDialog = $dialog;
|
||||||
|
|
||||||
|
$infoContent.text(message);
|
||||||
|
|
||||||
|
$dialog.modal();
|
||||||
|
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
resolve = res;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$dialog.on('shown.bs.modal', () => $okButton.trigger("focus"));
|
||||||
|
|
||||||
|
$dialog.on("hidden.bs.modal", () => {
|
||||||
|
if (resolve) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$okButton.click(() => $dialog.modal("hide"));
|
||||||
|
|
||||||
|
export default {
|
||||||
|
info
|
||||||
|
}
|
||||||
@ -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
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
<div id="info-dialog" class="modal mx-auto" tabindex="-1" role="dialog">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title mr-auto">Info message</h5>
|
||||||
|
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div id="info-dialog-content"></div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button class="btn btn-primary btn-sm" id="info-dialog-ok-button">OK <kbd>enter</kbd></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
<div id="prompt-dialog" class="modal mx-auto" tabindex="-1" role="dialog">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<form id="prompt-dialog-form">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title mr-auto">Prompt</h5>
|
||||||
|
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="prompt-dialog-answer" id="prompt-dialog-question"></label>
|
||||||
|
<input type="text" class="form-control" id="prompt-dialog-answer" placeholder="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button class="btn btn-primary btn-sm" id="prompt-dialog-ok-button">OK <kbd>enter</kbd></button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
Loading…
Reference in New Issue