Last active
August 29, 2015 14:02
-
-
Save jremmen/4f2dcc32d09a7cce171d to your computer and use it in GitHub Desktop.
jquery: tripleclick event
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
(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