Bug Tracker

Opened 9 years ago

Closed 9 years ago

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

Description (last modified by Rick Waldron)

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 (17)

comment:1 Changed 9 years ago by dmethvin

Owner: set to wheresrhys
Status: newpending

Can you provide some more description of what you mean?

comment:2 Changed 9 years ago by wheresrhys

Status: pendingnew

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 9 years ago by Rick Waldron

Component: unfiledevent
Status: newpending

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 9 years ago by wheresrhys

Status: pendingnew

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 Changed 9 years ago by dmethvin

Status: newpending

So is this what you are looking for?

http://jsfiddle.net/E4NZW/2/

comment:6 Changed 9 years ago by john

Keywords: 1.7-discuss added

Nominating ticket for 1.7 discussion.

comment:7 Changed 9 years ago by Rick Waldron

Description: modified (diff)

+0,

comment:8 Changed 9 years ago by jaubourg

+1, Seems it would be good for interoperability

comment:9 Changed 9 years ago by timmywil

+0,

comment:10 in reply to:  5 Changed 9 years ago by wheresrhys

Status: pendingnew

Replying to dmethvin:

So is this what you are looking for?

http://jsfiddle.net/E4NZW/2/

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 9 years ago by timmywil

Description: modified (diff)
Priority: undecidedlow
Status: newopen

comment:12 Changed 9 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 9 years ago by Rick Waldron

I think this is not reasonable

comment:14 Changed 9 years ago by john

Description: modified (diff)

-1, Not really keen on this.

comment:15 Changed 9 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 9 years ago by scottgonzalez

Description: modified (diff)

+0, isn't this exactly what $.event.fix does?

comment:17 Changed 9 years ago by Rick Waldron

Description: modified (diff)
Keywords: 1.7-discuss removed
Milestone: 1.next1.7
Resolution: wontfix
Status: openclosed
Note: See TracTickets for help on using tickets.