From aecab3c29373db6e82c71b74856d5e1e7473ce96 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Wed, 3 Jan 2007 01:31:06 +0000 Subject: [PATCH] Steal better version of sorttable, tweak some: * (bug 8154) Initial empty values now don't screw up sorting * (bug 8155) Percentages sorted numerically --- includes/DefaultSettings.php | 2 +- skins/common/sorttable.js | 440 ++++++++++++++++++++++++----------- 2 files changed, 303 insertions(+), 139 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index bef233b35b..72f7dae9fb 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -664,7 +664,7 @@ $wgDTD = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'; /** Enable to allow rewriting dates in page text. * DOES NOT FORMAT CORRECTLY FOR MOST LANGUAGES */ -$wgUseDynamicDates = false; +$wgUseDynamicDates = true; /** Enable dates like 'May 12' instead of '12 May', this only takes effect if * the interface is set to English */ diff --git a/skins/common/sorttable.js b/skins/common/sorttable.js index 66b2edf157..706c6e84c7 100644 --- a/skins/common/sorttable.js +++ b/skins/common/sorttable.js @@ -1,44 +1,67 @@ /* - * From: http://www.kryogenix.org/code/browser/sorttable/ - * Licence: X11 + * Table sorting script by Joost de Valk, check it out at http://www.joostdevalk.nl/code/sortable-table/. + * Based on a script from http://www.kryogenix.org/code/browser/sorttable/. + * Distributed under the MIT license: http://www.kryogenix.org/code/browser/licence.html . + * + * Copyright (c) 1997-2006 Stuart Langridge, Joost de Valk. + * + * @todo language-specific digit grouping/decimals (bug 8063) + * @todo support all accepted date formats (bug 8226) */ +var image_path = stylepath+"/common/images/"; +var image_up = "sort_up.gif"; +var image_down = "sort_down.gif"; +var image_none = "sort_none.gif"; +var europeandate = wgContentLanguage != "en"; // The non-American-inclined can change to "true" + +var alternate_row_colors = true; + + hookEvent( "load", sortables_init); -var NO_ARROW = stylepath+'/common/sort_none.gif'; -var UP_ARROW = stylepath+'/common/sort_up.gif'; -var DOWN_ARROW = stylepath+'/common/sort_down.gif'; +var SORT_COLUMN_INDEX; +var thead = false; function sortables_init() { var idnum = 0; - // Find all tables with class sortable and make them sortable - if (!document.getElementsByTagName) return; - tbls = document.getElementsByTagName("table"); - for (ti=0;ti 0) { - var firstRow = table.rows[0]; - } - if (!firstRow) return; - - // We have a first row: assume it's the header, and make its contents clickable links - for (var i=0;i↕'; - } + if (table.rows && table.rows.length > 0) { + if (table.tHead && table.tHead.rows.length > 0) { + var firstRow = table.tHead.rows[table.tHead.rows.length-1]; + thead = true; + } else { + var firstRow = table.rows[0]; + } + } + if (!firstRow) return; + + // We have a first row: assume it's the header, and make its contents clickable links + for (var i=0;i↓'; + } + } + if (alternate_row_colors) { + alternate(table); + } } function ts_getInnerText(el) { @@ -63,132 +86,273 @@ function ts_getInnerText(el) { } function ts_resortTable(lnk) { - // get the arrow image - var img; - for (var ci=0;ci)*$/); i++) { + var itm = ts_getInnerText(table.tBodies[0].rows[i].cells[column]); + itm = trim(itm); + } + sortfn = ts_sort_caseinsensitive; + if (itm.match(/^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/)) sortfn = ts_sort_date; + if (itm.match(/^\d\d[\/.-]\d\d[\/.-]\d\d\d\d$/)) sortfn = ts_sort_date; + if (itm.match(/^\d\d[\/.-]\d\d[\/.-]\d\d$/)) sortfn = ts_sort_date; + if (itm.match(/^[£$€Û¢´]/)) sortfn = ts_sort_currency; + if (itm.match(/^[\d.,]+\%?$/)) sortfn = ts_sort_numeric; + SORT_COLUMN_INDEX = column; + var firstRow = new Array(); + var newRows = new Array(); + + for (k=0;k'; + newRows.reverse(); + span.setAttribute('sortdir','up'); + } else { + ARROW = '↑'; + span.setAttribute('sortdir','down'); + } + + // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones + // don't do sortbottom rows + for (i=0; i'; + } + } + } + + span.innerHTML = ARROW; + alternate(table); } function getParent(el, pTagName) { - if (el == null) return null; - else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) // Gecko bug, supposed to be uppercase + if (el == null) { + return null; + } else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) { // Gecko bug, supposed to be uppercase return el; - else + } else { return getParent(el.parentNode, pTagName); + } } -function ts_sort_date(a,b) { - if (a.grp != b.grp) return a.grp-b.grp; - // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX - aa = a.txt; - bb = b.txt; - if (aa.length == 10) { - dt1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2); - } else { - yr = aa.substr(6,2); - if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; } - dt1 = yr+aa.substr(3,2)+aa.substr(0,2); - } - if (bb.length == 10) { - dt2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2); - } else { - yr = bb.substr(6,2); - if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; } - dt2 = yr+bb.substr(3,2)+bb.substr(0,2); - } - if (dt1==dt2) return a.idx-b.idx; - if (dt1)*/, "").replace(/([ \t]|\n|\ |)*$/, ""); +} + +function alternate(table) { + // Take object table and get all it's tbodies. + var tableBodies = table.getElementsByTagName("tbody"); + // Loop through these tbodies + for (var i = 0; i < tableBodies.length; i++) { + // Take the tbody, and get all it's rows + var tableRows = tableBodies[i].getElementsByTagName("tr"); + // Loop through these rows + // Start at 1 because we want to leave the heading row untouched + for (var j = 0; j < tableRows.length; j++) { + // Check if j is even, and apply classes for both possible results + if ( (j % 2) == 0 ) { + if ( !(tableRows[j].className.indexOf('odd') == -1) ) { + tableRows[j].className = replace(tableRows[j].className, 'odd', 'even'); + } else { + if ( tableRows[j].className.indexOf('even') == -1 ) { + tableRows[j].className += " even"; + } + } + } else { + if ( !(tableRows[j].className.indexOf('even') == -1) ) { + tableRows[j].className = replace(tableRows[j].className, 'even', 'odd'); + } else { + if ( tableRows[j].className.indexOf('odd') == -1 ) { + tableRows[j].className += " odd"; + } + } + } + } + } } -- 2.20.1