]>
Commit | Line | Data |
---|---|---|
512decf3 | 1 | import videojs from 'video.js' |
2adfc7ea | 2 | import { saveTheaterInStore, getStoredTheater } from '../peertube-player-local-storage' |
054a103b | 3 | |
f5fcd9f7 | 4 | const Button = videojs.getComponent('Button') |
054a103b C |
5 | class TheaterButton extends Button { |
6 | ||
7 | private static readonly THEATER_MODE_CLASS = 'vjs-theater-enabled' | |
8 | ||
7e37e111 | 9 | constructor (player: videojs.Player, options: videojs.ComponentOptions) { |
054a103b C |
10 | super(player, options) |
11 | ||
12 | const enabled = getStoredTheater() | |
13 | if (enabled === true) { | |
f5fcd9f7 | 14 | this.player().addClass(TheaterButton.THEATER_MODE_CLASS) |
9a18a625 | 15 | |
054a103b C |
16 | this.handleTheaterChange() |
17 | } | |
9a18a625 | 18 | |
f5fcd9f7 C |
19 | this.controlText('Theater mode') |
20 | ||
21 | this.player().theaterEnabled = enabled | |
054a103b C |
22 | } |
23 | ||
24 | buildCSSClass () { | |
25 | return `vjs-theater-control ${super.buildCSSClass()}` | |
26 | } | |
27 | ||
28 | handleTheaterChange () { | |
9a18a625 C |
29 | const theaterEnabled = this.isTheaterEnabled() |
30 | ||
31 | if (theaterEnabled) { | |
054a103b C |
32 | this.controlText('Normal mode') |
33 | } else { | |
34 | this.controlText('Theater mode') | |
35 | } | |
36 | ||
9a18a625 C |
37 | saveTheaterInStore(theaterEnabled) |
38 | ||
39 | this.player_.trigger('theaterChange', theaterEnabled) | |
054a103b C |
40 | } |
41 | ||
42 | handleClick () { | |
43 | this.player_.toggleClass(TheaterButton.THEATER_MODE_CLASS) | |
44 | ||
45 | this.handleTheaterChange() | |
46 | } | |
47 | ||
48 | private isTheaterEnabled () { | |
49 | return this.player_.hasClass(TheaterButton.THEATER_MODE_CLASS) | |
50 | } | |
51 | } | |
52 | ||
f5fcd9f7 | 53 | videojs.registerComponent('TheaterButton', TheaterButton) |