I've attached a patch that introduces the beginnings of event delegation to Prototype. The syntax is quite similar to that of Event.observe, with the only difference being an additional parameter that contains a CSS selector. This selector is used to check whether or not an element should receive the delegated handler.
Here's an example of its use. The following code will cause the onclick event for child elements of $('all') to be handled by the Behaviors.cancel handler, as long as they have the class name "cancel". This is beneficial, as obviously any elements that are added to the page dynamically will still receive this behavior, without any sort of handler refresh necessary.
var Behaviors = {
cancel: function(event){
event.stop()
}
}
$('all').delegate('click', '.cancel', Behaviors.cancel)
My implementation of Event.delegate only handles events that bubble, therefore "onsubmit" is woefully missing (until I get around to simulating it via a custom event). It's also missing the ability to unregister delegators, though I wonder if that might be alright for now, since delegators probably don't need to be created/destroyed nearly as frequently as handlers.
I added two new tests to the unit tests for Event, though I'm a bit new to unit testing for Javascript libraries, and the coverage could probably be improved. Any help here would be terrific.