Debian Codegraph @

js/widgets/widget-columns.js

raw symbols SCIP
1 /*! Widget: columns - updated 5/24/2017 (v2.28.11) */
2 ;(function ($) {
3 'use strict';
4 var ts = $.tablesorter || {};
5
6 ts.addWidget({
7 id: 'columns',
8 priority: 65,
9 options : {
10 columns : [ 'primary', 'secondary', 'tertiary' ]
11 },
12 format: function(table, c, wo) {
13 var $tbody, tbodyIndex, $rows, rows, $row, $cells, remove, indx,
14 $table = c.$table,
15 $tbodies = c.$tbodies,
16 sortList = c.sortList,
17 len = sortList.length,
18 // removed c.widgetColumns support
19 css = wo && wo.columns || [ 'primary', 'secondary', 'tertiary' ],
20 last = css.length - 1;
21 remove = css.join(' ');
22 // check if there is a sort (on initialization there may not be one)
23 for (tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
24 $tbody = ts.processTbody(table, $tbodies.eq(tbodyIndex), true); // detach tbody
25 $rows = $tbody.children('tr');
26 // loop through the visible rows
27 $rows.each(function() {
28 $row = $(this);
29 if (this.style.display !== 'none') {
30 // remove all columns class names
31 $cells = $row.children().removeClass(remove);
32 // add appropriate column class names
33 if (sortList && sortList[0]) {
34 // primary sort column class
35 $cells.eq(sortList[0][0]).addClass(css[0]);
36 if (len > 1) {
37 for (indx = 1; indx < len; indx++) {
38 // secondary, tertiary, etc sort column classes
39 $cells.eq(sortList[indx][0]).addClass( css[indx] || css[last] );
40 }
41 }
42 }
43 }
44 });
45 ts.processTbody(table, $tbody, false);
46 }
47 // add classes to thead and tfoot
48 rows = wo.columns_thead !== false ? [ 'thead tr' ] : [];
49 if (wo.columns_tfoot !== false) {
50 rows.push('tfoot tr');
51 }
52 if (rows.length) {
53 $rows = $table.find( rows.join(',') ).children().removeClass(remove);
54 if (len) {
55 for (indx = 0; indx < len; indx++) {
56 // add primary. secondary, tertiary, etc sort column classes
57 $rows.filter('[data-column="' + sortList[indx][0] + '"]').addClass(css[indx] || css[last]);
58 }
59 }
60 }
61 },
62 remove: function(table, c, wo) {
63 var tbodyIndex, $tbody,
64 $tbodies = c.$tbodies,
65 remove = (wo.columns || [ 'primary', 'secondary', 'tertiary' ]).join(' ');
66 c.$headers.removeClass(remove);
67 c.$table.children('tfoot').children('tr').children('th, td').removeClass(remove);
68 for (tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
69 $tbody = ts.processTbody(table, $tbodies.eq(tbodyIndex), true); // remove tbody
70 $tbody.children('tr').each(function() {
71 $(this).children().removeClass(remove);
72 });
73 ts.processTbody(table, $tbody, false); // restore tbody
74 }
75 }
76 });
77
78 })(jQuery);