Skip to content

Instantly share code, notes, and snippets.

@jremmen
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jremmen/4f2dcc32d09a7cce171d to your computer and use it in GitHub Desktop.
Save jremmen/4f2dcc32d09a7cce171d to your computer and use it in GitHub Desktop.
jquery: tripleclick event
(function($) {
$.event.special.tripleclick = {
clicked: 0,
time: 0,
threshold: 80,
setup: function() {
$(this).on('click', $.event.special.tripleclick.handler);
},
teardown: function() {
$(this).off('click', $.event.special.tripleclick.handler);
},
handler: function(event) {
var self = $.event.special.tripleclick,
clicked = self.clicked++;
if( clicked === 0 ) {
timed = setInterval(function() {
self.time += 1;
if(self.time > self.threshold) {
self.reset(timed);
}
}, 10);
}
if(clicked > 1) {
if(self.time < self.threshold) {
$( event.target ).trigger('tripleclick');
}
self.reset(timed);
}
},
reset: function(timed) {
clearInterval(timed);
this.clicked = 0;
this.time = 0;
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment