By using the keyup event you can avoid the conditions to check for
change, if the user has pressed and released a key on the input then
the value has changed.  Also it is very wise to add the timeout, your
users will thank you.


document.observe("dom:loaded", function() {

  var list = $$("#listAll li");
  var lastValue = $F("filter");
  var timeout = false;

  $('filter').observe('keyup', function(e) {
     var value = this.value;
     clearTimeout(timeout);

      timeout = setTimeout(function(){
          list.each(function(ele){ filterElement(ele, value) });
      }, 500);
  })

})

On Dec 2, 9:11 am, Walter Lee Davis <[EMAIL PROTECTED]> wrote:
> On Dec 1, 2008, at 11:01 PM, kangax wrote:
>
>
>
> >> This behaves the way you would want it to -- so fast that the change
> >> doesn't register until the list starts getting very short.
>
> > I think something along these lines could be faster:
>
> > document.observe("dom:loaded", function() {
>
> >  var list = $$("#listAll li");
> >  var lastValue = $F("filter");
>
> >  $('filter').observe('keyup', function(e) {
> >    var value = this.value;
> >    if (value !== lastValue) {
> >      value = value.toLowerCase();
> >      list.each(function(el) {
> >        if (el.innerHTML.toLowerCase().include(value)) {
> >          Element.show(el);
> >        }
> >        else {
> >          Element.hide(el);
> >        }
> >      })
> >      lastValue = value;
> >    }
> >  })
> > })
>
> Thanks very much, I'll give this a try. I can see where your shortcuts  
> are, and they make a lot of sense.
>
> Walter
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to