Skip to main content

Bug Tracker

Side navigation

#3662 closed feature (fixed)

Opened November 28, 2008 11:58PM UTC

Closed December 25, 2008 09:45PM UTC

Last modified December 31, 2008 02:59AM UTC

Add an Event class to jQuery

Reported by: flesler Owned by: flesler
Priority: major Milestone: 1.3
Component: event Version: 1.2.6
Keywords: Cc: john, brandon, joern, davidserduke
Blocked by: Blocking:
Description

While it's possible to pass custom event objects to jQuery.trigger, it's pretty complicated and lengthy to do that.

Also, there's no way to add custom attributes to the event objects when triggering (binding data is the closest).

In addition, this class could be used by both jQuery.event.fix and jQuery.trigger. Instead of creating literal objects with empty or custom methods (preventDefault,etc) we could have those in a prototype. That's much lighter than thousands of lambda functions.

This change breaks 2 old behaviors (on purpose).

  • It's not possible to pass an event object in the data array. It has to be passed as first argument, instead of the type, its 'type' will be used.
  • extra functions passed to jQuery.trigger won't get the event object (they used to get it if it was on the data array).

These are the new behaviors allowed:

$('#foo').trigger( new jQuery.Event('click') );
var e = new jQuery.Event('foo');
e.customAttr = 'bar';
$('#foo').trigger( e );
Attachments (3)
  • event-object[5953].diff (12.1 KB) - added by flesler November 28, 2008 11:58PM UTC.
  • event-object[5997].diff (10.1 KB) - added by flesler December 25, 2008 07:02PM UTC.

    Updated to new changes. Supports object literals as event objects (they're then copied to an actual instance)

  • event-object[6004].diff (10.6 KB) - added by flesler December 25, 2008 09:42PM UTC.

    This version makes all the tests pass, adds currentTarget attribute to event objects

Change History (5)

Changed November 28, 2008 11:59PM UTC by flesler comment:1

need: PatchCommit
status: newassigned

Changed November 29, 2008 12:06AM UTC by flesler comment:2

By the way, this is the native behavior of AS3 and probably EcmaScript something.

An event object is passed to dispatchEvent (trigger), not the type.

I think it's nice if we get closer to the standards.

Note that we already added event.stopImmediatePropagation().

Changed December 25, 2008 09:45PM UTC by flesler comment:3

resolution: → fixed
status: assignedclosed

Applied at [6005].

Changed December 29, 2008 09:59PM UTC by flesler comment:4

Since [6008], jQuery.Event can be instantiated without the 'new' operator, still optional.

Changed December 31, 2008 02:59AM UTC by flesler comment:5

[6016]

  • event objects have isDefaultPrevented, isPropagationStopped and isImmediatePropagationStopped methods.
  • Removed donative and dohandlers from $.trigger
  • event.result carries the last returned data from a handler(not undefined).
  • $.trigger doesn't keep bubbling if stopPropagation() is called.
  • Same event object is used all along for global trigger
  • Fixed the bug where target doesn't change when triggering on many elements.
  • The data array on $.trigger was accumulating objects as it bubbles.
  • adding more tests