Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#4532 closed bug (fixed)

Live event handlers don't receive custom event data

Reported by: nbubna Owned by: brandon
Priority: major Milestone: 1.4
Component: event Version: 1.3.2
Keywords: live, event, data Cc:
Blocked by: Blocking:

Description

$('.foo').live("foo", function(e, bar) {

alert(bar);

});

$('.foo').trigger("foo", bar?);

Does not alert "bar". Instead, it alerts ".foo" or some such selector. The custom data gets squashed by the jQuery.fn.live implementation. :( I can see where it happens, but i'm not sure how to fix it (yet).

Change History (6)

comment:2 Changed 11 years ago by nbubna

Here's a very simple demo page:

http://closertohere.com/script/4532.html

comment:3 Changed 11 years ago by nbubna

liveHandler is busted. it should look more like this:

function liveHandler( event ){
	var check = RegExp("(^|\\.)" + event.type + "(\\.|$)"),
		stop = true,
		elems = [];

	jQuery.each(jQuery.data(this, "events").live || [], function(i, fn){
		if ( check.test(fn.type) ) {
			var elem = jQuery(event.target).closest(fn.data)[0];
			if ( elem )
				elems.push({ elem: elem, fn: fn });
		}
	});

	elems.sort(function(a,b) {
		return jQuery.data(a.elem, "closest") - jQuery.data(b.elem, "closest");
	});
	var args = arguments;
	jQuery.each(elems, function(){
		if ( this.fn.apply(this.elem, args) === false )
			return (stop = false);
	});

	return stop;
}

The key part being that you apply the function with the arguments given to liveHandler, not with this.fn.data.

comment:4 Changed 11 years ago by dmethvin

Component: unfilledevent
Owner: set to brandon

comment:5 Changed 11 years ago by brandon

Resolution: fixed
Status: newclosed

fixed in r6325

comment:6 Changed 9 years ago by dmethvin

#5675 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.