| 1 |
|
| 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 |
|
| 19 |
css = wo && wo.columns || [ 'primary', 'secondary', 'tertiary' ], |
| 20 |
last = css.length - 1; |
| 21 |
remove = css.join(' '); |
| 22 |
|
| 23 |
for (tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) { |
| 24 |
$tbody = ts.processTbody(table, $tbodies.eq(tbodyIndex), true); |
| 25 |
$rows = $tbody.children('tr'); |
| 26 |
|
| 27 |
$rows.each(function() { |
| 28 |
$row = $(this); |
| 29 |
if (this.style.display !== 'none') { |
| 30 |
|
| 31 |
$cells = $row.children().removeClass(remove); |
| 32 |
|
| 33 |
if (sortList && sortList[0]) { |
| 34 |
|
| 35 |
$cells.eq(sortList[0][0]).addClass(css[0]); |
| 36 |
if (len > 1) { |
| 37 |
for (indx = 1; indx < len; indx++) { |
| 38 |
|
| 39 |
$cells.eq(sortList[indx][0]).addClass( css[indx] || css[last] ); |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
}); |
| 45 |
ts.processTbody(table, $tbody, false); |
| 46 |
} |
| 47 |
|
| 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 |
|
| 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); |
| 70 |
$tbody.children('tr').each(function() { |
| 71 |
$(this).children().removeClass(remove); |
| 72 |
}); |
| 73 |
ts.processTbody(table, $tbody, false); |
| 74 |
} |
| 75 |
} |
| 76 |
}); |
| 77 |
|
| 78 |
})(jQuery); |