Bug Tracker

Modify

Ticket #6738 (closed bug: invalid)

Opened 4 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

Description

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

 https://gist.github.com/1b1c48ed39f679c77fc4

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

comment:1 Changed 3 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 3 years ago by SlexAxton

  • Priority set to low
  • Status changed from new to open
  • Milestone changed from 1.4.3 to 1.5

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

comment:3 Changed 3 years ago by dmethvin

  • Status changed from open to closed
  • Resolution set to invalid

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.