we're working on a big web application and using prototype as well as
jQuery, both are needed due to dependencies on plugins, frameworks and
so on.
One specific framework, Tapestry to name it, uses prototype and
registers a click handler on each element, when clicked the event is
stopped and a custom event is thrown which then gets processed and
does the communication with the server.
We show parts of an entity on a page in different sections and use
optimistic locking. To prevent concurrent modification exceptions we'd
like to set one section in edit mode and prevent all outside elements
from being clicked. My problem is now that there're already click
handler on each element and there's no way i can run a JS before that
handler are registered. My first attempt was to resort the handler as
i already did something similar in jQuery and it worked just fine by
reading and manipulating the results of data('events').
In prototype i found this to read the handler:
var registry = Element.retrieve($(element),
if(registry) {
        var responders = registry.get('click');
        //insert new handler here
        responders = responders.reverse();
Even that's not the clean solution i'd want (preferably i'd like to
insert a new handler up front) i could live with that, regrettably
prototype isn't impressed by this solution and just ignores the order.
So my second approach was to still read the responders but instead of
inserting my new handler i first call stopObserving('click') to
unregister them all, then i register my new handler and subsequent the
earlier registered ones.

Any suggestions how to solve this kind of problem cleaner/faster/the
right way would be highly appreciated.
IMHO this problem shouldn't be new or unique as i'd guess it's quite
common that a later handler needs to prevent earlier registered ones
from running without removing them.

So the resorting at least kinda works as described above (copy
responders, unregister all, register new, register old, still
hopefully someone can come up with a better solution), 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. In
it's code there's even a call to event.stopPropagation() so i'd assume
it does so but it doesn't? Is it the wanted and expected behaviour
that stop doesn't prevent all subsequent handlers from also getting
the event?
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

Thanks for reading such a long post and even more for answering.

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to