/** * Register the tablefilter behavior to Drupal's behaviors */ Drupal.behaviors.tablefilter = function (context) { $('table.uses-filter:not(.tablefilter-processed)', context).each(function() { var filter_obj = $(''); var table_obj = $(this).addClass('tablefilter-processed').before($('').text(Drupal.t('Filter'))); var filter_value, str_exists; filter_obj.keyup(function() { filter_value = $(this).val().toLowerCase(); table_obj.find('tbody tr').each(function() { str_exists = false; $(this).find('td').each(function() { if ($(this).text().toLowerCase().indexOf(filter_value) > -1) { str_exists = true; }; }); if (!str_exists) { $(this).hide(); } else { $(this).show(); }; }); }).prependTo(table_obj.parent()); }); };