Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bootstrap Modal Dialog plugin for jQuery
jQuery.showDialog = function (options) {
var settings = $.extend({
confirm: true,
message: "Hurahhh!!!",
success: function () { },
cancel: function () { }
}, options);
var clickedOK = false;
var html = '<div class="modal fade" id="modalDialog" tabindex="-1" role="dialog"> ' +
' <div class="modal-dialog modal-sm"> ' +
' <div class="modal-content"> ' +
' <div class="modal-body"> ' +
settings.message +
' </div> ' +
' <div class="modal-footer"> ';
if (settings.confirm == true) {
html += ' <button type="button" class="btn btn-default" data-dismiss="modal">NO</button> ' +
' <button type="button" id="btnYES" class="btn btn-primary">YES</button> ';
} else {
html += ' <button type="button" class="btn btn-primary" data-dismiss="modal">OK</button> ';
}
html += ' </div> ' +
' </div> ' +
' </div> ' +
'</div> ';
$("body").append(html);
$("#modalDialog").modal().on('hidden.bs.modal', function () {
$("#modalDialog").remove();
if (!clickedOK) {
settings.cancel();
} else {
settings.success();
}
});
$("#modalDialog").on("click", "#btnYES", function () {
clickedOK = true;
$('#modalDialog').modal('hide');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.