aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/shared/control-bar/peertube-link-button.ts
diff options
context:
space:
mode:
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.ts47
1 files changed, 34 insertions, 13 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
index 45d7ac42f..8242b9cea 100644
--- a/client/src/assets/player/shared/control-bar/peertube-link-button.ts
+++ b/client/src/assets/player/shared/control-bar/peertube-link-button.ts
@@ -3,37 +3,58 @@ import { buildVideoLink, decorateVideoLink } from '@shared/core-utils'
3import { PeerTubeLinkButtonOptions } from '../../types' 3import { PeerTubeLinkButtonOptions } from '../../types'
4 4
5const Component = videojs.getComponent('Component') 5const Component = videojs.getComponent('Component')
6
6class PeerTubeLinkButton extends Component { 7class PeerTubeLinkButton extends Component {
8 private mouseEnterHandler: () => void
9 private clickHandler: () => void
7 10
8 constructor (player: videojs.Player, options?: PeerTubeLinkButtonOptions) { 11 options_: PeerTubeLinkButtonOptions & videojs.ComponentOptions
9 super(player, options as any)
10 }
11 12
12 createEl () { 13 constructor (player: videojs.Player, options?: PeerTubeLinkButtonOptions & videojs.ComponentOptions) {
13 return this.buildElement() 14 super(player, options)
15
16 this.updateShowing()
17 this.player().on('video-change', () => this.updateShowing())
14 } 18 }
15 19
16 updateHref () { 20 dispose () {
17 this.el().setAttribute('href', this.buildLink()) 21 if (this.el()) return
22
23 this.el().removeEventListener('mouseenter', this.mouseEnterHandler)
24 this.el().removeEventListener('click', this.clickHandler)
25
26 super.dispose()
18 } 27 }
19 28
20 private buildElement () { 29 createEl () {
21 const el = videojs.dom.createEl('a', { 30 const el = videojs.dom.createEl('a', {
22 href: this.buildLink(), 31 href: this.buildLink(),
23 innerHTML: (this.options_ as PeerTubeLinkButtonOptions).instanceName, 32 innerHTML: this.options_.instanceName,
24 title: this.player().localize('Video page (new window)'), 33 title: this.player().localize('Video page (new window)'),
25 className: 'vjs-peertube-link', 34 className: 'vjs-peertube-link',
26 target: '_blank' 35 target: '_blank'
27 }) 36 })
28 37
29 el.addEventListener('mouseenter', () => this.updateHref()) 38 this.mouseEnterHandler = () => this.updateHref()
30 el.addEventListener('click', () => this.player().pause()) 39 this.clickHandler = () => this.player().pause()
40
41 el.addEventListener('mouseenter', this.mouseEnterHandler)
42 el.addEventListener('click', this.clickHandler)
43
44 return el
45 }
46
47 updateShowing () {
48 if (this.options_.isDisplayed()) this.show()
49 else this.hide()
50 }
31 51
32 return el as HTMLButtonElement 52 updateHref () {
53 this.el().setAttribute('href', this.buildLink())
33 } 54 }
34 55
35 private buildLink () { 56 private buildLink () {
36 const url = buildVideoLink({ shortUUID: (this.options_ as PeerTubeLinkButtonOptions).shortUUID }) 57 const url = buildVideoLink({ shortUUID: this.options_.shortUUID() })
37 58
38 return decorateVideoLink({ url, startTime: this.player().currentTime() }) 59 return decorateVideoLink({ url, startTime: this.player().currentTime() })
39 } 60 }