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();
});
}
}
};
So by chance I ran across this post which, with the assistance of jfk, pretty much summed up what I was looking for. I was wanting to make the script run after dynamic content was created, when what I should have been doing was call the script when the user is wanting to make a search.
Any additional info from more advanced developers on making this better, I'm all ears. I hope this can one day help another. :)