Skip to content

Commit

Permalink
Make sure that the teardown is called after all the handlers of a typ…
Browse files Browse the repository at this point in the history
…e are removed. Fixes #6065.
  • Loading branch information
jeresig committed Feb 11, 2010
1 parent 639f493 commit 021b809
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/event.js
Expand Up @@ -221,7 +221,7 @@ jQuery.event = {
}

// remove generic event handler if no more handlers exist
if ( jQuery.isEmptyObject( events[ type ] ) ) {
if ( eventType.length === 0 || pos != null && eventType.length === 1 ) {
if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) {
removeEvent( elem, type, elemData.handle );
}
Expand Down
8 changes: 6 additions & 2 deletions test/unit/event.js
Expand Up @@ -72,7 +72,7 @@ test("bind(), multiple events at once and namespaces", function() {
});

test("bind(), namespace with special add", function() {
expect(18);
expect(19);

var div = jQuery("<div/>").bind("test", function(e) {
ok( true, "Test event fired." );
Expand All @@ -87,7 +87,9 @@ test("bind(), namespace with special add", function() {
equals( e.target, div[0], "And that the target is correct." );
},
setup: function(){},
teardown: function(){},
teardown: function(){
ok(true, "Teardown called.");
},
add: function( handleObj ) {
var handler = handleObj.handler;
handleObj.handler = function(e) {
Expand Down Expand Up @@ -116,6 +118,8 @@ test("bind(), namespace with special add", function() {

// Should trigger 2
div.trigger("test.b");

div.unbind("test");
});

test("bind(), no data", function() {
Expand Down

0 comments on commit 021b809

Please sign in to comment.