MCPcopy Index your code
hub / github.com/DustinBrett/daedalOS / showMessageBox

Function showMessageBox

public/Program Files/jspaint/src/msgbox.js:30–117  ·  view source on GitHub ↗
({
		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.
	})

Source from the content-addressed store, hash-verified

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");

Callers 15

constructorMethod · 0.85
startMethod · 0.85
set_languageFunction · 0.85
storage_quota_exceededFunction · 0.85
open_help_viewerFunction · 0.85
doItAgainFunction · 0.85
are_you_sureFunction · 0.85
please_enter_a_numberFunction · 0.85
show_error_messageFunction · 0.85
show_file_format_errorsFunction · 0.85

Calls 15

setTimeoutFunction · 0.85
play_chordFunction · 0.85
assignMethod · 0.80
attrMethod · 0.80
addClassMethod · 0.80
removeClassMethod · 0.80
$Function · 0.50
resolveFunction · 0.50
htmlMethod · 0.45
textMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected