Created
July 7, 2014 12:28
-
-
Save Xordal/992061825c164a276ba3 to your computer and use it in GitHub Desktop.
Single- and double-click functions
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
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