]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/assets/player/videojs-components/peertube-link-button.ts
Fix peertube link button
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / videojs-components / peertube-link-button.ts
CommitLineData
512decf3 1import videojs from 'video.js'
15a7eafb 2import { buildVideoLink, decorateVideoLink } from '@shared/core-utils'
9162fdd3 3import { PeerTubeLinkButtonOptions } from '../peertube-videojs-typings'
c6352f2c 4
f5fcd9f7 5const Button = videojs.getComponent('Button')
c6352f2c
C
6class PeerTubeLinkButton extends Button {
7
9162fdd3
C
8 constructor (player: videojs.Player, options?: PeerTubeLinkButtonOptions) {
9 super(player, options as any)
960a11e8
C
10 }
11
c6352f2c 12 createEl () {
fc73684a
C
13 return this.buildElement()
14 }
15
16 updateHref () {
9162fdd3 17 this.el().setAttribute('href', this.buildLink())
fc73684a
C
18 }
19
20 handleClick () {
f5fcd9f7 21 this.player().pause()
fc73684a
C
22 }
23
24 private buildElement () {
f5fcd9f7 25 const el = videojs.dom.createEl('a', {
9162fdd3 26 href: this.buildLink(),
c6352f2c 27 innerHTML: 'PeerTube',
d6d951dd 28 title: this.player().localize('Video page (new window)'),
c6352f2c
C
29 className: 'vjs-peertube-link',
30 target: '_blank'
31 })
fc73684a
C
32
33 el.addEventListener('mouseenter', () => this.updateHref())
34
f5fcd9f7 35 return el as HTMLButtonElement
c6352f2c 36 }
9162fdd3
C
37
38 private buildLink () {
23ca2f7b 39 const url = buildVideoLink({ shortUUID: (this.options_ as PeerTubeLinkButtonOptions).shortUUID })
9162fdd3
C
40
41 return decorateVideoLink({ url, startTime: this.player().currentTime() })
42 }
c6352f2c 43}
f5fcd9f7
C
44
45videojs.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton)