]>
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 | |
f5fcd9f7 | 5 | const Button = videojs.getComponent('Button') |
c6352f2c C |
6 | class 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(), |
bd2b51be | 27 | innerHTML: (this.options_ as PeerTubeLinkButtonOptions).instanceName, |
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 | |
45 | videojs.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton) |