$$('textarea').each(function(item) {
item.addEvent('keydown', function(e) {
if (e.key == 'enter')
{
var now = new Date().getTime();
var elapse = now - this.retrieve('ago');
do_something(elapse);
this.set('ago', now);
}
});
});
On Apr 14, 6:35 pm, Robert <[email protected]> wrote:
> Hello,
> I wonder if there is a simple way to start different methods depending
> on how much time passed between events.
> example:
> I have two textareas on a form. I added some functionality to the
> 'keydown' event.
>
> $$('textarea').each(function(item) {
> item.addEvent('keydown', function(e) {
> if (e.key == 'enter') {
> do_something();
> }
> });
> });
>
> Now I would want to fire different methods depending on how much time
> passed between two keystrokes:
> 0.5s - nothing, 2s - do_something_1(), 5s - do_something_2().
>
> Do I need to do the timing work in do_something() function or is it
> same better pattern?
>
> thanks,
> rt