click / dblclick Problem

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

click / dblclick Problem

Stefan Kilp [sk-software]
Hi,

i am using jscript-1.1

i have registered click and dbclick event on the same tag

$("#liste p").dblclick(function(){
...
}
$("#liste p").click(function(){
...
}

so that i have different bahavior on click and doubleclick.

click works fine
when i doubleclick the item then doubleclick gets execute, BUT click gets executed twice
BEFORE. i wanted to execute dblclick or click, not both.

what am i doing wrong.

thanks
stefan
--
Stefan Kilp
SK-Software, Entwicklung & Beratung


fon  : +49 6151 93344-0
fax  : +49 6151 93344-20
Herta-Mansbacher-Str. 98
64289 Darmstadt, Germany.
-----------------------------------------------------

_______________________________________________
jQuery mailing list
[hidden email]
http://jquery.com/discuss/
Reply | Threaded
Open this post in threaded view
|

Re: click / dblclick Problem

LeonL

I'm having the same problem.
Can anybody help please??
Thanks!

Stefan Kilp [sk-software] wrote
Hi,


i am using jscript-1.1


i have registered click and dbclick event on the same tag


$("#liste p").dblclick(function(){
...
}
$("#liste p").click(function(){
...
}


so that i have different bahavior on click and doubleclick.


click works fine
when i doubleclick the item then doubleclick gets execute, BUT click gets executed twice
BEFORE. i wanted to execute dblclick or click, not both.


what am i doing wrong.


thanks
stefan
--
Stefan Kilp
SK-Software, Entwicklung & Beratung


email: kilp@sk-software.de


fon  : +49 6151 93344-0
fax  : +49 6151 93344-20
Herta-Mansbacher-Str. 98
64289 Darmstadt, Germany.
-----------------------------------------------------





_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/
Reply | Threaded
Open this post in threaded view
|

Re: click / dblclick Problem

Richard D. Worth-2
The detail property on the event object will help you out here. On the first click it's 1, on each subsequent click in the same spot it goes up one. For the second click as well as on the double click, it will be 2.

$("#foo").click(function(ev) {
  if (ev.detail == 1) {
    //single click -- perform click action
  }
}).dblclick(function(ev) {
  //double click -- perform double click action
});

Ref: http://developer.mozilla.org/en/docs/DOM:event.detail

- Richard

Richard D. Worth
http://rdworth.org/

On Tue, Jun 10, 2008 at 9:57 AM, LeonL <[hidden email]> wrote:



I'm having the same problem.
Can anybody help please??
Thanks!


Stefan Kilp [sk-software] wrote:
>
>
> Hi,
>
>
> i am using jscript-1.1
>
>
> i have registered click and dbclick event on the same tag
>
>
> $(&quot;#liste p&quot;).dblclick(function(){
> ...
> }
> $(&quot;#liste p&quot;).click(function(){
> ...
> }
>
>
> so that i have different bahavior on click and doubleclick.
>
>
> click works fine
> when i doubleclick the item then doubleclick gets execute, BUT click gets
> executed twice
> BEFORE. i wanted to execute dblclick or click, not both.
>
>
> what am i doing wrong.
>
>
> thanks
> stefan
> --
> Stefan Kilp
> SK-Software, Entwicklung &amp; Beratung
>
>
> email: [hidden email]
>
>
> fon&#160; : +49 6151 93344-0
> fax&#160; : +49 6151 93344-20
> Herta-Mansbacher-Str. 98
> 64289 Darmstadt, Germany.
> -----------------------------------------------------
>
>
>
>
>
> _______________________________________________
> jQuery mailing list
> [hidden email]
> http://jquery.com/discuss/
>
>

--
View this message in context: http://www.nabble.com/click---dblclick-Problem-tp8389800s27240p17756125.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: click / dblclick Problem

Joel Newkirk
Richard: Your example (utilizing event detail - useful info, that) will still perform the 'click' action when double-clicked, just does it once instead of twice. 

I believe the OP ("I wanted to execute dblclick or click, not both.") was asking "How do I prevent the click() event from firing when the user performs a doubleclick?" 

The answer appears, however, to be "there's no easy way".  (a 'click handler' could conceivably be written to accept the click and do nothing for a specified period of time, then act on the click if a double-click were not also received, so if it's important enough it CAN be done)

j

Reply | Threaded
Open this post in threaded view
|

Re: click / dblclick Problem

balupton
In reply to this post by Stefan Kilp [sk-software]
jQuery Sparkle provides a clean elegant solution for this, by implementing a singleclick custom event. By doing this, you can use it just like any other event, so:

    $('#el').singleclick(function(){});
    // or event
    $('#el').bind('singleclick', function(){});

It also provides custom events for the last and first clicks of a series of clicks. And the lastclick custom event actually passes the amount of clicks back! So you could do this!

    $('#el').lastclick(function(event,clicks){
        if ( clicks === 3 ) alert('Tripple Click!');
    });

You can find the appropriate demo showcasing what I've just said right here:
http://www.balupton.com/projects/jquery-sparkle/#event-singleclick

And the source code for defining the custom event right here:
http://bit.ly/diBCkI

It's open source under the AGPL licence, so you can feel free to grab what you need out of it worry free! :-) It's also actively developed on a day to day basis so you will never be short on support.

But most importantly it is a DRY Plugin/Effect Framework to allow you to develop plugins and extensions much more easily. So hope this helps to achieve that goal!



You can find more about jQuery Sparkle, and see some demos of it right here at it's homepage:
http://www.balupton.com/projects/jquery-sparkle

Hope I've helped!