Ticket #9314 (closed enhancement: wontfix)
Ability to wrap DOM events to become jQuery events
| Reported by: | wheresrhys | Owned by: | wheresrhys |
|---|---|---|---|
| Priority: | low | Milestone: | 1.7 |
| Component: | event | Version: | 1.6.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description (last modified by rwaldron) (diff)
It'd be useful to be able to wrap DOM events in a jQuery wrapper, so
$.Event(event) = event which can be manipulated using the jQuery api.
I've come across the need to have this functionality recently when using Raphael.js. Say I have an event handler that can be triggered by clicking either a canvas element (event handled using Raphael) or a list item, (click handled using jQuery), then I have to write some convoluted code in order to handle both types of event. If there was a way to wrap events then I could simply use one line of code, something like
if (!event.jqueryEvent) { event = $.Event(event); }
... before continuing using the jQuery API
Change History
comment:1 Changed 2 years ago by dmethvin
- Owner set to wheresrhys
- Status changed from new to pending
comment:2 Changed 2 years ago by wheresrhys
- Status changed from pending to new
I've created a non-functioning jsFiddle to illustrate the difference it could make: http://jsfiddle.net/wheresrhys/J8Cym/1/. Let me know if you need further clarification
comment:3 Changed 2 years ago by rwaldron
- Status changed from new to pending
- Component changed from unfiled to event
Saw these updates just now, I was actually in the middle of creating a RaphaelJS + jQuery boilerplate for you to illustrate overlapping events:
http://jsfiddle.net/rwaldron/bpWVM/
just "fork" and create your example.
comment:4 Changed 2 years ago by wheresrhys
- Status changed from pending to new
OK, this hopefully illustrates why the ability to wrap native DOM events would be useful
http://jsfiddle.net/wheresrhys/E4NZW/
In a nutshell, other js libraries (in this case Raphael) use native DOM events, and if you want to write a handler it'd be nice to be able to call in the first line a jQuery method that takesa native DOM event/jquery event object, adn returns a jQuery event object so you can use the API no matter what library was used to attach the handler (provided the other library hasn't already wrapped the event in its own wrapper).
comment:5 follow-up: ↓ 10 Changed 2 years ago by dmethvin
- Status changed from new to pending
So is this what you are looking for?
comment:6 Changed 2 years ago by john
- Keywords 1.7-discuss added
Nominating ticket for 1.7 discussion.
comment:10 in reply to: ↑ 5 Changed 2 years ago by wheresrhys
- Status changed from pending to new
Replying to dmethvin:
So is this what you are looking for?
Yep - something like that syntax, although the
if ( !(ev instanceof $.Event) )
check could be included inside the $.Event() method to make it an even easier API.
comment:11 Changed 2 years ago by timmywil
- Priority changed from undecided to low
- Status changed from new to open
- Description modified (diff)
comment:12 Changed 2 years ago by dmethvin
-1, How would jQuery do this? Raphael is delivering the event directly to myHandler, so how would we intervene to convert it to a jQuery event?
comment:13 Changed 2 years ago by rwaldron
I think this is not reasonable
comment:15 Changed 2 years ago by ajpiano
- Description modified (diff)
-1, I sympathise with the request, but I think that Dave's suggestion (or your own genericisation of) that approach is certainly reasonable, we can't "intercept" the Raphael event.. You don't even have to do the instanceof check, you can just unconditionally transform it into a jQuery event if you know that that will always be necessary.
comment:16 Changed 2 years ago by scott.gonzalez
- Description modified (diff)
+0, isn't this exactly what $.event.fix does?
comment:17 Changed 2 years ago by rwaldron
- Keywords 1.7-discuss removed
- Status changed from open to closed
- Resolution set to wontfix
- Description modified (diff)
- Milestone changed from 1.next to 1.7
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Can you provide some more description of what you mean?