-
Notifications
You must be signed in to change notification settings - Fork 3
/
Header.js
101 lines (84 loc) · 2.59 KB
/
Header.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import $ from 'jquery'
import WindowAttached from '../helpers/WindowAttached'
import ThemeSwitcher, { THEMES } from '../scripts/ThemeSwitcher'
import { toggleClass, el as getEl } from '../helpers/dom_utils'
export class Header extends WindowAttached('header') {
themeSwitcher = new ThemeSwitcher({
onSwitchTheme: newTheme => {
$('.toggle.color').toggleClass('active', newTheme === THEMES.DARK)
},
})
deps = {
hotkeys: null,
}
configShowed = false
fullscreen = !!localStorage.getItem('fullscreen')
hotKeysEnabled = !!localStorage.getItem('hotkeys')
notificationsEnabled = !!localStorage.getItem('notifications')
constructor({ hotkeys }) {
super()
this.deps.hotkeys = hotkeys
$(document).ready(() => {
this.themeSwitcher.setTheme(localStorage.getItem('theme') || 'white')
this.updateFullscreen()
this.updateHotkeys()
this.updateNotifications()
window.addEventListener('click', () => {
if (this.configShowed) {
this.handleTitleClick(false)
}
})
})
}
handleThemeIconClick = () => {
this.themeSwitcher.switchTheme()
}
handleResizeIconClick = () => {
this.fullscreen = !this.fullscreen
this.updateFullscreen()
}
handleNotificationsIconClick = () => {
this.notificationsEnabled = !this.notificationsEnabled
this.updateNotifications()
}
handleTitleClick = overrideFlag => {
if (typeof overrideFlag === 'boolean') {
this.configShowed = overrideFlag
} else {
this.configShowed = !this.configShowed
window.event.stopPropagation()
}
document.body.setAttribute('config', this.configShowed ? 'show' : 'hide')
}
handleKeyboardIconClick = () => {
this.hotKeysEnabled = !this.hotKeysEnabled
this.updateHotkeys()
}
updateNotifications() {
toggleClass(
getEl('.main-button.notifications'),
'active',
this.notificationsEnabled
)
if (this.notificationsEnabled) {
localStorage.setItem('notifications', true)
} else {
delete localStorage.notifications
$('.task.updated').removeClass('updated')
}
}
updateFullscreen() {
toggleClass(getEl('.main-button.resize'), 'active', this.fullscreen)
if (this.fullscreen) {
localStorage.setItem('fullscreen', true)
document.body.setAttribute('fullscreen', 'true')
} else {
document.body.removeAttribute('fullscreen')
delete localStorage.fullscreen
}
}
updateHotkeys() {
toggleClass(getEl('.main-button.hot-keys'), 'active', this.hotKeysEnabled)
this.deps.hotkeys.triggerEnabled(this.hotKeysEnabled)
}
}