Thanks again for the advice, and let me tell you it made a huge
difference when testing with 2,000 rows vs. 200. Kangax's code made
for a very quick sort, but trying to do so at each keyup was a killer.
Here's where I ended up in the end:
var list = $$("#delegates li");
var lastValue = $F("filter");
var timeout = false;
for (var i = list.length - 1; i >= 0; i--){
list[i]['d'] =
list[i].innerHTML.stripTags().toLowerCase();
};
$('filter').observe('keyup', function(e) {
var value = this.value;
clearTimeout(timeout);
if (value !== lastValue) {
value = value.toLowerCase();
var stripe = 'even';
timeout = setTimeout(function(){
list.each(function(el) {
if (el.d.include(value)) {
Element.show(el);
el.className =
alternate();
}else{
Element.hide(el);
}
})
}, 200);
lastValue = value;
}
});
This worked just fine on Firefox without the pre-calculation step, but
Safari was a real dog, beachballing all over the place while it ran
through the sort. Once I added the step to calculate the match string
once for all elements, it all worked perfectly in both browsers.
Walter
On Dec 2, 2008, at 1:09 PM, Matt Foster wrote:
> 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.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---