]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/assets/player/peertube-link-button.ts
Resume video on peertube link click in embed
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / peertube-link-button.ts
1 import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
2
3 const Button: VideoJSComponentInterface = videojsUntyped.getComponent('Button')
4 class PeerTubeLinkButton extends Button {
5
6 createEl () {
7 return this.buildElement()
8 }
9
10 updateHref () {
11 const currentTime = Math.floor(this.player().currentTime())
12 this.el().setAttribute('href', this.buildHref(currentTime))
13 }
14
15 handleClick () {
16 this.player_.pause()
17 }
18
19 private buildElement () {
20 const el = videojsUntyped.dom.createEl('a', {
21 href: this.buildHref(),
22 innerHTML: 'PeerTube',
23 title: 'Go to the video page',
24 className: 'vjs-peertube-link',
25 target: '_blank'
26 })
27
28 el.addEventListener('mouseenter', () => this.updateHref())
29
30 return el
31 }
32
33 private buildHref (time?: number) {
34 let href = window.location.href.replace('embed', 'watch')
35 if (time) href += '?start=' + time
36
37 return href
38 }
39 }
40 Button.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton)