Dialog: Fixed #3087: Added beforeclose callback for dialogs (can prevent closing the dialog by returning false).

This commit is contained in:
Scott González 2008-09-19 02:07:54 +00:00
parent 7651fb4158
commit 90d7b7f708
2 changed files with 28 additions and 0 deletions

View File

@ -622,6 +622,30 @@ test("close", function() {
el.remove(); el.remove();
}); });
test("beforeclose", function() {
expect(6);
el = $('<div/>').dialog({
beforeclose: function(ev, ui) {
ok(true, '.dialog("close") fires beforeclose callback');
equals(this, el[0], "context of callback");
return false;
}
});
el.dialog('close');
isOpen('beforeclose callback should prevent dialog from closing');
el.remove();
el = $('<div/>').dialog().bind('dialogbeforeclose', function(ev, ui) {
ok(true, '.dialog("close") triggers dialogbeforeclose event');
equals(this, el[0], "context of event");
return false;
});
el.dialog('close');
isOpen('dialogbeforeclose event should prevent dialog from closing');
el.remove();
});
module("dialog: Tickets"); module("dialog: Tickets");
})(jQuery); })(jQuery);

View File

@ -135,6 +135,10 @@ $.widget("ui.dialog", {
}, },
close: function() { close: function() {
if (false === this._trigger('beforeclose', null, { options: this.options })) {
return;
}
(this.overlay && this.overlay.destroy()); (this.overlay && this.overlay.destroy());
this.uiDialog this.uiDialog
.hide(this.options.hide) .hide(this.options.hide)