commit: b086a3ec683b0464d6a3a5fbd5e2ecf5dd0cf004
parent cd67b3793ca07cb4b365252053b4d59f509a9a5d
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 13 Apr 2019 18:48:12 +0200
javascript/sorttable.js: Bump to 0a0d8c1
Diffstat:
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/javascript/sorttable.js b/javascript/sorttable.js
@@ -36,22 +36,24 @@ sorttable = {
// make it clickable to sort
headrow[i].sorttable_columnindex = i;
headrow[i].sorttable_tbody = table.tBodies[0];
- headrow[i].addEventListener("click", sorttable.innerSortFunction);
+ headrow[i].addEventListener("click", event => { if(event.target){ sorttable.innerSortFunction(event.target) } });
+ headrow[i].addEventListener("keydown", event => { if(event.target && (event.key && event.key == "Enter")){ sorttable.innerSortFunction(event.target); } });
+ headrow[i].setAttribute("tabindex", "0");
headrow[i].classList.add('made_sortable');
}
}
},
- innerSortFunction : function(e) {
- if (this.classList.contains("sorttable_sorted")) {
- sorttable.reverse(this.sorttable_tbody);
- this.classList.replace('sorttable_sorted', 'sorttable_sorted_reverse');
- } else if (this.classList.contains("sorttable_sorted_reverse")) {
- sorttable.reverse(this.sorttable_tbody);
- this.classList.replace('sorttable_sorted_reverse', 'sorttable_sorted');
+ innerSortFunction : function(tr) {
+ if (tr.classList.contains("sorttable_sorted")) {
+ sorttable.reverse(tr.sorttable_tbody);
+ tr.classList.replace('sorttable_sorted', 'sorttable_sorted_reverse');
+ } else if (tr.classList.contains("sorttable_sorted_reverse")) {
+ sorttable.reverse(tr.sorttable_tbody);
+ tr.classList.replace('sorttable_sorted_reverse', 'sorttable_sorted');
} else {
// remove sorttable_sorted classes
- theadRow = this.parentNode;
+ theadRow = tr.parentNode;
theadRow.childNodes.forEach(function(cell) {
cell.classList.remove('sorttable_sorted_reverse', 'sorttable_sorted');
});
@@ -60,16 +62,16 @@ sorttable = {
// sort based on the sort keys, and then put the rows back in order
// which is a lot faster because you only do getInnerText once per row
row_array = [];
- col = this.sorttable_columnindex;
- rows = this.sorttable_tbody.rows;
+ col = tr.sorttable_columnindex;
+ rows = tr.sorttable_tbody.rows;
for (var j = 0; j < rows.length; j++) {
row_array[row_array.length] = [ sorttable.getElementValue(rows[j].cells[col]), rows[j] ];
}
row_array.sort().reverse();
- tb = this.sorttable_tbody;
+ tb = tr.sorttable_tbody;
row_array.forEach(function(row) { tb.appendChild(row[1]); });
delete row_array;
- this.classList.add('sorttable_sorted');
+ tr.classList.add('sorttable_sorted');
}
},