From 021b809acecc4e94613375b3182c86722470fe9b Mon Sep 17 00:00:00 2001 From: John Resig Date: Thu, 11 Feb 2010 01:42:51 -0500 Subject: [PATCH] Make sure that the teardown is called after all the handlers of a type are removed. Fixes #6065. --- src/event.js | 2 +- test/unit/event.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/event.js b/src/event.js index 2e510eabf..e15a2ea63 100644 --- a/src/event.js +++ b/src/event.js @@ -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 ); } diff --git a/test/unit/event.js b/test/unit/event.js index e85c4bd9d..33329c311 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -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("
").bind("test", function(e) { ok( true, "Test event fired." ); @@ -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) { @@ -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() { -- 2.39.5