]>
Commit | Line | Data |
---|---|---|
512decf3 | 1 | import videojs from 'video.js' |
15a7eafb | 2 | import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' |
57d65032 | 3 | import { PeerTubeLinkButtonOptions } from '../../types' |
c6352f2c | 4 | |
c9c21faf C |
5 | const Component = videojs.getComponent('Component') |
6 | class PeerTubeLinkButton extends Component { | |
c6352f2c | 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 | ||
fc73684a | 20 | private buildElement () { |
f5fcd9f7 | 21 | const el = videojs.dom.createEl('a', { |
9162fdd3 | 22 | href: this.buildLink(), |
bd2b51be | 23 | innerHTML: (this.options_ as PeerTubeLinkButtonOptions).instanceName, |
d6d951dd | 24 | title: this.player().localize('Video page (new window)'), |
c6352f2c C |
25 | className: 'vjs-peertube-link', |
26 | target: '_blank' | |
27 | }) | |
fc73684a C |
28 | |
29 | el.addEventListener('mouseenter', () => this.updateHref()) | |
c9c21faf | 30 | el.addEventListener('click', () => this.player().pause()) |
fc73684a | 31 | |
f5fcd9f7 | 32 | return el as HTMLButtonElement |
c6352f2c | 33 | } |
9162fdd3 C |
34 | |
35 | private buildLink () { | |
23ca2f7b | 36 | const url = buildVideoLink({ shortUUID: (this.options_ as PeerTubeLinkButtonOptions).shortUUID }) |
9162fdd3 C |
37 | |
38 | return decorateVideoLink({ url, startTime: this.player().currentTime() }) | |
39 | } | |
c6352f2c | 40 | } |
f5fcd9f7 C |
41 | |
42 | videojs.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton) |