aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2008-09-19 02:07:54 +0000
committerScott González <scott.gonzalez@gmail.com>2008-09-19 02:07:54 +0000
commit90d7b7f7087a4c18d3648775ba062e95aab9ff77 (patch)
tree946f1d52af13d452894df5d8dd61d24096547edc
parent7651fb4158018cac461ce008013f60e7fa0d5e54 (diff)
downloadjquery-ui-90d7b7f7087a4c18d3648775ba062e95aab9ff77.tar.gz
jquery-ui-90d7b7f7087a4c18d3648775ba062e95aab9ff77.zip
Dialog: Fixed #3087: Added beforeclose callback for dialogs (can prevent closing the dialog by returning false).
-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)