views:

100

answers:

1

I want to know when all of the events for a mouse event have fired.

For example, if I have registered listeners on document and an element, then click the element, i could get multiple events firing (more if the resultant events are bubbling).

How would i know when all events resulting from that click have completed?

This site provides one way of doing this -- they cluster mouse events into a list by updating the list with new events on a time interval. I was hoping for an automated way without a timer.

A: 

If you're just wanting to run some code after all the events have completed, you should use a timeout with a value of 0:

window.setTimeout(function ()
{
    // All events have finished, so we can run our code now
}, 0);

Timers in Javascript are run on the same thread, so they don't even count while other Javascript code is running. Setting a timer with a count of 0 will run when the thread becomes idle.

The site you mentioned doesn't update that list on a time interval - it actually updates that list every time the event fires using the handlers on all those objects. It's not possible to use a time interval to catch events.

Andy E
Thanks for your suggestion. It looks to me that ppk's site uses a timeout to cluster events onto a list (see log.end and how it is called).
jedierikb
No worries, glad I was some help. You are correct that log.end() is called from a timer. However log.msg() is the function that outputs to the list. log.end(), among other things, makes sure the log is scrolled to the bottom whenever an entry is added.
Andy E