以下のコードは、この問題に対する私の解決策です。関数内での使用法を文書化しましたが、ここで強調します。
$.ConfirmDialog('Do you want to continue?', 'Continue Title', function() { alert('yes'); }, function() { alert('no'); }, null);
特別な設定は必要ありません。ページに「ConfirmDialog」コードブロックを含めて (私は自分の app.js に入れました)、上記の 1 行で呼び出します。楽しみ!
$.ConfirmDialog = function (message, title, callbackYes, callbackNo, callbackArgument) {
/// <summary>
/// Generic confirmation dialog.
///
/// Usage:
/// $.ConfirmDialog('Do you want to continue?', 'Continue Title', function() { alert('yes'); }, function() { alert('no'); }, null);
/// $.ConfirmDialog('Do you want to continue?', 'Continue Title', function(arg) { alert('yes, ' + arg); }, function(arg) { alert('no, ' + arg); }, 'please');
///</summary>
///<param name="message" type="String">
/// The string message to display in the dialog.
///</param>
///<param name="title" type="String">
/// The string title to display in the top bar of the dialog.
///</param>
///<param name="callbackYes" type="Function">
/// The callback function when response is yes.
///</param>
///<param name="callbackNo" type="Function">
/// The callback function when response is no.
///</param>
///<param name="callbackNo" type="Object">
/// Optional parameter that is passed to either callback function.
///</param>
if ($("#modalConfirmDialog").length == 0)
$('body').append('<div id="modalConfirmDialog"></div>');
var dlg = $("#modalConfirmDialog")
.html(message)
.dialog({
autoOpen: false, // set this to false so we can manually open it
dialogClass: "confirmScreenWindow",
closeOnEscape: true,
draggable: false,
width: 460,
minHeight: 50,
modal: true,
resizable: false,
title: title,
buttons: {
Yes: function () {
if (callbackYes && typeof (callbackYes) === "function") {
if (callbackArgument == null) {
callbackYes();
} else {
callbackYes(callbackArgument);
}
}
$(this).dialog("close");
},
No: function () {
if (callbackNo && typeof (callbackNo) === "function") {
if (callbackArgument == null) {
callbackNo();
} else {
callbackNo(callbackArgument);
}
}
$(this).dialog("close");
}
}
});
dlg.dialog("open");
};