-
Notifications
You must be signed in to change notification settings - Fork 6
/
chorus.js
92 lines (72 loc) · 2.71 KB
/
chorus.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
import { createSnipControls } from '../components/snip/snip-controls.js'
import { createSpeedControls } from '../components/speed/speed-controls.js'
import { createSeekControls } from '../components/seek/seek-controls.js'
import { createEffectsControls } from '../components/effects/effects-controls.js'
import { createEqualizerControls } from '../components/equalizer/equalizer-controls.js'
import HeaderListeners from '../events/listeners/header-listeners.js'
import ActionListeners from '../events/listeners/action-listeners.js'
import { parseNodeString } from '../utils/parser.js'
import { spotifyVideo } from '../actions/overload.js'
import { clickOutside } from '../utils/click-outside.js'
export default class Chorus {
constructor(songTracker) {
this._songTracker = songTracker
this._video = spotifyVideo.element
this._clickOutsideHandler = null
}
init() {
this.headerListeners = new HeaderListeners(this._songTracker)
this.actionListeners = new ActionListeners(this._songTracker)
}
get isShowing() {
if (!this.mainElement) return false
return this.mainElement.style.display == 'block'
}
get mainElement() {
return document.getElementById('chorus-main')
}
get chorusControls() {
return document.getElementById('chorus-controls')
}
async toggle() {
this.isShowing ? await this.hide() : this.show()
}
get #hasSnipControls() {
return !!document.getElementById('chorus-snip-controls')
}
#setupModal() {
if (this._clickOutsideHandler) return
this._clickOutsideHandler = clickOutside({ node: this.mainElement })
this.mainElement.addEventListener('click_outside', this.hide)
}
#insertIntoDOM() {
if (this.#hasSnipControls) return
const controls = [
createSnipControls(),
createSpeedControls(),
createSeekControls(),
createEffectsControls(),
createEqualizerControls()
].map(parseNodeString)
controls.forEach((control) => this.chorusControls.appendChild(control))
}
#cleanUpOutsideHandler() {
this._clickOutsideHandler?.destroy()
this._clickOutsideHandler = null
}
hide = async () => {
if (!this.mainElement) return
await this.headerListeners.hide()
this.mainElement.style.display = 'none'
this._video.resetTempTimes()
this.#cleanUpOutsideHandler()
this.headerListeners._reverb.destroyClickHandlers()
}
show() {
this.#insertIntoDOM()
this.mainElement.style.display = 'block'
this.headerListeners.init()
this.actionListeners.init()
this.#setupModal()
}
}