Last active
September 5, 2017 11:57
-
-
Save yairEO/83bd087aa7a74212c607c34b47fe5382 to your computer and use it in GitHub Desktop.
jQuery special-event "clickLimit" [only fires the event if a duration threshold hasn't passed]
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.event.special.clickLimit = { | |
delegateType: "mousedown", | |
bindType: "mousedown", | |
handle: function( event ) { | |
var handleObj = event.handleObj, | |
startTime = new Date().getTime(), | |
threshold = event.data.threshold || 500; | |
$(this) | |
.unbind('mouseup.clickLimit') | |
.bind('mouseup.clickLimit', function(){ | |
var delta = new Date().getTime() - startTime; | |
delta < threshold && fire(); | |
}) | |
function fire(){ | |
event.type = handleObj.origType; | |
handleObj.handler.apply( this, arguments ); | |
event.type = handleObj.type; | |
} | |
return null; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: