commit: 151e4a0d8654c7013e6252b99341c9b250fbfd5b
parent: 189ba54314e1990bd493f46347d60c7a426cb434
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 17 May 2018 06:58:13 +0200
sorttable: Compatibility
Diffstat:
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/sorttable/sorttable.js b/sorttable/sorttable.js
@@ -1,20 +1,24 @@
/*
* Copyright 2007 Stuart Langridge http://www.kryogenix.org/code/browser/sorttable/
- * Copyright 2018 Haelwenn (lanodan) Monnier
- * Distributed under the terms of the X11 license http://www.kryogenix.org/code/browser/licence.html
+ * Distributed under the terms of the X11 license
+ *
+ * Copyright 2018 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
+ * Distributed under the terms of the CC-BY 4.0 License
*/
/* Usage:
- * Add <script src="sorttable.js"></script> to your HTML
+ * Add <script src="sorttable.js"></script> to your HTML pages
* Add class="sortable" to any table you'd like to make sortable
+ * See sorttable.css for an example of styling
*/
sorttable = {
+ done : false,
init : function() {
// quit if this function has already been called
- if (arguments.callee.done) return;
+ if (sorttable.done) return;
// flag this function so we don't do the same thing twice
- arguments.callee.done = true;
+ sorttable.done = true;
var sortableElements = document.getElementsByClassName("sortable");
Array.prototype.filter.call(sortableElements, function(sortableElement) {
@@ -45,11 +49,10 @@ sorttable = {
} else if (this.classList.contains("sorttable_sorted_reverse")) {
sorttable.reverse(this.sorttable_tbody);
this.classList.replace('sorttable_sorted_reverse', 'sorttable_sorted');
- return;
} else {
// remove sorttable_sorted classes
- theadrow = this.parentNode;
- theadrow.childNodes.forEach(function(cell) {
+ theadRow = this.parentNode;
+ theadRow.childNodes.forEach(function(cell) {
cell.classList.remove('sorttable_sorted_reverse', 'sorttable_sorted');
});
// build an array to sort. This is a Schwartzian transform thing,
@@ -62,7 +65,7 @@ sorttable = {
for (var j = 0; j < rows.length; j++) {
row_array[row_array.length] = [ sorttable.getElementValue(rows[j].cells[col]), rows[j] ];
}
- row_array.sort();
+ row_array.sort().reverse();
tb = this.sorttable_tbody;
row_array.forEach(function(row) { tb.appendChild(row[1]); });
delete row_array;
@@ -89,4 +92,4 @@ sorttable = {
}
};
-window.onload = sorttable.init()
+sorttable.init()