Permalink
Browse files
Dialog: Fixed #3087: Added beforeclose callback for dialogs (can prev…
…ent closing the dialog by returning false).
- Loading branch information
Showing
with
28 additions
and
0 deletions.
-
+24
−0
tests/dialog.js
-
+4
−0
ui/ui.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); |
|
|
@@ -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) |
|
|
|