Skip to content

Instantly share code, notes, and snippets.

@toledox82
Created October 15, 2013 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toledox82/6992043 to your computer and use it in GitHub Desktop.
Save toledox82/6992043 to your computer and use it in GitHub Desktop.
// Live Search
function liveSearch() {
// Active tab All
if ($('#search-filter').val() == '') {
$('#filter-all').addClass('active');
} else {
$('.tabs .button').removeClass('active');
}
// Retrieve the input field text and reset the count to zero
var filter = $('#search-filter').val(), count = 0;
// Loop through the comment list
$(".main-list li").each(function(){
// If the list item does not contain the text phrase fade it out
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).hide();
// Show the list item if the phrase matches and increase the count by 1
} else {
$(this).show();
count++;
}
});
// Update the counter
switch(count)
{
case 0:
$("#filter-count").text("nenhum domínio");
break;
case 1:
$("#filter-count").text(count + " domínio");
break;
default:
$("#filter-count").text(count + " domínios");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment