I havent looked the logics but set() should be changed to store():

$$('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.store('ago', now);
       }
   });
});

http://mootools.net/docs/Element/Element#Element:store

And this example could give a nice customEvent:

http://demos.mootools.net/CustomEvents


Fábio Miranda Costa
Engenheiro de Computação
http://meiocodigo.com


On Wed, Apr 15, 2009 at 6:24 AM, Ken Marfilla <[email protected]>wrote:

>
> $$('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
>

Reply via email to