On 6 avr, 17:46, Alex Wallace <alexmlwall...@gmail.com> wrote: > In general I would simplify things a bit: > > * the two selectors ($$) are pretty lengthy- could they be optimized,
I thought the more precise I'll be, the fastest it would be for Prototype to find. > Also, try doing those selectors beforehand and caching the values somewhere. I tried with moving var lines = ... before func declaration, but I get strange behaviors : lines (tr) no longer hide ! > * Avoid using .each(function(j) { j.singleFunction(); }. Instead try using > Enumerable.invoke. [1] Done. No notable speed improvements, but Prototype API confirms what you say. > * When going through the lines to hide those with hidden cells, there are a > lot of expensive functions being used: childElements() should be detected > before and cached along with the lines variable. Yeah but with the "lines do not hide anymore" behavior, that's kinda impossible for now. > detect() is an expensive > function in IE, especially if there are a lot of lines and cells. It seems > there would probably be a way to tighten that behavior up so you only need > to do one iteration of hiding and showing- maybe operate on the rows first > instead of cells first followed by the row filtering. I just want to hide lines (tr) that do not have any "hide"-class cells. Thanks for you firsts directions though. Code is now : function(nam, val) { val = val.toLowerCase(); var lines = $$("#annuaire_table > div > table > tbody > tr"); var ourcells = $$("#annuaire_table > div > table > tbody > tr > ."+nam); ourcells.invoke("removeClassName", "highlight").invoke("removeClassName", "hide"); if( val.length > 0 ) { var rtab = ourcells.partition( function(i) { return ((i.textContent || i.innerText || "").toLowerCase().indexOf(val) >= 0); } ); rtab[0].invoke("addClassName", "highlight"); rtab[1].invoke("addClassName", "hide"); } lines.each( function(i) { var childcells = i.childElements(); if( childcells.detect( function(j) { return j.hasClassName("hide"); } ) ) { i.hide(); } else { i.show(); } } ); }; -- 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 prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.