From 12849ba6bca9c357319a2f02c9dbee8c5d8c219c Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 27 Aug 2019 14:27:57 +0200 Subject: [PATCH] rename sorttable -> sortt and remove som stuff --- sortt.js | 128 +++++++++++++++++++++++++------------------------------ 1 file changed, 57 insertions(+), 71 deletions(-) diff --git a/sortt.js b/sortt.js index c19a821..0b52192 100644 --- a/sortt.js +++ b/sortt.js @@ -3,10 +3,10 @@ @License MIT @Author 6543 - Credits to Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/ + Credits to Stuart Langridge, http://www.kryogenix.org/code/browser/sortt/ and its contributors */ -sorttable = { +sortt = { init: function() { // quit if this function has already been called if (arguments.callee.done) return; @@ -17,11 +17,9 @@ sorttable = { if (!document.createElement || !document.getElementsByTagName) return; - sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/; - forEach(document.getElementsByTagName('table'), function(table) { - if (table.className.search(/\bsorttable\b/) != -1) { - sorttable.makeSortable(table); + if (table.className.search(/\bsortt\b/) != -1) { + sortt.makeSortable(table); } }); @@ -40,7 +38,7 @@ sorttable = { if (table.tHead.rows.length != 1) return; // can't cope with two header rows - // Sorttable v1 put rows with a class of "sortbottom" at the bottom (as + // sortt v1 put rows with a class of "sortbottom" at the bottom (as // "total" rows, for example). This is B&R, since what you're supposed // to do is put them in a tfoot. So, if there are sortbottom rows, // for backwards compatibility, move them to tfoot (creating it if needed). @@ -65,63 +63,63 @@ sorttable = { // work through each column and calculate its type headrow = table.tHead.rows[0].cells; for (var i=0; i5' : ' ▴'; this.appendChild(sortrevind); return; } - if (this.className.search(/\bsorttable_sorted_reverse\b/) != -1) { + if (this.className.search(/\bsortt_sorted_reverse\b/) != -1) { // if we're already sorted by this column in reverse, just // re-reverse the table, which is quicker - sorttable.reverse(this.sorttable_tbody); - this.className = this.className.replace('sorttable_sorted_reverse', - 'sorttable_sorted'); - this.removeChild(document.getElementById('sorttable_sortrevind')); + sortt.reverse(this.sortt_tbody); + this.className = this.className.replace('sortt_sorted_reverse', + 'sortt_sorted'); + this.removeChild(document.getElementById('sortt_sortrevind')); sortfwdind = document.createElement('span'); - sortfwdind.id = "sorttable_sortfwdind"; + sortfwdind.id = "sortt_sortfwdind"; //sortfwdind.innerHTML = stIsIE ? ' 6' : ' ▾'; this.appendChild(sortfwdind); return; } - // remove sorttable_sorted classes + // remove sortt_sorted classes theadrow = this.parentNode; forEach(theadrow.childNodes, function(cell) { if (cell.nodeType == 1) { // an element - cell.className = cell.className.replace('sorttable_sorted_reverse',''); - cell.className = cell.className.replace('sorttable_sorted',''); + cell.className = cell.className.replace('sortt_sorted_reverse',''); + cell.className = cell.className.replace('sortt_sorted',''); } }); - sortfwdind = document.getElementById('sorttable_sortfwdind'); + sortfwdind = document.getElementById('sortt_sortfwdind'); if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); } - sortrevind = document.getElementById('sorttable_sortrevind'); + sortrevind = document.getElementById('sortt_sortrevind'); if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); } - this.className += ' sorttable_sorted'; + this.className += ' sortt_sorted'; sortfwdind = document.createElement('span'); - sortfwdind.id = "sorttable_sortfwdind"; + sortfwdind.id = "sortt_sortfwdind"; //sortfwdind.innerHTML = stIsIE ? ' 6' : ' ▾'; this.appendChild(sortfwdind); @@ -130,17 +128,17 @@ 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 = this.sortt_columnindex; + rows = this.sortt_tbody.rows; for (var j=0; j 12) { // definitely dd/mm - return sorttable.sort_ddmm; + return sortt.sort_ddmm; } else if (second > 12) { - return sorttable.sort_mmdd; + return sortt.sort_mmdd; } else { // looks like a date, but we can't tell which, so assume // that it's dd/mm (English imperialism!) and keep looking - sortfn = sorttable.sort_ddmm; + sortfn = sortt.sort_ddmm; } } } @@ -187,7 +185,7 @@ sorttable = { getInnerText: function(node) { // gets the text we want to use for sorting for a cell. // strips leading and trailing whitespace. - // this is *not* a generic getInnerText function; it's special to sorttable. + // this is *not* a generic getInnerText function; it's special to sortt. // for example, you can override the cell text with a customkey attribute. // it also gets .value for fields. @@ -196,8 +194,8 @@ sorttable = { hasInputs = (typeof node.getElementsByTagName == 'function') && node.getElementsByTagName('input').length; - if (node.getAttribute("sorttable_customkey") != null) { - return node.getAttribute("sorttable_customkey"); + if (node.getAttribute("sortt_customkey") != null) { + return node.getAttribute("sortt_customkey"); } else if (typeof node.textContent != 'undefined' && !hasInputs) { return node.textContent.replace(/^\s+|\s+$/g, ''); @@ -221,7 +219,7 @@ sorttable = { case 11: var innerText = ''; for (var i = 0; i < node.childNodes.length; i++) { - innerText += sorttable.getInnerText(node.childNodes[i]); + innerText += sortt.getInnerText(node.childNodes[i]); } return innerText.replace(/^\s+|\s+$/g, ''); break; @@ -259,12 +257,12 @@ sorttable = { return 1; }, sort_ddmm: function(a,b) { - mtch = a[0].match(sorttable.DATE_RE); + mtch = a[0].match(sortt.DATE_RE); y = mtch[3]; m = mtch[2]; d = mtch[1]; if (m.length == 1) m = '0'+m; if (d.length == 1) d = '0'+d; dt1 = y+m+d; - mtch = b[0].match(sorttable.DATE_RE); + mtch = b[0].match(sortt.DATE_RE); y = mtch[3]; m = mtch[2]; d = mtch[1]; if (m.length == 1) m = '0'+m; if (d.length == 1) d = '0'+d; @@ -274,12 +272,12 @@ sorttable = { return 1; }, sort_mmdd: function(a,b) { - mtch = a[0].match(sorttable.DATE_RE); + mtch = a[0].match(sortt.DATE_RE); y = mtch[3]; d = mtch[2]; m = mtch[1]; if (m.length == 1) m = '0'+m; if (d.length == 1) d = '0'+d; dt1 = y+m+d; - mtch = b[0].match(sorttable.DATE_RE); + mtch = b[0].match(sortt.DATE_RE); y = mtch[3]; d = mtch[2]; m = mtch[1]; if (m.length == 1) m = '0'+m; if (d.length == 1) d = '0'+d; @@ -329,32 +327,20 @@ sorttable = { /* for Mozilla/Opera9 */ if (document.addEventListener) { - document.addEventListener("DOMContentLoaded", sorttable.init, false); + document.addEventListener("DOMContentLoaded", sortt.init, false); } -/* for Internet Explorer */ -/*@cc_on @*/ -/*@if (@_win32) - document.write("