Fixed a bug where events are propagated to document from $events

This is to fix the issue reported in #525. I have tested this on my own site and found that the event handler is executed only once, correctly.