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

                                         
                                                                            


                          
               



                              
                                                                                              


                  
                         


                           
                                          
                             
                            
                                                               


                                     


                                                              
                                  
   
 

                                                                   
import { buildVideoLink } from '../utils'
import videojs from 'video.js'

const Button = videojs.getComponent('Button')
class PeerTubeLinkButton extends Button {

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

  createEl () {
    return this.buildElement()
  }

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

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

  private buildElement () {
    const el = videojs.dom.createEl('a', {
      href: buildVideoLink(),
      innerHTML: 'PeerTube',
      title: this.player().localize('Video page (new window)'),
      className: 'vjs-peertube-link',
      target: '_blank'
    })

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

    return el as HTMLButtonElement
  }
}

videojs.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton)