Commit 021b809a authored by John Resig's avatar John Resig

Make sure that the teardown is called after all the handlers of a type are removed. Fixes #6065.

parent 639f4931
...@@ -221,7 +221,7 @@ jQuery.event = { ...@@ -221,7 +221,7 @@ jQuery.event = {
} }
// remove generic event handler if no more handlers exist // 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 ) { if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) {
removeEvent( elem, type, elemData.handle ); removeEvent( elem, type, elemData.handle );
} }
......
...@@ -72,7 +72,7 @@ test("bind(), multiple events at once and namespaces", function() { ...@@ -72,7 +72,7 @@ test("bind(), multiple events at once and namespaces", function() {
}); });
test("bind(), namespace with special add", function() { test("bind(), namespace with special add", function() {
expect(18); expect(19);
var div = jQuery("<div/>").bind("test", function(e) { var div = jQuery("<div/>").bind("test", function(e) {
ok( true, "Test event fired." ); ok( true, "Test event fired." );
...@@ -87,7 +87,9 @@ test("bind(), namespace with special add", function() { ...@@ -87,7 +87,9 @@ test("bind(), namespace with special add", function() {
equals( e.target, div[0], "And that the target is correct." ); equals( e.target, div[0], "And that the target is correct." );
}, },
setup: function(){}, setup: function(){},
teardown: function(){}, teardown: function(){
ok(true, "Teardown called.");
},
add: function( handleObj ) { add: function( handleObj ) {
var handler = handleObj.handler; var handler = handleObj.handler;
handleObj.handler = function(e) { handleObj.handler = function(e) {
...@@ -116,6 +118,8 @@ test("bind(), namespace with special add", function() { ...@@ -116,6 +118,8 @@ test("bind(), namespace with special add", function() {
// Should trigger 2 // Should trigger 2
div.trigger("test.b"); div.trigger("test.b");
div.unbind("test");
}); });
test("bind(), no data", function() { test("bind(), no data", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment