2022-05-26 15:18:53 +08:00
|
|
|
import {isMobile} from "../util/functions";
|
|
|
|
|
import {Dialog} from "./index";
|
|
|
|
|
|
2023-07-30 13:16:14 +08:00
|
|
|
export const confirmDialog = (title: string, text: string, confirm?: (dialog:Dialog) => void, cancel?: (dialog:Dialog) => void) => {
|
2022-05-26 15:18:53 +08:00
|
|
|
const dialog = new Dialog({
|
|
|
|
|
title,
|
2023-04-14 20:21:09 +08:00
|
|
|
content: `<div class="b3-dialog__content">
|
|
|
|
|
<div class="ft__breakword">${text}</div>
|
|
|
|
|
</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
<div class="b3-dialog__action">
|
|
|
|
|
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
|
|
|
|
<button class="b3-button b3-button--text" id="confirmDialogConfirmBtn">${window.siyuan.languages.confirm}</button>
|
|
|
|
|
</div>`,
|
2023-04-20 10:05:24 +08:00
|
|
|
width: isMobile() ? "92vw" : "520px",
|
2022-05-26 15:18:53 +08:00
|
|
|
});
|
|
|
|
|
const btnsElement = dialog.element.querySelectorAll(".b3-button");
|
|
|
|
|
btnsElement[0].addEventListener("click", () => {
|
2022-09-08 22:40:01 +08:00
|
|
|
if (cancel) {
|
2023-07-30 13:16:14 +08:00
|
|
|
cancel(dialog);
|
2022-09-08 22:40:01 +08:00
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
dialog.destroy();
|
|
|
|
|
});
|
|
|
|
|
btnsElement[1].addEventListener("click", () => {
|
|
|
|
|
if (confirm) {
|
2023-07-30 13:16:14 +08:00
|
|
|
confirm(dialog);
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
dialog.destroy();
|
|
|
|
|
});
|
|
|
|
|
};
|