-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextMessage.js
61 lines (51 loc) · 1.41 KB
/
TextMessage.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
class TextMessage {
constructor({ text, link, onComplete }) {
this.text = text;
this.onComplete = onComplete;
this.element = null;
this.link = link;
}
createElement() {
//Create the element
this.element = document.createElement("div");
this.element.classList.add("TextMessage");
if (this.link) {
this.element.innerHTML = (`
<p class="TextMessage_p"></p>
<a href="${this.link}" target="_blank" class="TextMessage_a">Download</a>
<button class="TextMessage_button">Next</button>
`)
} else {
this.element.innerHTML = (`
<p class="TextMessage_p"></p>
<button class="TextMessage_button">Next</button>
`)
}
//Init the typewriter effect
this.revealingText = new RevealingText({
element: this.element.querySelector(".TextMessage_p"),
text: this.text
})
this.element.querySelector("button").addEventListener("click", () => {
//Close the text message
this.done();
});
this.actionListener = new KeyPressListener("Enter", () => {
this.done();
})
}
done() {
if (this.revealingText.isDone) {
this.element.remove();
this.actionListener.unbind();
this.onComplete();
} else {
this.revealingText.warpToDone();
}
}
init(container) {
this.createElement();
container.appendChild(this.element);
this.revealingText.init();
}
}