jquery-livesearch
jquery-livesearch copied to clipboard
jQuery v1.8 compatibility
Hi-
As of version 1.8, Live Search is broken.
The error is here: https://github.com/nakajima/jquery-livesearch/blob/master/src/jquery.livesearch.js#L5
To fix, please see: http://stackoverflow.com/questions/2196641/how-do-i-make-jquery-contains-case-insensitive-including-jquery-1-8
Code:
jQuery.expr[":"].Contains = jQuery.expr.createPseudo(function(arg) {
return function( elem ) {
return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
To maintain 1.7 compatibility, I wrote a little if test using the jQuery version function here: http://stackoverflow.com/questions/2655308/jquery-version-compatibility-detection/3113707#3113707
/** jQuery < 1.8 */
if ($.isVersion('1.8', '<'))
{
$.extend($.expr[':'], {
'containsi': function(elem, i, match, array) {
return $(elem).text().toLowerCase()
.indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
} else
{
/** jQuery > 1.8 */
jQuery.expr[":"].containsi = jQuery.expr.createPseudo(function(arg) {
return function( elem ) {
return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
}
Of course, using the if statement is okay for my project but it may add unnecessary weight to the live search plugin.
-Greg