PeerTube/client/src/assets/player/videojs-components/theater-button.ts

54 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-01-28 10:29:50 -06:00
import videojs, { VideoJsPlayer } from 'video.js'
import { saveTheaterInStore, getStoredTheater } from '../peertube-player-local-storage'
2018-06-11 09:49:56 -05:00
2020-01-28 10:29:50 -06:00
const Button = videojs.getComponent('Button')
2018-06-11 09:49:56 -05:00
class TheaterButton extends Button {
private static readonly THEATER_MODE_CLASS = 'vjs-theater-enabled'
2020-01-28 10:29:50 -06:00
constructor (player: VideoJsPlayer, options: videojs.ComponentOptions) {
2018-06-11 09:49:56 -05:00
super(player, options)
const enabled = getStoredTheater()
if (enabled === true) {
2020-01-28 10:29:50 -06:00
this.player().addClass(TheaterButton.THEATER_MODE_CLASS)
2019-03-18 04:26:53 -05:00
2018-06-11 09:49:56 -05:00
this.handleTheaterChange()
}
2019-03-18 04:26:53 -05:00
2020-01-28 10:29:50 -06:00
this.controlText('Theater mode')
this.player().theaterEnabled = enabled
2018-06-11 09:49:56 -05:00
}
buildCSSClass () {
return `vjs-theater-control ${super.buildCSSClass()}`
}
handleTheaterChange () {
2019-03-18 04:26:53 -05:00
const theaterEnabled = this.isTheaterEnabled()
if (theaterEnabled) {
2018-06-11 09:49:56 -05:00
this.controlText('Normal mode')
} else {
this.controlText('Theater mode')
}
2019-03-18 04:26:53 -05:00
saveTheaterInStore(theaterEnabled)
this.player_.trigger('theaterChange', theaterEnabled)
2018-06-11 09:49:56 -05:00
}
handleClick () {
this.player_.toggleClass(TheaterButton.THEATER_MODE_CLASS)
this.handleTheaterChange()
}
private isTheaterEnabled () {
return this.player_.hasClass(TheaterButton.THEATER_MODE_CLASS)
}
}
2020-01-28 10:29:50 -06:00
videojs.registerComponent('TheaterButton', TheaterButton)