A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
at lambda-fork/main 46 lines 1.9 kB view raw
1import {isMobile} from "../util/functions"; 2import {Dialog} from "./index"; 3import {Constants} from "../constants"; 4 5export const confirmDialog = (title: string, text: string, 6 confirm?: (dialog?: Dialog) => void, 7 cancel?: (dialog: Dialog) => void, 8 isDelete = false) => { 9 if (!text && !title) { 10 confirm(); 11 return; 12 } 13 const dialog = new Dialog({ 14 title, 15 content: `<div class="b3-dialog__content"> 16 <div class="ft__breakword">${text}</div> 17</div> 18<div class="b3-dialog__action"> 19 <button class="b3-button b3-button--cancel" id="cancelDialogConfirmBtn">${window.siyuan.languages.cancel}</button><div class="fn__space"></div> 20 <button class="b3-button ${isDelete ? "b3-button--remove" : "b3-button--text"}" id="confirmDialogConfirmBtn">${window.siyuan.languages[isDelete ? "delete" : "confirm"]}</button> 21</div>`, 22 width: isMobile() ? "92vw" : "520px", 23 }); 24 25 dialog.element.addEventListener("click", (event) => { 26 let target = event.target as HTMLElement; 27 const isDispatch = typeof event.detail === "string"; 28 while (target && target !== dialog.element || isDispatch) { 29 if (target.id === "cancelDialogConfirmBtn" || (isDispatch && event.detail=== "Escape")) { 30 if (cancel) { 31 cancel(dialog); 32 } 33 dialog.destroy(); 34 break; 35 } else if (target.id === "confirmDialogConfirmBtn" || (isDispatch && event.detail=== "Enter")) { 36 if (confirm) { 37 confirm(dialog); 38 } 39 dialog.destroy(); 40 break; 41 } 42 target = target.parentElement; 43 } 44 }); 45 dialog.element.setAttribute("data-key", Constants.DIALOG_CONFIRM); 46};