Skip to main content

Bug Tracker

Side navigation

#923 closed bug (fixed)

Opened February 07, 2007 12:45AM UTC

Closed May 31, 2007 03:54AM UTC

Last modified June 21, 2007 03:27AM UTC

Global triggers can execute handlers multiple times

Reported by: jchaffer@gmail.com Owned by:
Priority: minor Milestone: 1.1.3
Component: event Version:
Keywords: Cc:
Blocked by: Blocking:
Description

If two global handlers for the same event type are attached to the same element, the handlers will each fire twice. For example:

$('#foo').ajaxComplete(function() {

alert('foo');

});

$('#foo').ajaxComplete(function() {

alert('bar');

});

When a request completes, we will see four alerts, not two.

This is due to the flow of "trigger: function(type, data, element)". This calls .trigger() on each element, which in turn calls each handler. To fix, the function probably needs to first winnow the matched elements down to a unique set before the recursive call to .trigger().

Attachments (0)
Change History (2)

Changed May 01, 2007 04:46PM UTC by brandon comment:1

milestone: → 1.1.3
need: → Test Case

Changed May 31, 2007 03:54AM UTC by brandon comment:2

description: If two global handlers for the same event type are attached to the same element, the handlers will each fire twice. For example:\ \ $('#foo').ajaxComplete(function() {\ alert('foo');\ });\ $('#foo').ajaxComplete(function() {\ alert('bar');\ });\ \ When a request completes, we will see four alerts, not two.\ \ This is due to the flow of "trigger: function(type, data, element)". This calls .trigger() on each element, which in turn calls each handler. To fix, the function probably needs to first winnow the matched elements down to a unique set before the recursive call to .trigger().If two global handlers for the same event type are attached to the same element, the handlers will each fire twice. For example: \ \ $('#foo').ajaxComplete(function() { \ alert('foo'); \ }); \ $('#foo').ajaxComplete(function() { \ alert('bar'); \ }); \ \ When a request completes, we will see four alerts, not two. \ \ This is due to the flow of "trigger: function(type, data, element)". This calls .trigger() on each element, which in turn calls each handler. To fix, the function probably needs to first winnow the matched elements down to a unique set before the recursive call to .trigger().
resolution: → fixed
status: newclosed

This is now fixed in Rev [2011].