forked from pkage/pkage.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartmenu.js
More file actions
48 lines (38 loc) · 1.35 KB
/
startmenu.js
File metadata and controls
48 lines (38 loc) · 1.35 KB
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
class StartMenuManager {
constructor() {
this.bg = document.querySelector('.start-menu__container')
this.menu = document.querySelector('.start-menu')
this.btn = document.querySelector('#start-btn')
this.btn.addEventListener('click', this.openStartMenu.bind(this))
this.bg.addEventListener('click', this.startMenuBackgroundClick.bind(this))
this.menu.querySelectorAll('[data-launch]')
.forEach(el => this.attachLaunchClickHandler(el))
this.menu.querySelectorAll('a')
.forEach(el => this.attachLinkClickHandler(el))
}
openStartMenu() {
this.bg.style.display = 'block'
this.btn.classList.add('start-btn--active')
}
startMenuBackgroundClick(e) {
if (e.target !== this.bg) {
return
}
this.closeStartMenu()
}
closeStartMenu() {
this.bg.style.display = 'none'
this.btn.classList.remove('start-btn--active')
}
attachLaunchClickHandler(el) {
if (!el.dataset.launch) {return;}
el.addEventListener('click', () => {
this.closeStartMenu()
window.pm.createInstance(el.dataset.launch)
})
}
attachLinkClickHandler(el) {
el.addEventListener('click', () => this.closeStartMenu())
}
}
window.sm = new StartMenuManager()