/* Sortt @License MIT @Author 6543 Credits to Stuart Langridge, http://www.kryogenix.org/code/browser/sortt/ and its contributors */ sortt = { init: function() { // quit if this function has already been called if (arguments.callee.done) return; // flag this function so we don't do the same thing twice arguments.callee.done = true; // kill the timer if (_timer) clearInterval(_timer); if (!document.createElement || !document.getElementsByTagName) return; forEach(document.getElementsByTagName('table'), function(table) { if (table.className.search(/\bsortt\b/) != -1) { sortt.makeSortable(table); } }); }, makeSortable: function(table) { // table doesn't have a tHead ignore it if (table.getElementsByTagName('thead').length == 0) return; // Safari doesn't support table.tHead, sigh if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0]; if (table.tHead.rows.length != 1) return; // can't cope with two header rows // 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(/\bsortt_sorted_reverse\b/) != -1) { // if we're already sorted by this column in reverse, just // re-reverse the table, which is quicker 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 = "sortt_sortfwdind"; //sortfwdind.innerHTML = stIsIE ? ' 6' : ' ▾'; this.appendChild(sortfwdind); return; } // remove sortt_sorted classes theadrow = this.parentNode; forEach(theadrow.childNodes, function(cell) { if (cell.nodeType == 1) { // an element cell.className = cell.className.replace('sortt_sorted_reverse',''); cell.className = cell.className.replace('sortt_sorted',''); } }); sortfwdind = document.getElementById('sortt_sortfwdind'); if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); } sortrevind = document.getElementById('sortt_sortrevind'); if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); } this.className += ' sortt_sorted'; sortfwdind = document.createElement('span'); sortfwdind.id = "sortt_sortfwdind"; //sortfwdind.innerHTML = stIsIE ? ' 6' : ' ▾'; this.appendChild(sortfwdind); // build an array to sort. This is a Schwartzian transform thing, // i.e., we "decorate" each row with the actual sort key, // 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.sortt_columnindex; rows = this.sortt_tbody.rows; for (var j=0; j