#3662 closed feature (fixed)
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)
Change History (8)
Changed 14 years ago by
Attachment: | event-object[5953].diff added |
---|
comment:1 Changed 14 years ago by
need: | Patch → Commit |
---|---|
Status: | new → assigned |
comment:2 Changed 14 years ago by
Changed 14 years ago by
Attachment: | event-object[5997].diff added |
---|
Updated to new changes. Supports object literals as event objects (they're then copied to an actual instance)
Changed 14 years ago by
Attachment: | event-object[6004].diff added |
---|
This version makes all the tests pass, adds currentTarget attribute to event objects
comment:4 Changed 14 years ago by
Since [6008], jQuery.Event can be instantiated without the 'new' operator, still optional.
comment:5 Changed 14 years ago by
- 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
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().