2020-10-31 15:04:44 +01:00
|
|
|
var TYPO3 = TYPO3 || {};
|
|
|
|
TYPO3.tea = {};
|
|
|
|
|
|
|
|
TYPO3.tea.makeSortable = function (table) {
|
2020-11-29 21:15:29 +01:00
|
|
|
var th = table.tHead,
|
|
|
|
i;
|
|
|
|
th && (th = th.rows[0]) && (th = th.cells);
|
|
|
|
if (th) i = th.length;
|
|
|
|
else return;
|
|
|
|
while (--i >= 0)
|
|
|
|
(function (i) {
|
|
|
|
var dir = 1;
|
2022-05-18 17:17:45 +02:00
|
|
|
th[i].addEventListener('click', function () {
|
2020-11-29 21:15:29 +01:00
|
|
|
TYPO3.tea.sortTable(table, i, (dir = 1 - dir));
|
|
|
|
});
|
|
|
|
})(i);
|
2020-10-31 15:04:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TYPO3.tea.sortTable = function (table, col, reverse) {
|
2020-11-29 21:15:29 +01:00
|
|
|
var tb = table.tBodies[0],
|
|
|
|
tr = Array.prototype.slice.call(tb.rows, 0),
|
|
|
|
i;
|
|
|
|
reverse = -(+reverse || -1);
|
|
|
|
tr = tr.sort(function (a, b) {
|
2022-05-18 17:17:45 +02:00
|
|
|
return reverse * a.cells[col].textContent.trim().localeCompare(b.cells[col].textContent.trim());
|
2020-11-29 21:15:29 +01:00
|
|
|
});
|
|
|
|
for (i = 0; i < tr.length; ++i) tb.appendChild(tr[i]);
|
2020-10-31 15:04:44 +01:00
|
|
|
};
|
|
|
|
|
2022-05-18 17:17:45 +02:00
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
var t = document.querySelectorAll('.tx-tea table'),
|
2020-11-29 21:15:29 +01:00
|
|
|
i = t.length;
|
|
|
|
while (--i >= 0) {
|
|
|
|
TYPO3.tea.makeSortable(t[i]);
|
|
|
|
}
|
2020-10-31 15:04:44 +01:00
|
|
|
});
|