aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/assets/player/peertube-link-button.ts
blob: de9a49de93dbb95fb94d3113c6a96888987f94d2 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                                                      
                                        


                                                                          



                                                                               
                                              


                          
               



                              
                                                                               







                                                 
                             
                            
                                                           


                                     



                                                              
   

                                                                  
import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
import { buildVideoLink } from './utils'
// FIXME: something weird with our path definition in tsconfig and typings
// @ts-ignore
import { Player } from 'video.js'

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

  constructor (player: Player, options: any) {
    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)