]>
Commit | Line | Data |
---|---|---|
c6352f2c C |
1 | import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' |
2 | ||
3 | const Button: VideoJSComponentInterface = videojsUntyped.getComponent('Button') | |
4 | class 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 | } | |
43 | Button.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton) |