| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
var stIsIE = false; |
| 20 |
|
| 21 |
sorttable = { |
| 22 |
init: function() { |
| 23 |
|
| 24 |
if (arguments.callee.done) return; |
| 25 |
|
| 26 |
arguments.callee.done = true; |
| 27 |
|
| 28 |
if (_timer) clearInterval(_timer); |
| 29 |
|
| 30 |
if (!document.createElement || !document.getElementsByTagName) return; |
| 31 |
|
| 32 |
sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/; |
| 33 |
|
| 34 |
forEach(document.getElementsByTagName('table'), function(table) { |
| 35 |
if (table.className.search(/\bsortable\b/) != -1) { |
| 36 |
sorttable.makeSortable(table); |
| 37 |
} |
| 38 |
}); |
| 39 |
|
| 40 |
}, |
| 41 |
|
| 42 |
makeSortable: function(table) { |
| 43 |
if (table.getElementsByTagName('thead').length == 0) { |
| 44 |
|
| 45 |
|
| 46 |
the = document.createElement('thead'); |
| 47 |
the.appendChild(table.rows[0]); |
| 48 |
table.insertBefore(the,table.firstChild); |
| 49 |
} |
| 50 |
|
| 51 |
if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0]; |
| 52 |
|
| 53 |
if (table.tHead.rows.length != 1) return; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
sortbottomrows = []; |
| 60 |
for (var i=0; i<table.rows.length; i++) { |
| 61 |
if (table.rows[i].className.search(/\bsortbottom\b/) != -1) { |
| 62 |
sortbottomrows[sortbottomrows.length] = table.rows[i]; |
| 63 |
} |
| 64 |
} |
| 65 |
if (sortbottomrows) { |
| 66 |
if (table.tFoot == null) { |
| 67 |
|
| 68 |
tfo = document.createElement('tfoot'); |
| 69 |
table.appendChild(tfo); |
| 70 |
} |
| 71 |
for (var i=0; i<sortbottomrows.length; i++) { |
| 72 |
tfo.appendChild(sortbottomrows[i]); |
| 73 |
} |
| 74 |
delete sortbottomrows; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
headrow = table.tHead.rows[0].cells; |
| 79 |
for (var i=0; i<headrow.length; i++) { |
| 80 |
|
| 81 |
if (!headrow[i].className.match(/\bsorttable_nosort\b/)) { |
| 82 |
mtch = headrow[i].className.match(/\bsorttable_([a-z0-9]+)\b/); |
| 83 |
if (mtch) { override = mtch[1]; } |
| 84 |
if (mtch && typeof sorttable["sort_"+override] == 'function') { |
| 85 |
headrow[i].sorttable_sortfunction = sorttable["sort_"+override]; |
| 86 |
} else { |
| 87 |
headrow[i].sorttable_sortfunction = sorttable.guessType(table,i); |
| 88 |
} |
| 89 |
|
| 90 |
headrow[i].sorttable_columnindex = i; |
| 91 |
headrow[i].sorttable_tbody = table.tBodies[0]; |
| 92 |
dean_addEvent(headrow[i],"click", sorttable.innerSortFunction = function(e) { |
| 93 |
|
| 94 |
if (this.className.search(/\bsorttable_sorted\b/) != -1) { |
| 95 |
|
| 96 |
|
| 97 |
sorttable.reverse(this.sorttable_tbody); |
| 98 |
this.className = this.className.replace('sorttable_sorted', |
| 99 |
'sorttable_sorted_reverse'); |
| 100 |
this.removeChild(document.getElementById('sorttable_sortfwdind')); |
| 101 |
sortrevind = document.createElement('span'); |
| 102 |
sortrevind.id = "sorttable_sortrevind"; |
| 103 |
sortrevind.innerHTML = stIsIE ? ' <font face="webdings">5</font>' : ' ▴'; |
| 104 |
this.appendChild(sortrevind); |
| 105 |
return; |
| 106 |
} |
| 107 |
if (this.className.search(/\bsorttable_sorted_reverse\b/) != -1) { |
| 108 |
|
| 109 |
|
| 110 |
sorttable.reverse(this.sorttable_tbody); |
| 111 |
this.className = this.className.replace('sorttable_sorted_reverse', |
| 112 |
'sorttable_sorted'); |
| 113 |
this.removeChild(document.getElementById('sorttable_sortrevind')); |
| 114 |
sortfwdind = document.createElement('span'); |
| 115 |
sortfwdind.id = "sorttable_sortfwdind"; |
| 116 |
sortfwdind.innerHTML = stIsIE ? ' <font face="webdings">6</font>' : ' ▾'; |
| 117 |
this.appendChild(sortfwdind); |
| 118 |
return; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
theadrow = this.parentNode; |
| 123 |
forEach(theadrow.childNodes, function(cell) { |
| 124 |
if (cell.nodeType == 1) { |
| 125 |
cell.className = cell.className.replace('sorttable_sorted_reverse',''); |
| 126 |
cell.className = cell.className.replace('sorttable_sorted',''); |
| 127 |
} |
| 128 |
}); |
| 129 |
sortfwdind = document.getElementById('sorttable_sortfwdind'); |
| 130 |
if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); } |
| 131 |
sortrevind = document.getElementById('sorttable_sortrevind'); |
| 132 |
if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); } |
| 133 |
|
| 134 |
this.className += ' sorttable_sorted'; |
| 135 |
sortfwdind = document.createElement('span'); |
| 136 |
sortfwdind.id = "sorttable_sortfwdind"; |
| 137 |
sortfwdind.innerHTML = stIsIE ? ' <font face="webdings">6</font>' : ' ▾'; |
| 138 |
this.appendChild(sortfwdind); |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
row_array = []; |
| 145 |
col = this.sorttable_columnindex; |
| 146 |
rows = this.sorttable_tbody.rows; |
| 147 |
for (var j=0; j<rows.length; j++) { |
| 148 |
row_array[row_array.length] = [sorttable.getInnerText(rows[j].cells[col]), rows[j]]; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
row_array.sort(this.sorttable_sortfunction); |
| 154 |
|
| 155 |
row_array.reverse(); |
| 156 |
|
| 157 |
tb = this.sorttable_tbody; |
| 158 |
for (var j=0; j<row_array.length; j++) { |
| 159 |
tb.appendChild(row_array[j][1]); |
| 160 |
} |
| 161 |
|
| 162 |
delete row_array; |
| 163 |
}); |
| 164 |
} |
| 165 |
} |
| 166 |
}, |
| 167 |
|
| 168 |
guessType: function(table, column) { |
| 169 |
|
| 170 |
sortfn = sorttable.sort_alpha; |
| 171 |
for (var i=0; i<table.tBodies[0].rows.length; i++) { |
| 172 |
text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]); |
| 173 |
if (text != '') { |
| 174 |
if (text.match(/^-?[£$¤]?[\d,.]+\s*[%KMGTP]?[B]?$/)) { |
| 175 |
return sorttable.sort_numeric; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
possdate = text.match(sorttable.DATE_RE) |
| 181 |
if (possdate) { |
| 182 |
|
| 183 |
first = parseInt(possdate[1]); |
| 184 |
second = parseInt(possdate[2]); |
| 185 |
if (first > 12) { |
| 186 |
|
| 187 |
return sorttable.sort_ddmm; |
| 188 |
} else if (second > 12) { |
| 189 |
return sorttable.sort_mmdd; |
| 190 |
} else { |
| 191 |
|
| 192 |
|
| 193 |
sortfn = sorttable.sort_ddmm; |
| 194 |
} |
| 195 |
} |
| 196 |
} |
| 197 |
} |
| 198 |
return sortfn; |
| 199 |
}, |
| 200 |
|
| 201 |
getInnerText: function(node) { |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
if (!node) return ""; |
| 209 |
|
| 210 |
hasInputs = (typeof node.getElementsByTagName == 'function') && |
| 211 |
node.getElementsByTagName('input').length; |
| 212 |
|
| 213 |
if (node.getAttribute("sorttable_customkey") != null) { |
| 214 |
return node.getAttribute("sorttable_customkey"); |
| 215 |
} |
| 216 |
else if (typeof node.textContent != 'undefined' && !hasInputs) { |
| 217 |
return node.textContent.replace(/^\s+|\s+$/g, ''); |
| 218 |
} |
| 219 |
else if (typeof node.innerText != 'undefined' && !hasInputs) { |
| 220 |
return node.innerText.replace(/^\s+|\s+$/g, ''); |
| 221 |
} |
| 222 |
else if (typeof node.text != 'undefined' && !hasInputs) { |
| 223 |
return node.text.replace(/^\s+|\s+$/g, ''); |
| 224 |
} |
| 225 |
else { |
| 226 |
switch (node.nodeType) { |
| 227 |
case 3: |
| 228 |
if (node.nodeName.toLowerCase() == 'input') { |
| 229 |
return node.value.replace(/^\s+|\s+$/g, ''); |
| 230 |
} |
| 231 |
case 4: |
| 232 |
return node.nodeValue.replace(/^\s+|\s+$/g, ''); |
| 233 |
break; |
| 234 |
case 1: |
| 235 |
case 11: |
| 236 |
var innerText = ''; |
| 237 |
for (var i = 0; i < node.childNodes.length; i++) { |
| 238 |
innerText += sorttable.getInnerText(node.childNodes[i]); |
| 239 |
} |
| 240 |
return innerText.replace(/^\s+|\s+$/g, ''); |
| 241 |
break; |
| 242 |
default: |
| 243 |
return ''; |
| 244 |
} |
| 245 |
} |
| 246 |
}, |
| 247 |
|
| 248 |
reverse: function(tbody) { |
| 249 |
|
| 250 |
newrows = []; |
| 251 |
for (var i=0; i<tbody.rows.length; i++) { |
| 252 |
newrows[newrows.length] = tbody.rows[i]; |
| 253 |
} |
| 254 |
for (var i=newrows.length-1; i>=0; i--) { |
| 255 |
tbody.appendChild(newrows[i]); |
| 256 |
} |
| 257 |
delete newrows; |
| 258 |
}, |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
sort_numeric: function(a,b) { |
| 264 |
am = 1; |
| 265 |
if (a[0].match(/KB/)) { |
| 266 |
am = 1000; |
| 267 |
} else if (a[0].match(/MB/)) { |
| 268 |
am = 1000000; |
| 269 |
} else if (a[0].match(/GB/)) { |
| 270 |
am = 1000000000; |
| 271 |
} else if (a[0].match(/TB/)) { |
| 272 |
am = 1000000000000; |
| 273 |
} else if (a[0].match(/PB/)) { |
| 274 |
am = 1000000000000000; |
| 275 |
} |
| 276 |
aa = parseFloat(a[0].replace(/[^0-9.-]/g,'')); |
| 277 |
if (isNaN(aa)) aa = 0; |
| 278 |
aa = aa*am; |
| 279 |
bm = 1; |
| 280 |
if (b[0].match(/KB/)) { |
| 281 |
bm = 1000; |
| 282 |
} else if (b[0].match(/MB/)) { |
| 283 |
bm = 1000000; |
| 284 |
} else if (b[0].match(/GB/)) { |
| 285 |
bm = 1000000000; |
| 286 |
} else if (b[0].match(/TB/)) { |
| 287 |
bm = 1000000000000; |
| 288 |
} else if (b[0].match(/PB/)) { |
| 289 |
bm = 1000000000000000; |
| 290 |
} |
| 291 |
bb = parseFloat(b[0].replace(/[^0-9.-]/g,'')); |
| 292 |
if (isNaN(bb)) bb = 0; |
| 293 |
bb = bb*bm; |
| 294 |
|
| 295 |
return aa-bb; |
| 296 |
}, |
| 297 |
sort_alpha: function(a,b) { |
| 298 |
|
| 299 |
if (a[0].replace(/ <.*\(.*%\).*/, '')) { |
| 300 |
b[0].replace(/ <.*\(.*%\).*/,''); |
| 301 |
aa = parseFloat(a[0].replace(/[^0-9.-]/g,'')); |
| 302 |
if (isNaN(aa)) aa = 0; |
| 303 |
bb = parseFloat(b[0].replace(/[^0-9.-]/g,'')); |
| 304 |
if (isNaN(bb)) bb = 0; |
| 305 |
return aa-bb; |
| 306 |
} else { |
| 307 |
if (a[0]==b[0]) return 0; |
| 308 |
if (a[0]<b[0]) return -1; |
| 309 |
} |
| 310 |
return 1; |
| 311 |
}, |
| 312 |
sort_ddmm: function(a,b) { |
| 313 |
mtch = a[0].match(sorttable.DATE_RE); |
| 314 |
y = mtch[3]; m = mtch[2]; d = mtch[1]; |
| 315 |
if (m.length == 1) m = '0'+m; |
| 316 |
if (d.length == 1) d = '0'+d; |
| 317 |
dt1 = y+m+d; |
| 318 |
mtch = b[0].match(sorttable.DATE_RE); |
| 319 |
y = mtch[3]; m = mtch[2]; d = mtch[1]; |
| 320 |
if (m.length == 1) m = '0'+m; |
| 321 |
if (d.length == 1) d = '0'+d; |
| 322 |
dt2 = y+m+d; |
| 323 |
if (dt1==dt2) return 0; |
| 324 |
if (dt1<dt2) return -1; |
| 325 |
return 1; |
| 326 |
}, |
| 327 |
sort_mmdd: function(a,b) { |
| 328 |
mtch = a[0].match(sorttable.DATE_RE); |
| 329 |
y = mtch[3]; d = mtch[2]; m = mtch[1]; |
| 330 |
if (m.length == 1) m = '0'+m; |
| 331 |
if (d.length == 1) d = '0'+d; |
| 332 |
dt1 = y+m+d; |
| 333 |
mtch = b[0].match(sorttable.DATE_RE); |
| 334 |
y = mtch[3]; d = mtch[2]; m = mtch[1]; |
| 335 |
if (m.length == 1) m = '0'+m; |
| 336 |
if (d.length == 1) d = '0'+d; |
| 337 |
dt2 = y+m+d; |
| 338 |
if (dt1==dt2) return 0; |
| 339 |
if (dt1<dt2) return -1; |
| 340 |
return 1; |
| 341 |
}, |
| 342 |
|
| 343 |
shaker_sort: function(list, comp_func) { |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
var b = 0; |
| 348 |
var t = list.length - 1; |
| 349 |
var swap = true; |
| 350 |
|
| 351 |
while(swap) { |
| 352 |
swap = false; |
| 353 |
for(var i = b; i < t; ++i) { |
| 354 |
if ( comp_func(list[i], list[i+1]) > 0 ) { |
| 355 |
var q = list[i]; list[i] = list[i+1]; list[i+1] = q; |
| 356 |
swap = true; |
| 357 |
} |
| 358 |
} |
| 359 |
t--; |
| 360 |
|
| 361 |
if (!swap) break; |
| 362 |
|
| 363 |
for(var i = t; i > b; --i) { |
| 364 |
if ( comp_func(list[i], list[i-1]) < 0 ) { |
| 365 |
var q = list[i]; list[i] = list[i-1]; list[i-1] = q; |
| 366 |
swap = true; |
| 367 |
} |
| 368 |
} |
| 369 |
b++; |
| 370 |
|
| 371 |
} |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
if (document.addEventListener) { |
| 383 |
document.addEventListener("DOMContentLoaded", sorttable.init, false); |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
if (/WebKit/i.test(navigator.userAgent)) { |
| 400 |
var _timer = setInterval(function() { |
| 401 |
if (/loaded|complete/.test(document.readyState)) { |
| 402 |
sorttable.init(); |
| 403 |
} |
| 404 |
}, 10); |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
window.onload = sorttable.init; |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
function dean_addEvent(element, type, handler) { |
| 416 |
if (element.addEventListener) { |
| 417 |
element.addEventListener(type, handler, false); |
| 418 |
} else { |
| 419 |
|
| 420 |
if (!handler.$$guid) handler.$$guid = dean_addEvent.guid++; |
| 421 |
|
| 422 |
if (!element.events) element.events = {}; |
| 423 |
|
| 424 |
var handlers = element.events[type]; |
| 425 |
if (!handlers) { |
| 426 |
handlers = element.events[type] = {}; |
| 427 |
|
| 428 |
if (element["on" + type]) { |
| 429 |
handlers[0] = element["on" + type]; |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
handlers[handler.$$guid] = handler; |
| 434 |
|
| 435 |
element["on" + type] = handleEvent; |
| 436 |
} |
| 437 |
}; |
| 438 |
|
| 439 |
dean_addEvent.guid = 1; |
| 440 |
|
| 441 |
function removeEvent(element, type, handler) { |
| 442 |
if (element.removeEventListener) { |
| 443 |
element.removeEventListener(type, handler, false); |
| 444 |
} else { |
| 445 |
|
| 446 |
if (element.events && element.events[type]) { |
| 447 |
delete element.events[type][handler.$$guid]; |
| 448 |
} |
| 449 |
} |
| 450 |
}; |
| 451 |
|
| 452 |
function handleEvent(event) { |
| 453 |
var returnValue = true; |
| 454 |
|
| 455 |
event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event); |
| 456 |
|
| 457 |
var handlers = this.events[event.type]; |
| 458 |
|
| 459 |
for (var i in handlers) { |
| 460 |
this.$$handleEvent = handlers[i]; |
| 461 |
if (this.$$handleEvent(event) === false) { |
| 462 |
returnValue = false; |
| 463 |
} |
| 464 |
} |
| 465 |
return returnValue; |
| 466 |
}; |
| 467 |
|
| 468 |
function fixEvent(event) { |
| 469 |
|
| 470 |
event.preventDefault = fixEvent.preventDefault; |
| 471 |
event.stopPropagation = fixEvent.stopPropagation; |
| 472 |
return event; |
| 473 |
}; |
| 474 |
fixEvent.preventDefault = function() { |
| 475 |
this.returnValue = false; |
| 476 |
}; |
| 477 |
fixEvent.stopPropagation = function() { |
| 478 |
this.cancelBubble = true; |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
if (!Array.forEach) { |
| 490 |
Array.forEach = function(array, block, context) { |
| 491 |
for (var i = 0; i < array.length; i++) { |
| 492 |
block.call(context, array[i], i, array); |
| 493 |
} |
| 494 |
}; |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
Function.prototype.forEach = function(object, block, context) { |
| 499 |
for (var key in object) { |
| 500 |
if (typeof this.prototype[key] == "undefined") { |
| 501 |
block.call(context, object[key], key, object); |
| 502 |
} |
| 503 |
} |
| 504 |
}; |
| 505 |
|
| 506 |
|
| 507 |
String.forEach = function(string, block, context) { |
| 508 |
Array.forEach(string.split(""), function(chr, index) { |
| 509 |
block.call(context, chr, index, string); |
| 510 |
}); |
| 511 |
}; |
| 512 |
|
| 513 |
|
| 514 |
var forEach = function(object, block, context) { |
| 515 |
if (object) { |
| 516 |
var resolve = Object; |
| 517 |
if (object instanceof Function) { |
| 518 |
|
| 519 |
resolve = Function; |
| 520 |
} else if (object.forEach instanceof Function) { |
| 521 |
|
| 522 |
object.forEach(block, context); |
| 523 |
return; |
| 524 |
} else if (typeof object == "string") { |
| 525 |
|
| 526 |
resolve = String; |
| 527 |
} else if (typeof object.length == "number") { |
| 528 |
|
| 529 |
resolve = Array; |
| 530 |
} |
| 531 |
resolve.forEach(object, block, context); |
| 532 |
} |
| 533 |
}; |
| 534 |
|