Skip to content
This repository

Fire custom events vs delegation #2484

Closed
inkstak opened this Issue · 3 comments

3 participants

Savater Sebastien Garrick Cheung Mario Ruiz
Savater Sebastien

Hi,

Am trying to play with delegations and custom events, but no way to catch them.

$(document.body).addEvent('show:relay(div)', function() {
  $$('pre').appendText("relay show\n");
});

$$('div').setStyle('display', 'block').fireEvent('show')

Should I have to pass an event object when firing the custom event ?
You can get a Fiddle here : http://jsfiddle.net/z2LqR/1/

Garrick Cheung
Collaborator

Your example shows that you have two show event handlers attached div elements and document.body element.

In order to trigger the show delegated event on the document.body you must fire the event on the object, and pass it the correct arguments. Here's the example working with delegated events: http://jsfiddle.net/z2LqR/2/

As you can see, the event object from anchors click event (not delegated) and the div element is passed as arguments to fireEvent method of the document.body. I hope this helps.

If this works, please close the ticket.

Savater Sebastien

Hi,

Thanks for your answer (I just saw it today, with 2 months late).
You're solution is right. that means the issue can be closed.

However, I suggest to update the docs on http://mootools.net/docs/core/Element/Element.Delegation about how linking delegation and FireEvent.

Savater Sebastien inkstak closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.