Skip to content

Instantly share code, notes, and snippets.

@shelaf
Last active June 12, 2017 12:37
Show Gist options
  • Save shelaf/91eaa7bd20c6905f45fca70a7901a88e to your computer and use it in GitHub Desktop.
Save shelaf/91eaa7bd20c6905f45fca70a7901a88e to your computer and use it in GitHub Desktop.
jQueryUIで複数ボタンのダイアログ実装試作
export module MyDialog {
export interface Button {
text: string,
method(): void
}
export function confirm(title: string, buttons: Button[]): void {
let button_set: any = {};
for (let button of buttons) {
button_set[button.text] = (function () {
button.method();
$(this).dialog("close");
});
}
var dialog = $("#dialog");
dialog.dialog({
autoOpen: false,
title: title,
modal: true,
buttons: button_set,
});
}
}
$(document).ready(function () {
let buttons: dialog.MyDialog.Button[] = [
{
text: "confirm", method: (function () {
alert("test");
})
},
{
text: "confirm2", method: (function () {
alert("test2");
})
},
{
text: "confirm3", method: (function () {
alert("test3");
})
},
{
text: "Cancel", method: (function () {
})
}
];
dialog.MyDialog.confirm("title", buttons);
var button = document.getElementById("button");
button.addEventListener("click", function () {
$('#dialog').dialog('open');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment