Fix mishandling of events.

In some situations the "click" events were not stopped properly and the underlying actions failed
(specifically when using external JS libraries).