views:

324

answers:

2

Hi,

I'm writing a web application that decodes Morse Code that is tapped in using mouse button.

I originally did a proof of concept using conventional JavaScript, but now I'm redoing it using jQuery.

Is there a clever way with jQuery to tell if a button has been pressed again within so many milliseconds, or not - and run some jQuery code if the button was NOT pressed again.

I've been going over the jQuery API and I'm not seeing a clever way of doing this....

Any ideas...

Derek

+2  A: 

I suspect you'll need to monitor the buttons' click events and do the timing yourself.

theraccoonbear
I think you are correct. I'm having a difficult time wrapping my brain for doing something in the future that is not initiated by a event...
Derek
You might be able to use a closure to redefine the click handler after the first click, thus allowing the closure to keep state for you.
theraccoonbear
Good idea! I will give that a try.... Thanks!
Derek
+1  A: 

To your point about the button NOT being pressed again within so many milliseconds, you'll need to use setTimeout() and clearTimeout(), keeping track of the targets yourself as theracoonbear said. You were probably doing it this way in your POC, and JQuery doesn't have this in the API (that I've seen), so just refactor where you can.

Pseudo Masochist
Well, you have a nice timer plugin that can help : http://jquery.offput.ca/every/
e-satis