jQuey Delayed KeyPress Event
for Stepan Suvorov Blog
http://stepansuvorov.com/blog/2014/06/delayed-keypress-jquery/
by Stepan Suvorov
JavaScript
jQuery.event.special.delayedkeypress = {
delegateType: "keypress",
bindType: "keypress",
handle: function (event) {
var self = this;
this.timer && clearTimeout(this.timer);
this.timer = setTimeout(function(){
event.handleObj.handler.apply(self, arguments);
}, 500);
}
};
jQuery.fn[ "delayedkeypress" ] = function( data, fn ) {
return arguments.length > 0 ?
this.on( "delayedkeypress", null, data, fn ) :
this.trigger( "delayedkeypress" );
};
$("#id").delayedkeypress(function () {
console.log(this.value)
});