session.js
1.5 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
function Session(sId)
{
this.eSid = $(sId + " span");
this.canvas = $(sId + " canvas").get(0);
this.context = this.canvas.getContext("2d");
this.id = "none"
this.timeout = 0;
this.timeleft = 0;
this.username = "";
this.interval = null;
this.draw();
}
Session.prototype.loadJSON = function(data)
{
this.id = ("0" == data.id)? "none" : data.id;
this.timeout = data.timeout * 10;
this.timeleft = data.timeleft * 10;
this.username = data.username;
this.eSid.empty().append(this.id);
$("#main span:eq(0)").empty().append(" " + this.username);
this.draw();
if (0 < this.timeleft)
this.start();
}
Session.prototype.draw = function()
{
this.context.fillStyle = "rgb(255, 0, 0)";
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
this.context.fillStyle = "rgb(0, 255, 0)";
this.context.fillRect(0, 0,
this.canvas.width / this.timeout * this.timeleft,
this.canvas.height);
}
Session.prototype.start = function()
{
if (null === this.interval) {
this.interval = setInterval($.proxy(this.process, this), 100);
}
}
Session.prototype.process = function()
{
if (0 >= this.timeleft) {
this.stop();
}
else {
this.timeleft--;
this.draw();
}
}
Session.prototype.stop = function()
{
clearInterval(this.interval);
this.interval = null;
this.id = "none";
this.timeout = 0;
this.timeleft = 0;
this.username = "";
this.eSid.empty().append(this.id);
$("#main span:eq(0)").empty().append(" " + this.username);
this.draw();
}
// vim: set ts=4 sw=4: