-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighscores.js
101 lines (88 loc) · 2.86 KB
/
highscores.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
$(document).ready(function(){
var amountUsersWithoutAP = 0;
var apSum = 0;
var KEYCODE_ESC = 27;
$.getJSON("http://www.wintergate.se/index.php?event=wg11&controller=user&action=all&format=json&callback=?", function(data){
users = data || [{id:1,ap:1000,username:"Test (no users retrieved from system)"}];
$.each(users, function(i, user){
var htmlClass = 'user';
if (user.ap == 0){
htmlClass += ' zero_ap';
amountUsersWithoutAP++;
}
var row = document.createElement("tr");
row.className = htmlClass;
row.id = 'user_' + user.id;
var usernameColumn = document.createElement("td");
usernameColumn.innerHTML = '<a href="http://www.wintergate.se/index.php?controller=user&action=show&id=' + user.id + '">' + user.username + '</a>';
usernameColumn.className = 'username';
var apColumn = document.createElement("td");
//apColumn.innerHTML = thousandSeparator(user.ap, " "); // Not used since it prevents sorting by integer order.
apColumn.innerHTML = parseInt(user.ap);
apColumn.className = 'ap';
row.appendChild(usernameColumn);
row.appendChild(apColumn);
$("#users tbody").append(row);
apSum += user.ap;
}); // end $.each()
var tfoot = document.createElement("tfoot");
var row = document.createElement("tr");
var userTotalColumn = document.createElement("th");
userTotalColumn.innerHTML = users.length + ' användare (' + amountUsersWithoutAP + ' utan AP)';
var apTotalColumn = document.createElement("th");
apTotalColumn.innerHTML = thousandSeparator(apSum, ' ') + ' AP';
row.appendChild(userTotalColumn);
row.appendChild(apTotalColumn);
tfoot.appendChild(row);
$("#users").append(tfoot);
$("#users").dataTable({
"aaSorting": [[ 1, "desc" ], [ 0, "asc" ]],
"aoColumns": [
{ "sType": "html" },
{ "sType": "numeric"}
],
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"bInfo": false,
"bAutoWidth": false,
"oLanguage": {
"sSearch": "Sök:"
}
});
clearSearchBox();
}); // end $.getJSON()
$(document).keyup(function(e){
if(e.keyCode == KEYCODE_ESC){
clearSearchBox();
}
});
}); // end $(document).ready()
function clearSearchBox(){
$("#users_filter input").val("");
$("#users_filter input").focus();
$("#users_filter input").submit();
}
/*
* thousandSeparator (NUMBER n, STRING separator) STRING
* or
* thousandSeparator (String n, STRING sep) STRING
*
* Convert a number to the format xxx,xxx,xxx.xxxx
* Accepts integers, floating point or string
*
* Does not accept exponential notation, etc.
*
* n – the number to be formatted
* sep – the separator character. if skipped, “,” is used
*/
function thousandSeparator(n,sep) {
var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'), sValue=n+"";
if (sep === undefined) {
sep=',';
}
while(sRegExp.test(sValue)) {
sValue = sValue.replace(sRegExp, '$1'+sep+'$2');
}
return sValue;
}