I recently found Resig's jQuery rewrite of a Quicksilver Live Search and love the workings of it... but I'm trying to update it to work with the new .on() event handler. However my abilities (or lack thereof) fail me.
I'm thinking I need to edit the "this.keyup(filter)..." but I get nothin' to work. Any ideas?
Update: Just a point of clarification. My thoughts as to wanting to update the script is to accept list items brought in dynamically. Everything works fine as long as it's a static list, but since I have introduced a list created via an ajax call, it fails to work. I'm going to mock up a fiddle and link it here shortly. In the meantime, if anyone can help me out, it'd save my hide. Thanks.
jQuery.fn.liveUpdate = function(list){
list = jQuery(list);
if ( list.length ) {
var rows = list.children('li'),
cache = rows.map(function(){
//return this.innerHTML.toLowerCase();
return $('a', this)[0].innerHTML.toLowerCase();
});
this
.keyup(filter).keyup()
.parents('form').submit(function(){
return false;
});
}
return this;
function filter(){
var term = jQuery.trim( jQuery(this).val().toLowerCase() ), scores = [];
if ( !term ) {
rows.show();
} else {
rows.hide();
cache.each(function(i){
var score = this.score(term);
if (score > 0) { scores.push([score, i]); }
});
jQuery.each(scores.sort(function(a, b){return b[0] - a[0];}), function(){
jQuery(rows[ this[1] ]).show();
});
}
}
};