-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextMessage.js
42 lines (34 loc) · 1.07 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
class TextMessage {
constructor({ text, onComplete}) {
this.text = text;
this.onComplete = onComplete;
this.element = null;
}
// create a div and populate it with stuff from scratch
createElement() {
//create the element here
this.element = document.createElement("div");
this.element.classList.add("TextMessage");
this.element.innerHTML = (`
<p class="TextMessage_p">${this.text}</p>
<button class="TextMessage_button">Next</button>
` )
this.element.querySelector("button").addEventListener("click", () =>{
//close text message ez
this.done();
});
this.actionListener = new KeyPressListener("Enter", () =>{
//not always neccessary for this to have the unbind just in this case it is
this.actionListener.unbind();
this.done();
});
}
done(){
this.element.remove();
this.onComplete();
}
init(container) {
this.createElement();
container.appendChild(this.element);
}
}