-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmenu-screen.js
65 lines (52 loc) · 1.77 KB
/
menu-screen.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
62
63
64
65
// TODO(you): Modify the class in whatever ways necessary to implement
// the flashcard app behavior.
//
// You may need to do things such as:
// - Changing the constructor parameters
// - Adding methods
// - Adding additional fields
class MenuScreen {
constructor(containerElement) {
// for loop doesn't work
this.choiceDivHelper(0);
this.choiceDivHelper(1);
this.choiceDivHelper(2);
this.containerElement = containerElement;
this.addClickChoice();
}
show() {
this.containerElement.classList.remove('inactive');
}
hide() {
this.containerElement.classList.add('inactive');
}
choiceDivHelper(i){
// plug in topics from constant.js
const h = document.createElement("div") // Create a <h1> element
const t = document.createTextNode(FLASHCARD_DECKS[i]['title']); // Create a text node
h.appendChild(t);
const choiceDiv = document.querySelector('#choices');
choiceDiv.appendChild(h);
}
addClickChoice(){
const choiceDiv = document.querySelector('#choices');
this._initAnimCSS = this._initAnimCSS.bind(this);
this._initAnimBasic = this._initAnimBasic.bind(this);
this._initAnimFood = this._initAnimFood.bind(this);
choiceDiv.childNodes[0].addEventListener('click', this._initAnimCSS);
choiceDiv.childNodes[1].addEventListener('click', this._initAnimBasic);
choiceDiv.childNodes[2].addEventListener('click', this._initAnimFood);
}
_initAnimCSS(event){
this.hide();
document.dispatchEvent(new CustomEvent('css-menu-selected'));
}
_initAnimBasic(event){
this.hide();
document.dispatchEvent(new CustomEvent('basic-menu-selected'));
}
_initAnimFood(event){
this.hide();
document.dispatchEvent(new CustomEvent('food-menu-selected'));
}
}