From 90d7b7f7087a4c18d3648775ba062e95aab9ff77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Fri, 19 Sep 2008 02:07:54 +0000 Subject: [PATCH] Dialog: Fixed #3087: Added beforeclose callback for dialogs (can prevent closing the dialog by returning false). --- tests/dialog.js | 24 ++++++++++++++++++++++++ ui/ui.dialog.js | 4 ++++ 2 files changed, 28 insertions(+) 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 = $('
').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 = $('
').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)