Bug Tracker

Opened 13 years ago

Closed 12 years ago

#6738 closed bug (invalid)

Global events that are namespaced do not trigger correctly.

Reported by: swalke16 Owned by:
Priority: low Milestone:
Component: event Version: 1.4.2
Keywords: global namespaced events Cc:
Blocked by: Blocking:


If I have a global event that is namespaced such as in the following gist:


It will never be triggered.

Looking at the code, the $.bind function keeps track of all events used in a global array in this line:

Keep track of which events have been used, for global triggering jQuery.event.global[ type ] = true;

Firstly it seems like this should be used only for global events, but in any case the type used here is without the namespace.

When triggering the event the following code in the trigger function will not work:

Only trigger if we've ever bound an event for it if ( jQuery.event.global[ type ] ) {

jQuery.each( jQuery.cache, function() {

if ( this.events && this.events[type]) {

jQuery.event.trigger( event, data,

this.handle.elem );




First problem is that in the first line of this code, the type value still contains the namespace and so won't match the way that bind was storing this value in the global array without namespace.

If we simply fix that problem, the event will be fired, but exposes another problem in that the if statement inside the anonymous function passed to the .each() does not check to see if the namespace matches before triggering the event.

This clearly seems like a bug that needs to be fixed.

Change History (3)

comment:1 Changed 12 years ago by boushley

Here is a fiddle that is basically the test case from the gist, although I removed the animations and things to make it a bit simpler. http://jsfiddle.net/boushley/ZZ25f/ I think this bug is valid, however I think it is probably low priority as namespaced events firing on the global context probably don't affect a large portion of the user base.

comment:2 Changed 12 years ago by SlexAxton

Priority: low
Status: newopen

Sounds like a fair assessment, thanks for the fiddle. Adding.

comment:3 Changed 12 years ago by dmethvin

Resolution: invalid
Status: openclosed

jQuery doesn't support external calls to jQuery.event.trigger() in order to trigger a global event. That is not a documented interface.

Note: See TracTickets for help on using tickets.