Skip to content

Commit 021b809

Browse files
committed
Make sure that the teardown is called after all the handlers of a type are removed. Fixes #6065.
1 parent 639f493 commit 021b809

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ jQuery.event = {
221221
}
222222

223223
// remove generic event handler if no more handlers exist
224-
if ( jQuery.isEmptyObject( events[ type ] ) ) {
224+
if ( eventType.length === 0 || pos != null && eventType.length === 1 ) {
225225
if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) {
226226
removeEvent( elem, type, elemData.handle );
227227
}

test/unit/event.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ test("bind(), multiple events at once and namespaces", function() {
7272
});
7373

7474
test("bind(), namespace with special add", function() {
75-
expect(18);
75+
expect(19);
7676

7777
var div = jQuery("<div/>").bind("test", function(e) {
7878
ok( true, "Test event fired." );
@@ -87,7 +87,9 @@ test("bind(), namespace with special add", function() {
8787
equals( e.target, div[0], "And that the target is correct." );
8888
},
8989
setup: function(){},
90-
teardown: function(){},
90+
teardown: function(){
91+
ok(true, "Teardown called.");
92+
},
9193
add: function( handleObj ) {
9294
var handler = handleObj.handler;
9395
handleObj.handler = function(e) {
@@ -116,6 +118,8 @@ test("bind(), namespace with special add", function() {
116118

117119
// Should trigger 2
118120
div.trigger("test.b");
121+
122+
div.unbind("test");
119123
});
120124

121125
test("bind(), no data", function() {

0 commit comments

Comments
 (0)