Created
May 13, 2010 08:30
-
-
Save ncr/399624 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Code | |
$("button").single_double_click(function () { | |
alert("Try double-clicking me!") | |
}, function () { | |
alert("Double click detected, I'm hiding") | |
$(this).hide() | |
}) | |
Markup | |
<button>Click Me!</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author: Jacek Becela | |
// Source: http://gist.github.com/399624 | |
// License: MIT | |
jQuery.fn.single_double_click = function(single_click_callback, double_click_callback, timeout) { | |
return this.each(function(){ | |
var clicks = 0, self = this; | |
jQuery(this).click(function(event){ | |
clicks++; | |
if (clicks == 1) { | |
setTimeout(function(){ | |
if(clicks == 1) { | |
single_click_callback.call(self, event); | |
} else { | |
double_click_callback.call(self, event); | |
} | |
clicks = 0; | |
}, timeout || 300); | |
} | |
}); | |
}); | |
} |
In case anyone wants it I popped this into a JSfiddle to play with it easier:
http://jsfiddle.net/mBYPD/
very useful piece of code! I just adapted it so it makes my html5 videos go full screen on android devices. Thanks a lot for sharing!
jQuery(this).dblclick(function(event) {
jQuery(this).click().click();
});
Then manual dblclick trigger the double_click_callback.
http://jsfiddle.net/Lhnqswpb/
for jQuery 1.9.1
Thanks a lot for sharing. It solved my issue too that's related to the events "rowDblselect" and "rowSelect" of Primefaces' dataTable. :)
it's a good idea. but test result is when IE< 9 has a problem.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@CharlieSheather: I was dealing with the same sort of issue today, and I couldn't find a way around it. I ended up basically just chopping this function up and using it inside each .live() event I called. For example:
I've only tested this in Chrome so far, so it may have issues in other browsers, but it's a place to start if you don't have to set this up on a TON of objects.