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
|
function Test(a, b, c) {
this.SetDelay(500);
this.SetContainer(a);
this.SetImageList(b.reverse());
this.SetString(c);
this.Mode = -1;
this.Paused = false;
this.Image = new Image();
var t = this;
$(document).keypress(function() {t.Unpause();})
}
Test.prototype = {
Start: function() {
var t = this;
this.Interval = window.setInterval(function(){t.Step();}, this.Delay);
},
Stop: function() {
this.Mode = -1;
this.Paused = false;
window.clearInterval(this.Interval);
},
Pause: function() {
this.Paused = true;
window.clearInterval(this.Interval);
},
Unpause: function() {
if (this.Paused) {
this.Paused = false;
this.Start();
}
},
SetString: function(a) {
this.String = a;
},
SetImage: function(a) {
this.Image.src = a;
},
SetImageList: function(a) {
var l = [];
for (x in a) {
l.push(new Image(a[x]);
}
this.ImageList = l;
},
SetContainer: function(a) {
this.Container = a;
},
SetDelay: function(a) {
this.Delay = a;
},
Step: function() {
/*
Modes:
S0: Viðbúinn!
S1: Stafur
S2: Bið
S3: Bið
S4: Tómt
S5: Mynd (halt)
*/
this.Mode++;
if (this.Mode == 6) {
this.Mode = 0;
}
switch(this.Mode) {
case 0:
this.Container.empty();
this.Container.addClass("ready");
this.Container.text("Viðbúinn!");
break;
case 1:
this.Container.removeClass("ready");
this.Container.addClass("letter");
this.Container.text(this.String[0]);
this.String = this.String.substr(1, this.String.length);
break;
case 2:
case 3:
break;
case 4:
this.Container.text("");
case 5:
this.SetImage(this.ImageList.pop());
this.Container.append(this.Image);
this.Pause();
}
}
}
|