Created
March 22, 2009 05:02
-
-
Save donut/83079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***********************************************************/ | |
/* LiveFilter Plugin */ | |
/* Version: 1.0 */ | |
/* Mike Merritt */ | |
/* Updated January 4th, 2009 */ | |
/***********************************************************/ | |
(function($){ | |
$.fn.liveFilter = function (filter_field, items, text) { | |
// Grabs the id of the element containing the filter | |
var haystack = $(this); | |
// Listen for the value of the input to change | |
$(filter_field).keyup(function() { | |
// Grab the current value of the filter | |
var needle = $(this).val(); | |
// Hide all elements that do not contain the filter string | |
haystack.children(items).children(text+':not(:inContains("'+needle+'"))').parent(items).hide(); | |
// Show already hidden elements that do contain the filter string | |
haystack.children(items).children(text+'::inContains("'+needle+'")').parent(items).show(); | |
}); | |
// Used for a case insensitive :contains selector | |
jQuery.extend( | |
jQuery.expr[':'], { | |
inContains : function(a,b,m) { | |
return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0; } | |
}); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment