serverval.js
1.58 KB
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
function ServerVal(eId)
{
this.eId = eId;
this.eCtime = eId + " span:eq(1)";
this.eVnext = eId + " span:eq(2)";
this.eValue = eId + " span:eq(3)";
this.interval = null;
this.ctime = null;
this.vnext = 0;
this.value = null;
}
ServerVal.prototype.loadJSON = function(data)
{
this.ctime = new Date(data.ctime * 1000);
this.vnext = data.vnext;
this.value = data.value;
$.getJSON("/sessinfo/", $.proxy(sess.loadJSON, sess));
this.show();
}
ServerVal.prototype.show = function()
{
$(this.eCtime).empty().append(this.ctime.toString());
$(this.eVnext).empty().append(this.vnext);
$(this.eValue).empty().append(this.value);
if ($(this.eId).hasClass("hide")) {
$(this.eId).removeClass("hide");
}
}
ServerVal.prototype.start = function()
{
if (null === this.interval) {
this.interval = setInterval($.proxy(this.process, this), 1000);
}
}
ServerVal.prototype.process = function()
{
if (0 >= this.vnext) {
$.getJSON("/randval/", $.proxy(this.loadJSON, this))
.error($.proxy(function(xhr) {
this.stop();
$("#msg").append("AJAX error (" + xhr.status + "): ");
switch(xhr.status) {
case 403:
$("#msg").append(
"Please log in to access this function.<br />");
break;
default:
$("#msg").append(
"Unhandled - " + xhr.responseText + "<br />");
break;
}
}, this));
}
else {
this.vnext--;
$(this.eVnext).empty().append(this.vnext);
}
}
ServerVal.prototype.stop = function()
{
$(this.eId).addClass("hide");
clearInterval(this.interval);
this.interval = null;
this.vnext = 0;
}
// vim: set ts=4 sw=4: