31d7b4572f
Also updated dom2.js to partially match the Selectors/DOM4 spec. Fixes #1
39 lines
No EOL
1 KiB
JavaScript
39 lines
No EOL
1 KiB
JavaScript
define(["dom2"], function() {
|
|
|
|
return function(text, buttons, callback) {
|
|
if (typeof buttons == "function") {
|
|
callback = buttons;
|
|
buttons = ["ok", "cancel"];
|
|
}
|
|
var modal = document.createElement("div");
|
|
modal.className = "modal-overlay";
|
|
var dialog = document.createElement("div");
|
|
dialog.className = "dialog";
|
|
dialog.innerHTML = text;
|
|
var buttonRow = document.createElement("div");
|
|
buttonRow.className = "button-row";
|
|
modal.append(dialog);
|
|
dialog.append(buttonRow);
|
|
|
|
var clickButton = function() {
|
|
modal.remove();
|
|
callback(this.value);
|
|
}
|
|
|
|
buttons.forEach(function(options) {
|
|
var button = document.createElement("button");
|
|
if (typeof options == "string") {
|
|
options = {
|
|
label: options,
|
|
value: options
|
|
}
|
|
}
|
|
button.innerHTML = options.label;
|
|
button.value = options.value;
|
|
buttonRow.append(button);
|
|
button.on("click", clickButton);
|
|
});
|
|
document.body.append(modal);
|
|
}
|
|
|
|
}); |