]> source.dussan.org Git - jquery.git/commitdiff
Make sure that elements that have been removed also have their special events cleaned...
authorjeresig <jeresig@gmail.com>
Sat, 13 Feb 2010 11:10:43 +0000 (06:10 -0500)
committerjeresig <jeresig@gmail.com>
Sat, 13 Feb 2010 11:10:43 +0000 (06:10 -0500)
src/event.js
src/manipulation.js
test/unit/event.js

index 6e65438ace26731e83de0faba513e7cd19c71f19..d91231e8683ee99d7d1e042a04f98c5473f6a963 100644 (file)
@@ -112,6 +112,10 @@ jQuery.event = {
                        
                        if ( special.add ) { 
                                special.add.call( elem, handleObj ); 
+
+                               if ( !handleObj.handler.guid ) {
+                                       handleObj.handler.guid = handler.guid;
+                               }
                        }
 
                        // Add the function to the element's handler list
index a58e52b6a8b0b57084d6d9035ae556d650283727..4e7a31ed4120400d22c594323e533864f7bc10fe 100644 (file)
@@ -547,7 +547,7 @@ jQuery.extend({
        },
        
        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++ ) {
                        id = elem[ jQuery.expando ];
@@ -556,8 +556,13 @@ jQuery.extend({
                                data = cache[ id ];
                                
                                if ( data.events ) {
-                                       for ( var event in data.events ) {
-                                               removeEvent( elem, event, data.handle );
+                                       for ( var type in data.events ) {
+                                               if ( special[ type ] ) {
+                                                       jQuery.event.remove( elem, type );
+
+                                               } else {
+                                                       removeEvent( elem, type, data.handle );
+                                               }
                                        }
                                }
                                
index 21167c7de2177beb1673e9f9a86e726caf455a10..7d66c9ca2116ca9992eb8b7d04413160f354cb26 100644 (file)
@@ -72,7 +72,7 @@ test("bind(), multiple events at once and namespaces", function() {
 });
 
 test("bind(), namespace with special add", function() {
-       expect(19);
+       expect(24);
 
        var div = jQuery("<div/>").bind("test", function(e) {
                ok( true, "Test event fired." );
@@ -97,7 +97,9 @@ test("bind(), namespace with special add", function() {
                                handler.apply( this, arguments );
                        };
                },
-               remove: function() {}
+               remove: function() {
+                       ok(true, "Remove called.");
+               }
        };
 
        div.bind("test.a", {x: 1}, function(e) {
@@ -119,7 +121,17 @@ test("bind(), namespace with special add", function() {
        // Should trigger 2
        div.trigger("test.b");
 
+       // Should trigger 4
        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() {