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?
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