Commit da966573 authored by jeresig's avatar jeresig

Make sure that elements that have been removed also have their special events...

Make sure that elements that have been removed also have their special events cleaned up. Fixes #6084.
parent 6a82f2ae
...@@ -112,6 +112,10 @@ jQuery.event = { ...@@ -112,6 +112,10 @@ jQuery.event = {
if ( special.add ) { if ( special.add ) {
special.add.call( elem, handleObj ); special.add.call( elem, handleObj );
if ( !handleObj.handler.guid ) {
handleObj.handler.guid = handler.guid;
}
} }
// Add the function to the element's handler list // Add the function to the element's handler list
......
...@@ -547,7 +547,7 @@ jQuery.extend({ ...@@ -547,7 +547,7 @@ jQuery.extend({
}, },
cleanData: function( elems ) { cleanData: function( elems ) {
var data, id, cache = jQuery.cache; var data, id, cache = jQuery.cache, special = jQuery.event.special;
for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) { for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
id = elem[ jQuery.expando ]; id = elem[ jQuery.expando ];
...@@ -556,8 +556,13 @@ jQuery.extend({ ...@@ -556,8 +556,13 @@ jQuery.extend({
data = cache[ id ]; data = cache[ id ];
if ( data.events ) { if ( data.events ) {
for ( var event in data.events ) { for ( var type in data.events ) {
removeEvent( elem, event, data.handle ); if ( special[ type ] ) {
jQuery.event.remove( elem, type );
} else {
removeEvent( elem, type, data.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(19); expect(24);
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." );
...@@ -97,7 +97,9 @@ test("bind(), namespace with special add", function() { ...@@ -97,7 +97,9 @@ test("bind(), namespace with special add", function() {
handler.apply( this, arguments ); handler.apply( this, arguments );
}; };
}, },
remove: function() {} remove: function() {
ok(true, "Remove called.");
}
}; };
div.bind("test.a", {x: 1}, function(e) { div.bind("test.a", {x: 1}, function(e) {
...@@ -119,7 +121,17 @@ test("bind(), namespace with special add", function() { ...@@ -119,7 +121,17 @@ test("bind(), namespace with special add", function() {
// Should trigger 2 // Should trigger 2
div.trigger("test.b"); div.trigger("test.b");
// Should trigger 4
div.unbind("test"); div.unbind("test");
div = jQuery("<div/>").bind("test", function(e) {
ok( true, "Test event fired." );
});
// Should trigger 2
div.appendTo("#main").remove();
delete jQuery.event.special.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