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:00PM UTC by comment:1
Changed April 13, 2009 07:29PM UTC by comment:2
Here's a very simple demo page:
Changed April 13, 2009 11:32PM UTC by 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 comment:4
component: | unfilled → event |
---|---|
owner: | → brandon |
Changed April 30, 2009 09:50PM UTC by comment:5
resolution: | → fixed |
---|---|
status: | new → closed |
fixed in r6325
Also brought up here:
http://groups.google.com/group/jquery-en/browse_thread/thread/de524c310248a7d2/b1b8c095badd0a0b?lnk=gst&q=live+event+data#b1b8c095badd0a0b