/* SortTable version 2 7th April 2007 Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/ Instructions: Download this file Add to your HTML Add class="sortable" to any table you'd like to make sortable Click on the headers to sort Thanks to many, many people for contributions and suggestions. Licenced as X11: http://www.kryogenix.org/code/browser/licence.html This basically means: do what you want with it. -- pfSense modifications -- Allow for sorting of IP adresses 2012-09-15 Allow for multiple header rows, using "sortableHeaderRowIdentifier" class for the TR that has the column headers. (used in firewall-log) 2012-09-15 Allow sorting multiple dual/mutlti rows together, using sortablemultirow="2" attribute for the table 2012-09-15 Allow sorting of IP:Port texts, changed sort compare function 2012-11-05 Allow sorting of IP:Port and *:port texts toghether also AAA_23 AAA_123 in 'numeric order' (used in Diagnostics\Sockets column LOCAL) */ var stIsIE = /*@cc_on!@*/false; sorttable = { 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; sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/; forEach(document.getElementsByTagName('table'), function(table) { if (table.className.search(/\bsortable\b/) != -1) { sorttable.makeSortable(table); } }); }, makeSortable: function(table) { if (table.getElementsByTagName('thead').length == 0) { // table doesn't have a tHead. Since it should have, create one and // put the first table row in it. the = document.createElement('thead'); the.appendChild(table.rows[0]); table.insertBefore(the,table.firstChild); } // Safari doesn't support table.tHead, sigh if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0]; headrow = undefined; if (table.tHead.rows.length == 1) headrow = table.tHead.rows[0].cells; else { //if multiple rows are found one must be marked with class