#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:1 Changed 14 years ago by
comment:3 Changed 14 years ago by
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 14 years ago by
Component: | unfilled → event |
---|---|
Owner: | set to brandon |
Note: See
TracTickets for help on using
tickets.
Also brought up here:
http://groups.google.com/group/jquery-en/browse_thread/thread/de524c310248a7d2/b1b8c095badd0a0b?lnk=gst&q=live+event+data#b1b8c095badd0a0b