Skip to content

Instantly share code, notes, and snippets.

@Xordal
Created July 7, 2014 12:28
Show Gist options
  • Save Xordal/992061825c164a276ba3 to your computer and use it in GitHub Desktop.
Save Xordal/992061825c164a276ba3 to your computer and use it in GitHub Desktop.
Single- and double-click functions
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);
}
});
});
};
//use:
$("td.cell-free, td.cell-alive, td.cell-busy").single_double_click(function () {
selectCell($(this));
}, function () {
StartRecord($(this));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment