rename sorttable -> sortt

and remove som stuff
This commit is contained in:
6543 2019-08-27 14:27:57 +02:00
parent 21dc9ef50d
commit 12849ba6bc

128
sortt.js
View File

@ -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; i<headrow.length; i++) {
// manually override the type with a sorttable_type attribute
if (!headrow[i].className.match(/\bsorttable_nosort\b/)) { // skip this col
mtch = headrow[i].className.match(/\bsorttable_([a-z0-9]+)\b/);
// manually override the type with a sortt_type attribute
if (!headrow[i].className.match(/\bsortt_nosort\b/)) { // skip this col
mtch = headrow[i].className.match(/\bsortt_([a-z0-9]+)\b/);
if (mtch) { override = mtch[1]; }
if (mtch && typeof sorttable["sort_"+override] == 'function') {
headrow[i].sorttable_sortfunction = sorttable["sort_"+override];
if (mtch && typeof sortt["sort_"+override] == 'function') {
headrow[i].sortt_sortfunction = sortt["sort_"+override];
} else {
headrow[i].sorttable_sortfunction = sorttable.guessType(table,i);
headrow[i].sortt_sortfunction = sortt.guessType(table,i);
}
// make it clickable to sort
headrow[i].sorttable_columnindex = i;
headrow[i].sorttable_tbody = table.tBodies[0];
dean_addEvent(headrow[i],"click", sorttable.innerSortFunction = function(e) {
headrow[i].sortt_columnindex = i;
headrow[i].sortt_tbody = table.tBodies[0];
dean_addEvent(headrow[i],"click", sortt.innerSortFunction = function(e) {

if (this.className.search(/\bsorttable_sorted\b/) != -1) {
if (this.className.search(/\bsortt_sorted\b/) != -1) {
// if we're already sorted by this column, just
// reverse the table, which is quicker
sorttable.reverse(this.sorttable_tbody);
this.className = this.className.replace('sorttable_sorted',
'sorttable_sorted_reverse');
this.removeChild(document.getElementById('sorttable_sortfwdind'));
sortt.reverse(this.sortt_tbody);
this.className = this.className.replace('sortt_sorted',
'sortt_sorted_reverse');
this.removeChild(document.getElementById('sortt_sortfwdind'));
sortrevind = document.createElement('span');
sortrevind.id = "sorttable_sortrevind";
sortrevind.id = "sortt_sortrevind";
//sortrevind.innerHTML = stIsIE ? '&nbsp<font face="webdings">5</font>' : '&nbsp;&#x25B4;';
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 ? '&nbsp<font face="webdings">6</font>' : '&nbsp;&#x25BE;';
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 ? '&nbsp<font face="webdings">6</font>' : '&nbsp;&#x25BE;';
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<rows.length; j++) {
row_array[row_array.length] = [sorttable.getInnerText(rows[j].cells[col]), rows[j]];
row_array[row_array.length] = [sortt.getInnerText(rows[j].cells[col]), rows[j]];
}
/* If you want a stable sort, uncomment the following line */
//sorttable.shaker_sort(row_array, this.sorttable_sortfunction);
//sortt.shaker_sort(row_array, this.sortt_sortfunction);
/* and comment out this one */
row_array.sort(this.sorttable_sortfunction);
row_array.sort(this.sortt_sortfunction);

tb = this.sorttable_tbody;
tb = this.sortt_tbody;
for (var j=0; j<row_array.length; j++) {
tb.appendChild(row_array[j][1]);
}
@ -153,30 +151,30 @@ sorttable = {

guessType: function(table, column) {
// guess the type of a column based on its first non-blank row
sortfn = sorttable.sort_alpha;
sortfn = sortt.sort_alpha;
for (var i=0; i<table.tBodies[0].rows.length; i++) {
text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]);
text = sortt.getInnerText(table.tBodies[0].rows[i].cells[column]);
if (text != '') {
if (text.match(/^-?[£$€¤]?[\d,.]+%?$/)) {
return sorttable.sort_numeric;
return sortt.sort_numeric;
}
// check for a date: dd/mm/yyyy or dd/mm/yy
// can have / or . or - as separator
// can be mm/dd as well
possdate = text.match(sorttable.DATE_RE)
possdate = text.match(sortt.DATE_RE)
if (possdate) {
// looks like a date
first = parseInt(possdate[1]);
second = parseInt(possdate[2]);
if (first > 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 <input> 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("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
if (this.readyState == "complete") {
sorttable.init(); // call the onload handler
}
};
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
var _timer = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) {
sorttable.init(); // call the onload handler
sortt.init(); // call the onload handler
}
}, 10);
}

/* for other browsers */
window.onload = sorttable.init;
window.onload = sortt.init;

// written by Dean Edwards, 2005
// with input from Tino Zijdel, Matthias Miller, Diego Perini