Hi,
The fundamental answer here is: Relying on the order in which event
handlers are triggered is usually not a good design decision. Rather
than spending time trying to get it working, I'd spend time finding a
completely different way to solve the problem if at all possible.
Unlike jQuery, Prototype doesn't guarantee the order in which event
handlers are fired. When you attach an event handler with Prototype,
it really calls addEventListener/attachEvent for your specific handler
(after putting a wrapper around it), and so the order in which the
handlers are called is determined by the browser implementation.
Unfortunately, different browsers do different things. *Most* browsers
(Chrome, Firefox, Safari, Opera, IE9+ [if in standards mode]) fire
handlers in the order in which they were attached (FIFO); some
browsers (IE6, IE7, IE8) fire them in reverse order (LIFO).
jQuery addresses that by only attaching a single handler for each
event to each element; if you attach further handlers, jQuery chains
them *itself* rather than relying on the browser to do it. Prototype
doesn't do that.
> ...when i'm
> running the scripts my handler comes first but doesn't prevent the
> other handlers to run. Do i misinterpret the event.stop() method.
No, `event.stop` is meant to both stop propagation and prevent the
default action -- and it does, in the normal case.
> Weirdly, subsequent handler don't get the event when i call
> event.stopImmediatePropagation(); from within my first prototype
> handler. I'm writing weirdly cause i couldn't find any documentation
> about stopImmediatePropagation() except in jQuery, any explanation to
> this?
stopImmediatePropagation is a jQuery-only thing. If you're calling it
from within a Prototype handler, you're presumably causing an
exception by trying to call a function that doesn't exist. I can't see
why that would prevent other handlers from running.
So trying to address this with order-of-handlers is going to be a mess
and I don't recommend it. There has to be another solution.
However, if you're going to go down the order-of-handlers route, one
option would be to use a modified version of Prototype that actually
uses jQuery to hook up the handlers. This would be non-trivial, but
possible. The event object jQuery passes into handlers has access to
the "raw" event object as `event.originalEvent`, so it would be
possible for you to modify Prototype so that it inserts a wrapper
handler that receives the jQuery event object, uses Prototype to
extend the `event.originalEvent` object, and then fires the handler
using that. But it will get complicated fast (not least around
`stopObserving`).
Good luck,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com