-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextMessage.js
51 lines (42 loc) · 1.29 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
class TextMessage {
constructor({text, onComplete}){
this.text = text
this.onComplete = onComplete
this.element = null
}
createElement() {
//Create element
this.element = document.createElement("div")
this.element.classList.add("TextMessage")
this.element.innerHTML = (`
<p class="TextMessage_p"></p>
<button class="TextMessage_button">Next</button>
`)
//Init type writer effect
this.revealingText = new RevealingText({
element: this.element.querySelector(".TextMessage_p"),
text: this.text,
})
this.element.querySelector("button").addEventListener("click", () => {
//Close 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()
}
}