Side navigation
#2249 closed enhancement (fixed)
Opened January 28, 2008 08:38PM UTC
Closed April 29, 2008 11:35PM UTC
Last modified May 19, 2008 10:42PM UTC
Addition of "once" event handler
Reported by: | bfattori | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.2.4 |
Component: | event | Version: | 1.2.2 |
Keywords: | once,one,bind,events | Cc: | |
Blocked by: | Blocking: |
Description
The following code will assign an event, and then unbind that event immediately after assignment. Similar in effect to "one", however "one" will unbind all events bound to the type. "once" will only unbind the event passed.
/** * Similar in effect to using one() to bind an event to fire once and be * removed, however this will only remove the handler you assign. Any * handlers already assigned to the event will not be removed as one() does. */ once: function(type, data, fn) { return this.each(function(){ jQuery.event.add( this, type, function(event) { jQuery(this).unbind(event, arguments.callee); return (fn || data).apply( this, arguments); }, data); }); }
Attachments (3)
Change History (9)
Changed January 28, 2008 08:39PM UTC by comment:1
Changed March 17, 2008 11:24PM UTC by comment:2
I think this is actually a bug of jQuery, IMO one should only unbind the recently bound function.
Changed March 28, 2008 01:45PM UTC by comment:3
I have one more suggestion about "one" function: currently it isn't possible to unbind function bound using one(), i.e. unbind in the following code doesn't work:
function test() { alert("test"); } $(document).one("click", test); $(document).unbind("click", test);
I guess it would be good to have the ability to unbind "one" event handlers.
Changed March 29, 2008 03:29PM UTC by comment:4
It might also be used for jQuery.fn._toggle, mapping both (or more) functions, to the bound click handler.
Changed April 29, 2008 10:07PM UTC by comment:5
Fixed and implemented $.event.proxy at [5352]
Changed April 29, 2008 11:35PM UTC by comment:6
resolution: | → fixed |
---|---|
status: | new → closed |
Fixed in [5352].
Changed May 13, 2008 05:43PM UTC by comment:7
milestone: | 1.2.3 → 1.2.4 |
---|
Changed May 19, 2008 10:28PM UTC by comment:8
It seems that the fix for this [source:tags/1.2.4/src/event.js#L403 didn't actually make it into v1.2.4], so I'd suggest changing the milestone to avoid confusing others like myself (who actually that this ''was'' fixed in v1.2.4).
Changed May 19, 2008 10:42PM UTC by comment:9
Replying to [comment:8 aheimlich]:
(who actually that this ''was'' fixed in v1.2.4).
duurrrr....
That should have been: (who actually thought that this ''was'' fixed in v1.2.4).
Crap... I hate that I cannot edit my ticket! It doesn't unbind after ''assignment'', but after ''execution''
Sheesh... =)