|
@@ -1,328 +0,0 @@
|
1
|
|
-/*
|
2
|
|
-Table sorting script by Joost de Valk, check it out at http://www.joostdevalk.nl/code/sortable-table/.
|
3
|
|
-Based on a script from http://www.kryogenix.org/code/browser/sorttable/.
|
4
|
|
-Distributed under the MIT license: http://www.kryogenix.org/code/browser/licence.html .
|
5
|
|
-
|
6
|
|
-Copyright (c) 1997-2006 Stuart Langridge, Joost de Valk.
|
7
|
|
-
|
8
|
|
-Version 1.5.6
|
9
|
|
-*/
|
10
|
|
-
|
11
|
|
-/* You can change these values */
|
12
|
|
-var image_path = "http://www.joostdevalk.nl/code/sortable-table/";
|
13
|
|
-var image_up = "arrow-up.gif";
|
14
|
|
-var image_down = "arrow-down.gif";
|
15
|
|
-var image_none = "arrow-none.gif";
|
16
|
|
-var europeandate = true;
|
17
|
|
-var alternate_row_colors = true;
|
18
|
|
-
|
19
|
|
-/* Don't change anything below this unless you know what you're doing */
|
20
|
|
-addEvent(window, "load", sortables_init);
|
21
|
|
-
|
22
|
|
-var SORT_COLUMN_INDEX;
|
23
|
|
-var thead = false;
|
24
|
|
-
|
25
|
|
-function sortables_init() {
|
26
|
|
- // Find all tables with class sortable and make them sortable
|
27
|
|
- if (!document.getElementsByTagName) return;
|
28
|
|
- tbls = document.getElementsByTagName("table");
|
29
|
|
- for (ti=0;ti<tbls.length;ti++) {
|
30
|
|
- thisTbl = tbls[ti];
|
31
|
|
- if (((' '+thisTbl.className+' ').indexOf("sortable") != -1) && (thisTbl.id)) {
|
32
|
|
- ts_makeSortable(thisTbl);
|
33
|
|
- }
|
34
|
|
- }
|
35
|
|
-}
|
36
|
|
-
|
37
|
|
-function ts_makeSortable(t) {
|
38
|
|
- if (t.rows && t.rows.length > 0) {
|
39
|
|
- if (t.tHead && t.tHead.rows.length > 0) {
|
40
|
|
- var firstRow = t.tHead.rows[t.tHead.rows.length-1];
|
41
|
|
- thead = true;
|
42
|
|
- } else {
|
43
|
|
- var firstRow = t.rows[0];
|
44
|
|
- }
|
45
|
|
- }
|
46
|
|
- if (!firstRow) return;
|
47
|
|
-
|
48
|
|
- // We have a first row: assume it's the header, and make its contents clickable links
|
49
|
|
- for (var i=0;i<firstRow.cells.length;i++) {
|
50
|
|
- var cell = firstRow.cells[i];
|
51
|
|
- var txt = ts_getInnerText(cell);
|
52
|
|
- if (cell.className != "unsortable" && cell.className.indexOf("unsortable") == -1) {
|
53
|
|
- cell.innerHTML = '<a href="#" class="sortheader" onclick="ts_resortTable(this, '+i+');return false;">'+txt+'<span class="sortarrow"> <img src="'+ image_path + image_none + '" alt="↓"/></span></a>';
|
54
|
|
- }
|
55
|
|
- }
|
56
|
|
- if (alternate_row_colors) {
|
57
|
|
- alternate(t);
|
58
|
|
- }
|
59
|
|
-}
|
60
|
|
-
|
61
|
|
-function ts_getInnerText(el) {
|
62
|
|
- if (typeof el == "string") return el;
|
63
|
|
- if (typeof el == "undefined") { return el };
|
64
|
|
- if (el.innerText) return el.innerText; //Not needed but it is faster
|
65
|
|
- var str = "";
|
66
|
|
-
|
67
|
|
- var cs = el.childNodes;
|
68
|
|
- var l = cs.length;
|
69
|
|
- for (var i = 0; i < l; i++) {
|
70
|
|
- switch (cs[i].nodeType) {
|
71
|
|
- case 1: //ELEMENT_NODE
|
72
|
|
- str += ts_getInnerText(cs[i]);
|
73
|
|
- break;
|
74
|
|
- case 3: //TEXT_NODE
|
75
|
|
- str += cs[i].nodeValue;
|
76
|
|
- break;
|
77
|
|
- }
|
78
|
|
- }
|
79
|
|
- return str;
|
80
|
|
-}
|
81
|
|
-
|
82
|
|
-function ts_resortTable(lnk, clid) {
|
83
|
|
- var span;
|
84
|
|
- for (var ci=0;ci<lnk.childNodes.length;ci++) {
|
85
|
|
- if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci];
|
86
|
|
- }
|
87
|
|
- var spantext = ts_getInnerText(span);
|
88
|
|
- var td = lnk.parentNode;
|
89
|
|
- var column = clid || td.cellIndex;
|
90
|
|
- var t = getParent(td,'TABLE');
|
91
|
|
- // Work out a type for the column
|
92
|
|
- if (t.rows.length <= 1) return;
|
93
|
|
- var itm = "";
|
94
|
|
- var i = 1;
|
95
|
|
- while (itm == "") {
|
96
|
|
- var itm = ts_getInnerText(t.tBodies[0].rows[i].cells[column]);
|
97
|
|
- itm = trim(itm);
|
98
|
|
- if (itm.substr(0,4) == "<!--" || itm.length == 0) {
|
99
|
|
- itm = "";
|
100
|
|
- }
|
101
|
|
- i++;
|
102
|
|
- }
|
103
|
|
- sortfn = ts_sort_caseinsensitive;
|
104
|
|
- if (itm.match(/^\d\d[\/\.-][a-zA-z][a-zA-Z][a-zA-Z][\/\.-]\d\d\d\d$/)) sortfn = ts_sort_date;
|
105
|
|
- if (itm.match(/^\d\d[\/\.-]\d\d[\/\.-]\d\d\d{2}?$/)) sortfn = ts_sort_date;
|
106
|
|
- if (itm.match(/^-?[£$€Û¢´]\d/)) sortfn = ts_sort_numeric;
|
107
|
|
- if (itm.match(/^-?(\d+[,\.]?)+(E[-+][\d]+)?%?$/)) sortfn = ts_sort_numeric;
|
108
|
|
- SORT_COLUMN_INDEX = column;
|
109
|
|
- var firstRow = new Array();
|
110
|
|
- var newRows = new Array();
|
111
|
|
- for (k=0;k<t.tBodies.length;k++) {
|
112
|
|
- for (i=0;i<t.tBodies[k].rows[0].length;i++) {
|
113
|
|
- firstRow[i] = t.tBodies[k].rows[0][i];
|
114
|
|
- }
|
115
|
|
- }
|
116
|
|
- for (k=0;k<t.tBodies.length;k++) {
|
117
|
|
- if (!thead) {
|
118
|
|
- // Skip the first row
|
119
|
|
- for (j=1;j<t.tBodies[k].rows.length;j++) {
|
120
|
|
- newRows[j-1] = t.tBodies[k].rows[j];
|
121
|
|
- }
|
122
|
|
- } else {
|
123
|
|
- // Do NOT skip the first row
|
124
|
|
- for (j=0;j<t.tBodies[k].rows.length;j++) {
|
125
|
|
- newRows[j] = t.tBodies[k].rows[j];
|
126
|
|
- }
|
127
|
|
- }
|
128
|
|
- }
|
129
|
|
- newRows.sort(sortfn);
|
130
|
|
- if (span.getAttribute("sortdir") == 'down') {
|
131
|
|
- ARROW = ' <img src="'+ image_path + image_down + '" alt="↓"/>';
|
132
|
|
- newRows.reverse();
|
133
|
|
- span.setAttribute('sortdir','up');
|
134
|
|
- } else {
|
135
|
|
- ARROW = ' <img src="'+ image_path + image_up + '" alt="↑"/>';
|
136
|
|
- span.setAttribute('sortdir','down');
|
137
|
|
- }
|
138
|
|
- // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
|
139
|
|
- // don't do sortbottom rows
|
140
|
|
- for (i=0; i<newRows.length; i++) {
|
141
|
|
- if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) {
|
142
|
|
- t.tBodies[0].appendChild(newRows[i]);
|
143
|
|
- }
|
144
|
|
- }
|
145
|
|
- // do sortbottom rows only
|
146
|
|
- for (i=0; i<newRows.length; i++) {
|
147
|
|
- if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1))
|
148
|
|
- t.tBodies[0].appendChild(newRows[i]);
|
149
|
|
- }
|
150
|
|
- // Delete any other arrows there may be showing
|
151
|
|
- var allspans = document.getElementsByTagName("span");
|
152
|
|
- for (var ci=0;ci<allspans.length;ci++) {
|
153
|
|
- if (allspans[ci].className == 'sortarrow') {
|
154
|
|
- if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us?
|
155
|
|
- allspans[ci].innerHTML = ' <img src="'+ image_path + image_none + '" alt="↓"/>';
|
156
|
|
- }
|
157
|
|
- }
|
158
|
|
- }
|
159
|
|
- span.innerHTML = ARROW;
|
160
|
|
- alternate(t);
|
161
|
|
-}
|
162
|
|
-
|
163
|
|
-function getParent(el, pTagName) {
|
164
|
|
- if (el == null) {
|
165
|
|
- return null;
|
166
|
|
- } else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) {
|
167
|
|
- return el;
|
168
|
|
- } else {
|
169
|
|
- return getParent(el.parentNode, pTagName);
|
170
|
|
- }
|
171
|
|
-}
|
172
|
|
-
|
173
|
|
-function sort_date(date) {
|
174
|
|
- // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
|
175
|
|
- dt = "00000000";
|
176
|
|
- if (date.length == 11) {
|
177
|
|
- mtstr = date.substr(3,3);
|
178
|
|
- mtstr = mtstr.toLowerCase();
|
179
|
|
- switch(mtstr) {
|
180
|
|
- case "jan": var mt = "01"; break;
|
181
|
|
- case "feb": var mt = "02"; break;
|
182
|
|
- case "mar": var mt = "03"; break;
|
183
|
|
- case "apr": var mt = "04"; break;
|
184
|
|
- case "may": var mt = "05"; break;
|
185
|
|
- case "jun": var mt = "06"; break;
|
186
|
|
- case "jul": var mt = "07"; break;
|
187
|
|
- case "aug": var mt = "08"; break;
|
188
|
|
- case "sep": var mt = "09"; break;
|
189
|
|
- case "oct": var mt = "10"; break;
|
190
|
|
- case "nov": var mt = "11"; break;
|
191
|
|
- case "dec": var mt = "12"; break;
|
192
|
|
- // default: var mt = "00";
|
193
|
|
- }
|
194
|
|
- dt = date.substr(7,4)+mt+date.substr(0,2);
|
195
|
|
- return dt;
|
196
|
|
- } else if (date.length == 10) {
|
197
|
|
- if (europeandate == false) {
|
198
|
|
- dt = date.substr(6,4)+date.substr(0,2)+date.substr(3,2);
|
199
|
|
- return dt;
|
200
|
|
- } else {
|
201
|
|
- dt = date.substr(6,4)+date.substr(3,2)+date.substr(0,2);
|
202
|
|
- return dt;
|
203
|
|
- }
|
204
|
|
- } else if (date.length == 8) {
|
205
|
|
- yr = date.substr(6,2);
|
206
|
|
- if (parseInt(yr) < 50) {
|
207
|
|
- yr = '20'+yr;
|
208
|
|
- } else {
|
209
|
|
- yr = '19'+yr;
|
210
|
|
- }
|
211
|
|
- if (europeandate == true) {
|
212
|
|
- dt = yr+date.substr(3,2)+date.substr(0,2);
|
213
|
|
- return dt;
|
214
|
|
- } else {
|
215
|
|
- dt = yr+date.substr(0,2)+date.substr(3,2);
|
216
|
|
- return dt;
|
217
|
|
- }
|
218
|
|
- }
|
219
|
|
- return dt;
|
220
|
|
-}
|
221
|
|
-
|
222
|
|
-function ts_sort_date(a,b) {
|
223
|
|
- dt1 = sort_date(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]));
|
224
|
|
- dt2 = sort_date(ts_getInnerText(b.cells[SORT_COLUMN_INDEX]));
|
225
|
|
-
|
226
|
|
- if (dt1==dt2) {
|
227
|
|
- return 0;
|
228
|
|
- }
|
229
|
|
- if (dt1<dt2) {
|
230
|
|
- return -1;
|
231
|
|
- }
|
232
|
|
- return 1;
|
233
|
|
-}
|
234
|
|
-function ts_sort_numeric(a,b) {
|
235
|
|
- var aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
|
236
|
|
- aa = clean_num(aa);
|
237
|
|
- var bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
|
238
|
|
- bb = clean_num(bb);
|
239
|
|
- return compare_numeric(aa,bb);
|
240
|
|
-}
|
241
|
|
-function compare_numeric(a,b) {
|
242
|
|
- var a = parseFloat(a);
|
243
|
|
- a = (isNaN(a) ? 0 : a);
|
244
|
|
- var b = parseFloat(b);
|
245
|
|
- b = (isNaN(b) ? 0 : b);
|
246
|
|
- return a - b;
|
247
|
|
-}
|
248
|
|
-function ts_sort_caseinsensitive(a,b) {
|
249
|
|
- aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase();
|
250
|
|
- bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();
|
251
|
|
- if (aa==bb) {
|
252
|
|
- return 0;
|
253
|
|
- }
|
254
|
|
- if (aa<bb) {
|
255
|
|
- return -1;
|
256
|
|
- }
|
257
|
|
- return 1;
|
258
|
|
-}
|
259
|
|
-function ts_sort_default(a,b) {
|
260
|
|
- aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
|
261
|
|
- bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
|
262
|
|
- if (aa==bb) {
|
263
|
|
- return 0;
|
264
|
|
- }
|
265
|
|
- if (aa<bb) {
|
266
|
|
- return -1;
|
267
|
|
- }
|
268
|
|
- return 1;
|
269
|
|
-}
|
270
|
|
-function addEvent(elm, evType, fn, useCapture)
|
271
|
|
-// addEvent and removeEvent
|
272
|
|
-// cross-browser event handling for IE5+, NS6 and Mozilla
|
273
|
|
-// By Scott Andrew
|
274
|
|
-{
|
275
|
|
- if (elm.addEventListener){
|
276
|
|
- elm.addEventListener(evType, fn, useCapture);
|
277
|
|
- return true;
|
278
|
|
- } else if (elm.attachEvent){
|
279
|
|
- var r = elm.attachEvent("on"+evType, fn);
|
280
|
|
- return r;
|
281
|
|
- } else {
|
282
|
|
- alert("Handler could not be removed");
|
283
|
|
- }
|
284
|
|
-}
|
285
|
|
-function clean_num(str) {
|
286
|
|
- str = str.replace(new RegExp(/[^-?0-9.]/g),"");
|
287
|
|
- return str;
|
288
|
|
-}
|
289
|
|
-function trim(s) {
|
290
|
|
- while (s.substring(0,1) == ' ') {
|
291
|
|
- s = s.substring(1,s.length);
|
292
|
|
- }
|
293
|
|
- while (s.substring(s.length-1,s.length) == ' ') {
|
294
|
|
- s = s.substring(0,s.length-1);
|
295
|
|
- }
|
296
|
|
- return s;
|
297
|
|
-}
|
298
|
|
-function alternate(table) {
|
299
|
|
- // Take object table and get all it's tbodies.
|
300
|
|
- var tableBodies = table.getElementsByTagName("tbody");
|
301
|
|
- // Loop through these tbodies
|
302
|
|
- for (var i = 0; i < tableBodies.length; i++) {
|
303
|
|
- // Take the tbody, and get all it's rows
|
304
|
|
- var tableRows = tableBodies[i].getElementsByTagName("tr");
|
305
|
|
- // Loop through these rows
|
306
|
|
- // Start at 1 because we want to leave the heading row untouched
|
307
|
|
- for (var j = 0; j < tableRows.length; j++) {
|
308
|
|
- // Check if j is even, and apply classes for both possible results
|
309
|
|
- if ( (j % 2) == 0 ) {
|
310
|
|
- if ( !(tableRows[j].className.indexOf('odd') == -1) ) {
|
311
|
|
- tableRows[j].className = tableRows[j].className.replace('odd', 'even');
|
312
|
|
- } else {
|
313
|
|
- if ( tableRows[j].className.indexOf('even') == -1 ) {
|
314
|
|
- tableRows[j].className += " even";
|
315
|
|
- }
|
316
|
|
- }
|
317
|
|
- } else {
|
318
|
|
- if ( !(tableRows[j].className.indexOf('even') == -1) ) {
|
319
|
|
- tableRows[j].className = tableRows[j].className.replace('even', 'odd');
|
320
|
|
- } else {
|
321
|
|
- if ( tableRows[j].className.indexOf('odd') == -1 ) {
|
322
|
|
- tableRows[j].className += " odd";
|
323
|
|
- }
|
324
|
|
- }
|
325
|
|
- }
|
326
|
|
- }
|
327
|
|
- }
|
328
|
|
-}
|