-
Notifications
You must be signed in to change notification settings - Fork 0
/
mltclick.js
26 lines (25 loc) · 930 Bytes
/
mltclick.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(function($) {
$.fn.mltclick = function(delegateSelector, callback, dblclickWait) {
var obj;
if (typeof(delegateSelector)==='function' && typeof(callback)!=='function') {
callback= delegateSelector; delegateSelector = null; // If 'delegateSelector' is missing reorder arguments
}
if (( delegateSelector!=null && typeof(delegateSelector)!=='string') || typeof(callback)!=='function' ) {
return false;
}
return $(this).each(function() {
var clicks = 0;
$(this).on('click', delegateSelector, function(event) {
var self = this;
clicks++;
if (clicks == 1) {
setTimeout(function(){
event.clickCount=clicks;
callback.call(self, event); // Single click action
clicks=0;
}, dblclickWait || 300);
}
});
});
};
})(jQuery);