onClickHold

onClickHold is a jQuery plugin that adds a custom "on click & hold" event. You can try it out by clicking & holding (duh) your primary mouse button anywhere on this page. The few options that it has are explained below. Also note that this stuff is provided as-is with no guarantees.

Note that it is not possible to use .bind(), .live(), or .delegate() to bind listeners to this event. For that, I still need to figure out a good way to trigger the custom event without listening for mouse events on all the elements on the page, or the entire page itself. Any suggestions are welcome.

Download it!

Usage

Fairly straightforward:

$(selector).clickhold(function(event){

	// do something interesting here

	// selector can be any jQuery selector
	// event will contain the event object, which is actually just
	// an 'extension' of the original mousedown event

});

You can unbind the custom event (and all mouse event that it binds to) using .unClickhold()., passing it a reference to the original listener.

Options

There are a few options that can be passed in an object as the second argument.

delay (400)
The duration that the mouse button needs to be depressed. If the button is released before the dalay has elapsed, the event will not be fired. Value in milliseconds.
tolerance (5)
The distance that the mouse is allowed to move (in any direction) during the delay. If movement exceeds this distance, the event will not be fired. Value in pixels.