Opened 12 years ago
Closed 12 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 )
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 12 years ago by
Owner: | set to wheresrhys |
---|---|
Status: | new → pending |
comment:2 Changed 12 years ago by
Status: | pending → 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 12 years ago by
Component: | unfiled → event |
---|---|
Status: | new → pending |
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 12 years ago by
Status: | pending → 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 12 years ago by
Status: | new → pending |
---|
So is this what you are looking for?
comment:10 Changed 12 years ago by
Status: | pending → 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 12 years ago by
Description: | modified (diff) |
---|---|
Priority: | undecided → low |
Status: | new → open |
comment:12 Changed 12 years ago by
-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:15 Changed 12 years ago by
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 12 years ago by
Description: | modified (diff) |
---|
+0, isn't this exactly what $.event.fix does?
comment:17 Changed 12 years ago by
Description: | modified (diff) |
---|---|
Keywords: | 1.7-discuss removed |
Milestone: | 1.next → 1.7 |
Resolution: | → wontfix |
Status: | open → closed |
Can you provide some more description of what you mean?