Requesting a way to prepend an event handler

Requesting a way to prepend an event handler

Hi, I'm reposting this from  http://forum.jquery.com/topic/requesting-a-way-to-prepend-an-event-handler, which did not get any responses.

It appears that all of the event handler adding functions (on(), one(), etc) append to the list of handlers.  This can make it difficult to override other handlers that are already registered.  Could jQuery add a way to  prepend  to the handler list?

My use case is that I am creating a separate implementation of this jQuery-based drag/drop library:  http://threedubmedia.com/code/event/drag

That library has a very nice and flexible interface (check out its demos), but its implementation depends too much on jQuery internals and is hard to follow, so I created my own implementation of the same API:  https://github.com/haberman/jdragdrop

Unfortunately, there is one feature I cannot figure out how to implement without accessing private parts of jQuery.  Once a drag has begun, the user can choose to suppress the firing of the regular "click" handler when the mouse button comes back up.  The original library implements this by wrapping jQuery's own $.event.dispatch() function -- a big no no!  They use this wrapper to suppress click events when necessary.

I want to accomplish the same but sticking with public jQuery interfaces.  If I could prepend an event handler, this would be easy; I could just prepend a "click" event handler with one(), and in that handler call stopImmediatePropagation(). This would be clean and easy to implement.

The inability to prepend an event leads people do to very ugly things as workarounds.  Besides wrapping $.event.dispatch(), people sometimes muck around in $.data(elem, "events").  There is clearly a need for this, and providing an official function to prepend an event would keep people from messing around in jQuery internals.

Thanks,
Josh