diff options
Diffstat (limited to 'client/src/assets/player/shared/control-bar/peertube-link-button.ts')
-rw-r--r-- | client/src/assets/player/shared/control-bar/peertube-link-button.ts | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/client/src/assets/player/shared/control-bar/peertube-link-button.ts b/client/src/assets/player/shared/control-bar/peertube-link-button.ts new file mode 100644 index 000000000..6d83263cc --- /dev/null +++ b/client/src/assets/player/shared/control-bar/peertube-link-button.ts | |||
@@ -0,0 +1,45 @@ | |||
1 | import videojs from 'video.js' | ||
2 | import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' | ||
3 | import { PeerTubeLinkButtonOptions } from '../../types' | ||
4 | |||
5 | const Button = videojs.getComponent('Button') | ||
6 | class PeerTubeLinkButton extends Button { | ||
7 | |||
8 | constructor (player: videojs.Player, options?: PeerTubeLinkButtonOptions) { | ||
9 | super(player, options as any) | ||
10 | } | ||
11 | |||
12 | createEl () { | ||
13 | return this.buildElement() | ||
14 | } | ||
15 | |||
16 | updateHref () { | ||
17 | this.el().setAttribute('href', this.buildLink()) | ||
18 | } | ||
19 | |||
20 | handleClick () { | ||
21 | this.player().pause() | ||
22 | } | ||
23 | |||
24 | private buildElement () { | ||
25 | const el = videojs.dom.createEl('a', { | ||
26 | href: this.buildLink(), | ||
27 | innerHTML: 'PeerTube', | ||
28 | title: this.player().localize('Video page (new window)'), | ||
29 | className: 'vjs-peertube-link', | ||
30 | target: '_blank' | ||
31 | }) | ||
32 | |||
33 | el.addEventListener('mouseenter', () => this.updateHref()) | ||
34 | |||
35 | return el as HTMLButtonElement | ||
36 | } | ||
37 | |||
38 | private buildLink () { | ||
39 | const url = buildVideoLink({ shortUUID: (this.options_ as PeerTubeLinkButtonOptions).shortUUID }) | ||
40 | |||
41 | return decorateVideoLink({ url, startTime: this.player().currentTime() }) | ||
42 | } | ||
43 | } | ||
44 | |||
45 | videojs.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton) | ||