aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/dialog.js24
-rw-r--r--ui/ui.dialog.js4
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/dialog.js b/tests/dialog.js
index 85b744cb1..b5fbfa6ee 100644
--- a/tests/dialog.js
+++ b/tests/dialog.js
@@ -622,6 +622,30 @@ test("close", function() {
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");
})(jQuery);
diff --git a/ui/ui.dialog.js b/ui/ui.dialog.js
index 57bad1193..cc4f37762 100644
--- a/ui/ui.dialog.js
+++ b/ui/ui.dialog.js
@@ -135,6 +135,10 @@ $.widget("ui.dialog", {
},
close: function() {
+ if (false === this._trigger('beforeclose', null, { options: this.options })) {
+ return;
+ }
+
(this.overlay && this.overlay.destroy());
this.uiDialog
.hide(this.options.hide)