From e7b5a760e5b26e54d6fb5cfb33d1ac044855becc Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Mon, 20 Nov 2006 06:09:29 +0000 Subject: [PATCH] (bug 2001) Implement sortable tables. sorttable.js is loaded conditionally based on whether a sortable table is on the page, so there should be no unneeded hits. --- RELEASE-NOTES | 2 + skins/common/sorttable.js | 194 ++++++++++++++++++++++++++++++++++++++ skins/common/wikibits.js | 44 +++++++++ 3 files changed, 240 insertions(+) create mode 100644 skins/common/sorttable.js diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 893baf2fb0..eea8240ab7 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -201,6 +201,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 7688) When viewing diff, section anchors in autosummary jump to section on current page instead of loading the latest version. * (bug 7970) Use current connection explicitly on Database::getServerVersion +* (bug 2001) Tables with class="sortable" can now be dynamically sorted via + JavaScript. == Languages updated == diff --git a/skins/common/sorttable.js b/skins/common/sorttable.js new file mode 100644 index 0000000000..1752f08463 --- /dev/null +++ b/skins/common/sorttable.js @@ -0,0 +1,194 @@ +/* + * From: http://www.kryogenix.org/code/browser/sorttable/ + * Licence: X11 + */ + +addEvent(window, "load", sortables_init); + +var SORT_COLUMN_INDEX; + +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'; + } +} + +function ts_getInnerText(el) { + if (typeof el == "string") return el; + if (typeof el == "undefined") { return el }; + if (el.innerText) return el.innerText; //Not needed but it is faster + var str = ""; + + var cs = el.childNodes; + var l = cs.length; + for (var i = 0; i < l; i++) { + switch (cs[i].nodeType) { + case 1: //ELEMENT_NODE + str += ts_getInnerText(cs[i]); + break; + case 3: //TEXT_NODE + str += cs[i].nodeValue; + break; + } + } + return str; +} + +function ts_resortTable(lnk) { + // get the span + var span; + for (var ci=0;ci'); + } +} + + function runOnloadHook() { // don't run anything below this for non-dom browsers if (doneOnloadHook || !(document.getElementById && document.getElementsByTagName)) { @@ -813,6 +856,7 @@ function runOnloadHook() { akeytt(); scrollEditBox(); setupCheckboxShiftClick(); + sortableTables(); // Run any added-on functions for (var i = 0; i < onloadFuncts.length; i++) { -- 2.20.1