Skip to main content

Bug Tracker

Side navigation

Ticket #2889: eachBound.diff
File eachBound.diff, 2.0 KB (added by flesler, May 16, 2008 10:56PM UTC)
Index: src/core.js
===================================================================
--- src/core.js	(revision 5625)
+++ src/core.js	(working copy)
@@ -743,7 +743,24 @@
 
 		return object;
 	},
-
+	
+	// internal, node is the root
+	eachBound: function ( node, fn ){
+		var nodes = node.getElementsByTagName('*'),
+			index = nodes.length,
+			events;
+		
+		// add the root node itself
+		nodes[ index ] = node;
+		
+		do{
+			node = nodes[ index ];
+			if( node && node.nodeType == 1 && node[ expando ] && ( events = $.data(node, 'events') ) )
+				fn.call( node, events );
+				
+		}while( index-- );
+	},
+	
 	prop: function( elem, value, type, i, name ) {
 			// Handle executable functions
 			if ( jQuery.isFunction( value ) )
@@ -1303,7 +1320,7 @@
 	remove: function( selector ) {
 		if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) {
 			// Prevent memory leaks
-			jQuery( "*", this ).add(this).each(function(){
+			jQuery.eachBound( this, function(){
 				jQuery.event.remove(this);
 				jQuery.removeData(this);
 			});
Index: src/event.js
===================================================================
--- src/event.js	(revision 5625)
+++ src/event.js	(working copy)
@@ -167,8 +167,13 @@
 		// Handle a global trigger
 		if ( !elem ) {
 			// Only trigger if we've ever bound an event for it
-			if ( this.global[type] )
-				jQuery("*").add([window, document]).trigger(type, data);
+			if ( this.global[type] ){
+				jQuery.eachBound( document, function( events ){
+					if( events[type] )
+						jQuery.event.trigger( type, data, this, true );
+				});
+				jQuery.event.trigger( type, data, window, true );
+			}
 
 		// Handle triggering a single element
 		} else {
@@ -597,5 +602,7 @@
 // And prevent errors on refresh with events like mouseover in other browsers
 // Window isn't included so as not to unbind existing unload events
 jQuery(window).bind("unload", function() {
-	jQuery("*").add(document).unbind();
+	jQuery.eachBound( document, function(){
+		jQuery.event.remove(this);
+	});
 });

Download in other formats:

Original Format