({
title = window.defaultMessageBoxTitle ?? "Alert",
message,
messageHTML,
buttons = [{ label: "OK", value: "ok", default: true }],
iconID = "warning", // "error", "warning", "info", or "nuke" for deleting files/folders
windowOptions = {}, // for controlling width, etc.
})
| 28 | } |
| 29 | |
| 30 | function showMessageBox({ |
| 31 | title = window.defaultMessageBoxTitle ?? "Alert", |
| 32 | message, |
| 33 | messageHTML, |
| 34 | buttons = [{ label: "OK", value: "ok", default: true }], |
| 35 | iconID = "warning", // "error", "warning", "info", or "nuke" for deleting files/folders |
| 36 | windowOptions = {}, // for controlling width, etc. |
| 37 | }) { |
| 38 | let $window, $message; |
| 39 | const promise = new Promise((resolve, reject) => { |
| 40 | $window = make_window_supporting_scale(Object.assign({ |
| 41 | title, |
| 42 | resizable: false, |
| 43 | innerWidth: 400, |
| 44 | maximizeButton: false, |
| 45 | minimizeButton: false, |
| 46 | }, windowOptions)); |
| 47 | // $window.addClass("dialog-window horizontal-buttons"); |
| 48 | $message = |
| 49 | $("<div>").css({ |
| 50 | textAlign: "left", |
| 51 | fontFamily: "MS Sans Serif, Arial, sans-serif", |
| 52 | fontSize: "14px", |
| 53 | marginTop: "22px", |
| 54 | flex: 1, |
| 55 | minWidth: 0, // Fixes hidden overflow, see https://css-tricks.com/flexbox-truncated-text/ |
| 56 | whiteSpace: "normal", // overriding .window:not(.squish) |
| 57 | }); |
| 58 | if (messageHTML) { |
| 59 | $message.html(messageHTML); |
| 60 | } else if (message) { // both are optional because you may populate later with dynamic content |
| 61 | $message.text(message).css({ |
| 62 | whiteSpace: "pre-wrap", |
| 63 | wordWrap: "break-word", |
| 64 | }); |
| 65 | } |
| 66 | $("<div>").append( |
| 67 | $("<img width='32' height='32'>").attr("src", `images/${iconID}-32x32-8bpp.png`).css({ |
| 68 | margin: "16px", |
| 69 | display: "block", |
| 70 | }), |
| 71 | $message |
| 72 | ).css({ |
| 73 | display: "flex", |
| 74 | flexDirection: "row", |
| 75 | }).appendTo($window.$content); |
| 76 | |
| 77 | $window.$content.css({ |
| 78 | textAlign: "center", |
| 79 | }); |
| 80 | for (const button of buttons) { |
| 81 | const $button = $window.$Button(button.label, () => { |
| 82 | button.action?.(); // API may be required for using user gesture requiring APIs |
| 83 | resolve(button.value); |
| 84 | $window.close(); // actually happens automatically |
| 85 | }); |
| 86 | if (button.default) { |
| 87 | $button.addClass("default"); |
no test coverage detected