Bug Tracker

Modify

Ticket #8668 (closed enhancement: patchwelcome)

Opened 2 years ago

Last modified 2 years ago

Make click and dblclick events work properly with any browser when they both have a handler for the same element

Reported by: cfreed@… Owned by: cfreed@…
Priority: low Milestone: 1.next
Component: event Version: 1.5.1
Keywords: Cc:
Blocking: Blocked by:

Description (last modified by rwaldron) (diff)

Having an application where both click and dblclick event were expected on the same element, I realized that it worked or not, depending on which browser I used.

So I looked for information, and I successively found 2 contradictory advices in jQuery documentation!

  • in dblclick() page is advised not to use the 2 events on the same element
  • in bind() page is presented an example of this double use

I then investigated, and I seem having understood where the problem lies, and found a simple method to get it working always properly.

So I think that jQuery could integrate the involved mechanism to automatically apply it as soon as a it sees that the 2 events are bound on the same element.

Please look at for all details on how I understand the problem and how I get around it.

Thanks for your attention

Change History

comment:1 Changed 2 years ago by rwaldron

  • Owner set to cfreed@…
  • Status changed from new to pending
  • Component changed from unfiled to event
  • Description modified (diff)

Please provide a reduced test case on  http://jsfiddle.net (be sure to use jQuery Edge) thanks!

comment:2 Changed 2 years ago by cfreed@…

  • Status changed from pending to new

You may look at  http://jsfiddle.net/cFreed/ky7xh/.

CAUTION: uses jQuery-1.5.1, rather than jQuery Edge as required.

For me, using jQuery Edge fires an error with any simple HTML content:

"uncaught exception: [Exception... "Not enough arguments" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: http://code.jquery.com/jquery-git.js :: anonymous :: line 1285" data: no]"

comment:3 follow-up: ↓ 4 Changed 2 years ago by dmethvin

  • Keywords needsdocs added
  • Priority changed from undecided to low
  • Status changed from new to closed
  • Resolution set to patchwelcome

Re comment #2, that is a bug and has already been filed/fixed for 1.5.2.

I agree we're giving contradictory information, the example in  http://api.jquery.com/bind/ does attach both handlers even though the text in  http://api.jquery.com/dblclick/ warns about cross-browser issues. I do not think this is something worth normalizing, but if you would like to propose a solution (perhaps initially in a plugin) we could consider it.

comment:4 in reply to: ↑ 3 Changed 2 years ago by cfreed@…

Replying to dmethvin:

Re comment #2, that is a bug and has already been filed/fixed for 1.5.2.

I agree we're giving contradictory information, the example in  http://api.jquery.com/bind/ does attach both handlers even though the text in  http://api.jquery.com/dblclick/ warns about cross-browser issues. I do not think this is something worth normalizing, but if you would like to propose a solution (perhaps initially in a plugin) we could consider it.

Not sure to well understand what you mean when you "do not think this is sometingu worth normalizing".

May be I'm wrong but, from what I investigated, I seem that in the current state (no special survey), the risk of dysfunction when attaching both handlers is quite confirmed. So it will be worth to have a definitive solution to eliminate it, isn't it?

If yes, my only doubt is about the real efficacity of my own solution. As a simple application developper, I'm obviously much less experienced than jQuery contributors. It is why I need your opinion: does it seem to you that my solution covers all aspects of the problem?

Particularly, apart from the simple timing issue, I investigated about the problem of different browsers receiving one or two clicks before firing dblclick (look at my updated test case  http://jsfiddle.net/ky7xh/7/): seems that it doesn't matter. But perhaps I'm blind to other aspects...

So once again your opinion should be very welcome.

Thanks in advance.

comment:5 Changed 2 years ago by addyosmani

  • Keywords needsdocs removed

For the time-being, I've updated .bind() to reflect a similar note to the one we've included on dblclick and added a reference to the example that uses them. We should however consider (imo) dropping the example that binds both handlers as it doesn't really make sense to tell people not do something then show an example that contradicts this :)  http://api.jquery.com/bind/

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.