1(function ($, w, undefined) { 2 if (w.footable === undefined || w.footable === null) 3 throw new Error('Please check and make sure footable.js is included in the page and is loaded prior to this script.'); 4 5 var defaults = { 6 filter: { 7 enabled: true, 8 input: '.footable-filter', 9 timeout: 300, 10 minimum: 2, 11 disableEnter: false, 12 filterFunction: function(index) { 13 var $t = $(this), 14 $table = $t.parents('table:first'), 15 filter = $table.data('current-filter').toUpperCase(), 16 text = $t.find('td').text(); 17 if (!$table.data('filter-text-only')) { 18 $t.find('td[data-value]').each(function () { 19 text += $(this).data('value'); 20 }); 21 } 22 return text.toUpperCase().indexOf(filter) >= 0; 23 } 24 } 25 }; 26 27 function Filter() { 28 var p = this; 29 p.name = 'Footable Filter'; 30 p.init = function (ft) { 31 p.footable = ft; 32 if (ft.options.filter.enabled === true) { 33 if ($(ft.table).data('filter') === false) return; 34 ft.timers.register('filter'); 35 $(ft.table) 36 .unbind('.filtering') 37 .bind({ 38 'footable_initialized.filtering': function (e) { 39 var $table = $(ft.table); 40 var data = { 41 'input': $table.data('filter') || ft.options.filter.input, 42 'timeout': $table.data('filter-timeout') || ft.options.filter.timeout, 43 'minimum': $table.data('filter-minimum') || ft.options.filter.minimum, 44 'disableEnter': $table.data('filter-disable-enter') || ft.options.filter.disableEnter 45 }; 46 if (data.disableEnter) { 47 $(data.input).keypress(function (event) { 48 if (window.event) 49 return (window.event.keyCode !== 13); 50 else 51 return (event.which !== 13); 52 }); 53 } 54 $table.bind('footable_clear_filter', function () { 55 $(data.input).val(''); 56 p.clearFilter(); 57 }); 58 $table.bind('footable_filter', function (event, args) { 59 p.filter(args.filter); 60 }); 61 $(data.input).keyup(function (eve) { 62 ft.timers.filter.stop(); 63 if (eve.which === 27) { 64 $(data.input).val(''); 65 } 66 ft.timers.filter.start(function () { 67 var val = $(data.input).val() || ''; 68 p.filter(val); 69 }, data.timeout); 70 }); 71 }, 72 'footable_redrawn.filtering': function (e) { 73 var $table = $(ft.table), 74 filter = $table.data('filter-string'); 75 if (filter) { 76 p.filter(filter); 77 } 78 } 79 }) 80 //save the filter object onto the table so we can access it later 81 .data('footable-filter', p); 82 } 83 }; 84 85 p.filter = function (filterString) { 86 var ft = p.footable, 87 $table = $(ft.table), 88 minimum = $table.data('filter-minimum') || ft.options.filter.minimum, 89 clear = !filterString; 90 91 //raise a pre-filter event so that we can cancel the filtering if needed 92 var event = ft.raise('footable_filtering', { filter: filterString, clear: clear }); 93 if (event && event.result === false) return; 94 if (event.filter && event.filter.length < minimum) { 95 return; //if we do not have the minimum chars then do nothing 96 } 97 98 if (event.clear) { 99 p.clearFilter(); 100 } else { 101 var filters = event.filter.split(' '); 102 103 $table.find('> tbody > tr').hide().addClass('footable-filtered'); 104 var rows = $table.find('> tbody > tr:not(.footable-row-detail)'); 105 $.each(filters, function (i, f) { 106 if (f && f.length > 0) { 107 $table.data('current-filter', f); 108 rows = rows.filter(ft.options.filter.filterFunction); 109 } 110 }); 111 rows.each(function () { 112 p.showRow(this, ft); 113 $(this).removeClass('footable-filtered'); 114 }); 115 $table.data('filter-string', event.filter); 116 ft.raise('footable_filtered', { filter: event.filter, clear: false }); 117 } 118 }; 119 120 p.clearFilter = function () { 121 var ft = p.footable, 122 $table = $(ft.table); 123 124 $table.find('> tbody > tr:not(.footable-row-detail)').removeClass('footable-filtered').each(function () { 125 p.showRow(this, ft); 126 }); 127 $table.removeData('filter-string'); 128 ft.raise('footable_filtered', { clear: true }); 129 }; 130 131 p.showRow = function (row, ft) { 132 var $row = $(row), $next = $row.next(), $table = $(ft.table); 133 if ($row.is(':visible')) return; //already visible - do nothing 134 if ($table.hasClass('breakpoint') && $row.hasClass('footable-detail-show') && $next.hasClass('footable-row-detail')) { 135 $row.add($next).show(); 136 ft.createOrUpdateDetailRow(row); 137 } 138 else $row.show(); 139 }; 140 } 141 142 w.footable.plugins.register(Filter, defaults); 143 144}
144)(jQuery, window);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.