Hey, after reading up a bit about event delegation vs. event handling
(http://icant.co.uk/sandbox/eventdelegation), I put together this
little bit:

  Object.extend(Event, {
    delegate: function(element, eventName, targetSelector, handler) {
      var element = $(element);
      element.observe(eventName, function(event){
        var origin = $(event.target);
        if ( origin.match(targetSelector) ){
          return handler(event);
        } else {
          event.stop();
        }
      })
    }
  })

  var ElementExtensions = {
    delegate: Event.delegate
  }

  Element.addMethods(ElementExtensions);

Now, I'm not the foremost expert on Prototype's event handling, but I
thought this was a nice little bit of syntactic sugar, and it seems to
work well enough. Do you think it's fit for core? (If so, I'd love to
clean it up and write some tests)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to