Core Docs | Additional Modules Docs

Element.prototype.onDelayedKeyup


@Description: Fires after a delay on keyup. New keypresses restart the count.
Great for when you have a realtime ajax search but want to wait until after
the user finishes typing.
@File: Element/prototype/onDelayedKeyUp.js
@Author: Paul Visco
@Version: 0.11 06-17-09 07-29-09
@Param: o Object
o.onAfterDelay function The function to fire after the delay. The this is the element. The e arg is the event
o.onKeyUp function The function to fire on keyup. The this is the element. The e arg is the event
o.delay integer The delay in milliseconds to wait before firing onAfterDelay
o.debug boolean If timer is sent to console in browsers that support it
@Return: object r With the following properties: r.onAfterDelay() function which can be changed at any point r.onKeyUp() function which can be changed at any point r.observe(); function start or restart observing keypresses r.unobserve(); function stop observing keypresses
@Example:
var onDelayedKeyUp = $('#search_main').onDelayedKeyUp({
delay : 500,
onAfterDelay : function(e){
//if the value is more than one character
if(this.value.length > 3){

//do something app specific
search(this.value);
}

},
onKeyUp : function(e){
if(e.keyCode == 27 || this.value == ''){
//do something app specific
clearSearch();


return false;
}
}
});