]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/assets/player/peertube-link-button.ts
Fix resume video after peertube embed link click
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / peertube-link-button.ts
CommitLineData
c6352f2c
C
1import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
2
3const Button: VideoJSComponentInterface = videojsUntyped.getComponent('Button')
4class PeerTubeLinkButton extends Button {
5
6 createEl () {
fc73684a
C
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(),
c6352f2c
C
22 innerHTML: 'PeerTube',
23 title: 'Go to the video page',
24 className: 'vjs-peertube-link',
25 target: '_blank'
26 })
fc73684a
C
27
28 el.addEventListener('mouseenter', () => this.updateHref())
29
30 return el
c6352f2c
C
31 }
32
fc73684a
C
33 private buildHref (time?: number) {
34 let href = window.location.href.replace('embed', 'watch')
b4f8277c
C
35 if (time) {
36 if (window.location.search) href += '&start=' + time
37 else href += '?start=' + time
38 }
fc73684a
C
39
40 return href
c6352f2c
C
41 }
42}
43Button.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton)