Skip to main content

Bug Tracker

Side navigation

#4532 closed bug (fixed)

Opened April 13, 2009 06:58PM UTC

Closed April 30, 2009 09:50PM UTC

Last modified November 20, 2010 02:41PM UTC

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).

Attachments (0)
Change History (6)

Changed April 13, 2009 07:29PM UTC by nbubna comment:2

Here's a very simple demo page:

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

Changed April 13, 2009 11:32PM UTC by nbubna comment:3

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.

Changed April 14, 2009 04:13PM UTC by dmethvin comment:4

component: unfilledevent
owner: → brandon

Changed April 30, 2009 09:50PM UTC by brandon comment:5

resolution: → fixed
status: newclosed

fixed in r6325

Changed November 20, 2010 02:41PM UTC by dmethvin comment:6

#5675 is a duplicate of this ticket.