This repository has been archived on 2024-05-14. You can view files and clone it, but cannot push or open issues or pull requests.
awesome-xlabs/localappdata/xlabs/data/launcher-ui/js/message-box.js
2023-08-13 16:46:26 -04:00

48 lines
1.4 KiB
JavaScript

function constructMessageBox(title, message, buttons) {
title = title || "Error";
nessage = message || "";
buttons = buttons || ["Ok"];
return new Promise((resolve, reject) => {
try{
const messageBox = document.querySelector("#message-box");
const resolveInternal = function() {
messageBox.classList.remove("visible");
return resolve.apply(this, arguments);
};
const titleElement = messageBox.querySelector(".mb-title");
titleElement.innerHTML = title;
const contentElement = messageBox.querySelector(".mb-content");
contentElement.innerHTML = message;
const buttonElement = messageBox.querySelector(".mb-buttons");
buttonElement.textContent = "";
messageBox.classList.add("visible");
buttons.forEach((value, index) => {
var button = document.createElement("button");
button.innerHTML = value;
button.onclick = resolveInternal.bind(this, index);
buttonElement.appendChild(button);
});
}
catch(e) {
reject(e);
}
});
}
window.showMessageBox = function() {
window.lastBox = window.lastBox || Promise.resolve();
const newBox = window.lastBox.then(() => constructMessageBox.apply(this, arguments));
window.lastBox = newBox;
return newBox;
};