-
Notifications
You must be signed in to change notification settings - Fork 0
/
jQueryDialogue.js
56 lines (49 loc) · 1.03 KB
/
jQueryDialogue.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
var i = 0;
var tp = 0;
var animateDialogue = true;
var textbox;
var ps;
var t;
var w = 50;
function AdvanceDialogue() {
i++;
tp=0;
textbox.text("");
t = setInterval("AnimateDialogue()", w);
AnimateDialogue();
}
function AddButtons() {
AddAdvanceButton();
}
function AddAdvanceButton() {
textbox.append('<input type="button" value="->" id="jQueryDialogue-next">');
$('input#jQueryDialogue-next').bind('click', function(event) {
AdvanceDialogue();
});
}
function AnimateDialogue() {
var p = ps.eq(i).text();
if (tp < p.length) {
var text = textbox.text();
textbox.text(text+(p.substr(tp,1)));
tp++;
} else {
clearInterval(t);
AddButtons();
}
}
function BeginDialogue() {
$('div#jQueryDialogue').prepend($('<div id="jQueryDialogue-textbox"></div>'));
textbox = $('div#jQueryDialogue-textbox');
ps = $('div#jQueryDialogue > p');
if (animateDialogue) {
textbox.text("");
t = setInterval("AnimateDialogue()", w);
AnimateDialogue();
} else {
textbox.text(ps.eq(i).text());
}
}
$(function(){
BeginDialogue();
});