Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

showDialog deferreds example

View exampleUse.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$(function () {
$("#deleteAll").click(function () {
$.showDialog("You will lose all your data if you continue.")
.then(function (result) {
if (result) {
$.showDialog("Losing your data is permanent and cannot be restored. Are you sure?", "Loss is permanent", "Yes", "No")
.then(function (result) {
if (result) {
alert("all data lost!");
}
});
}
});
});
});
View exampleUse.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
(function ($, undefined) {
$.showDialog = function (msg, title, okTxt, cancelTxt) {
title = title || "Warning";
okTxt = okTxt || "OK";
cancelTxt = cancelTxt || "Cancel";
var dfd = $.Deferred(),
$dialog = $("<div></div>")
.html(msg)
.dialog({
autoOpen: false,
title: title,
modal: true,
buttons: [
{
text: okTxt,
click: function () {
dfd.resolve(true);
$(this).dialog("close");
}
},
{
text: cancelTxt,
click: function () {
dfd.resolve(false);
$(this).dialog("close");
}
}
],
close: function (event, ui) {
if (!dfd.isResolved()) {
dfd.reject();
}
}
});
$dialog.dialog("open");
return dfd;
};
}(jQuery));
Owner

Example of using jQuery deferreds by implementing showDialog similar to the old MessageBox.Show in winforms development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.