Bug Tracker

Ticket #3112 (closed bug: fixed)

Opened 6 years ago

Last modified 6 years ago

Special Events Data

Reported by: mike.helgeson Owned by: flesler
Priority: major Milestone: 1.3
Component: event Version: 1.2.6
Keywords: Cc:
Blocking: Blocked by:

Description

I would like to request that the special event setup function calls get passed the data parameter as a means to configuring the special event. The change would be made on line 1883 of 1.2.6:

if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) {

would become

if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem,data) === false ) {

Change History

comment:1 Changed 6 years ago by flesler

  • need changed from Review to Test Case

Note that data can is undefined most of the time, and it is shared for all the events bound together.

Can you provide a situation where this is useful ?

comment:2 Changed 6 years ago by mike.helgeso

I have a special event implementation of the "hoverIntent" plugin, and there are two options that are configurable (delay,speed). Currently, these options are only configurable document wide as they are attributes of the special event object. By leveraging the data parameter into the special event setup, I can extract custom settings within the setup function. The setup attaches mouseenter and mouseleave handlers and already uses the data param internally to share variables between the handlers. Personally, I don't plan on customizing the settings of this event per call, but such a small change would open a lot of possibilities. I understand that the data object is shared by all of the bound events, and while that may be a pitfall for some, I think it could also be cleverly powerful. In reality, it will most likely not be used by many developers, because as you said, data is undefined most of the time.

comment:3 Changed 6 years ago by flesler

  • need changed from Test Case to Patch
  • Owner set to brandon

I'll let Brandon decide on this (he's busy right now) as he added the special events feature.

comment:4 Changed 6 years ago by flesler

  • need changed from Patch to Commit
  • Owner changed from brandon to flesler
  • Type changed from enhancement to bug
  • Status changed from new to assigned
  • Priority changed from trivial to major

Actually, this is a bug. Right now, it isn't possible to bind data to any special special.

comment:5 Changed 6 years ago by flesler

  • Status changed from assigned to closed
  • Resolution set to fixed

Fixed at [5777].

comment:6 Changed 6 years ago by flesler

Actually, binding 'data' to a mouseenter/mouseleave was working without this change. As the data goes with the handler.

Still, this is a small change, I see no need to revert for now.

comment:7 Changed 6 years ago by mike.helgeso

Right, you are correct that the data always gets passed to the event handler, and there was never any problem with passing the data to special events. By additionally passing the data to the special event setup function, we are not fixing a bug, but opening up the possibility of more advanced event customization though this data transmission, without the need to make any other api changes.

Note: See TracTickets for help on using tickets.