Jquery Plugin - onHold Event

Written by Kevin on June 23, 2011

This simple plugin adds the following event:

.onHold(time,action);

See this for a working example: http://jsfiddle.net/hkBfP/

(function( $ ){
    $.fn.onHold= function(time,action) {
        this.data(‘onHold_selected’,false);
        this.mousedown(function(){
            $(this).data(‘onHold_selected’,true);
            var object = this;
            setTimeout(function(){
                if($(object).data(‘onHold_selected’)){
                     action();
                }
            },time);
        });
        this.mouseup(function(){
            $(this).data(‘onHold_selected’,false);
        });
       return this;
    };
})( jQuery );