aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/peertube-link-button.ts
blob: 715207bc07ba419d7b9fe3cb6dafe9084dd8aef6 (plain) (blame)
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
import * as videojs from 'video.js'
import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
import { buildVideoLink } from './utils'

const Button: VideoJSComponentInterface = videojsUntyped.getComponent('Button')
class PeerTubeLinkButton extends Button {

  constructor (player: videojs.Player, options) {
    super(player, options)
  }

  createEl () {
    return this.buildElement()
  }

  updateHref () {
    this.el().setAttribute('href', buildVideoLink(this.player().currentTime()))
  }

  handleClick () {
    this.player_.pause()
  }

  private buildElement () {
    const el = videojsUntyped.dom.createEl('a', {
      href: buildVideoLink(),
      innerHTML: 'PeerTube',
      title: this.player_.localize('Go to the video page'),
      className: 'vjs-peertube-link',
      target: '_blank'
    })

    el.addEventListener('mouseenter', () => this.updateHref())

    return el
  }
}
Button.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton)