-
-
Save Victa/1539457 to your computer and use it in GitHub Desktop.
jquery.single_double_click
This file contains 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 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); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone looking, I forked a hack that allows the use of this AND .draggable().