Debian Codegraph @

js/widgets/widget-repeatheaders.js

raw symbols SCIP
1 /*! Widget: repeatHeaders - updated 9/23/2016 (v2.27.7) *//*
2 * Requires tablesorter v2.8+ and jQuery 1.7+
3 * Original by Christian Bach from the example-widgets.html demo
4 */
5 /*global jQuery: false */
6 ;(function($) {
7 'use strict';
8
9 $.tablesorter.addWidget({
10 id: 'repeatHeaders',
11 priority: 10,
12 options: {
13 rowsToSkip : 4
14 },
15 // format is called on init and when a sorting has finished
16 format: function(table, c, wo) {
17 var h = '', i, $tr, l, skip;
18 // cache and collect all TH headers
19 if (!wo.repeatHeaders) {
20 h = '<tr class="repeated-header ' + c.selectorRemove.slice(1) + '">';
21 for (i = 0; i < c.columns; i++) {
22 // repeat the content of the current header (including child elements)
23 h += '<th>' + $.trim( c.$headers.eq(i).html() ) + '</th>';
24 }
25 // 'remove-me' class was added in case the table needs to be updated, the 'remove-me' rows will be
26 // removed prior to the update to prevent including the rows in the update - see 'selectorRemove' option
27 wo.repeatHeaders = h + '</tr>';
28 }
29
30 // number of rows to skip
31 skip = wo && wo.rowsToSkip || 4;
32
33 // remove appended headers by classname
34 c.$table.find('tr.repeated-header').remove();
35 $tr = c.$tbodies.find('tr');
36 l = $tr.length;
37 // loop all tr elements and insert a copy of the 'headers'
38 for (i = skip; i < l; i += skip) {
39 // insert a copy of the table head every X rows
40 $tr.eq(i).before(wo.repeatHeaders);
41 }
42 },
43 // this remove function is called when using the refreshWidgets method or when destroying the tablesorter plugin
44 // this function only applies to tablesorter v2.4+
45 remove: function(table, c, wo) {
46 wo.repeatHeaders = '';
47 c.$table.find('tr.repeated-header').remove();
48 }
49
50 });
51
52 })(jQuery);