X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fassets%2Fplayer%2Fvideojs-components%2Fpeertube-link-button.ts;h=98434898cfd9f082dd48690161662f71124b89b7;hb=171efc48e67498406feb6d7873b3482b41505515;hp=fed8ea33e4b0ea8748d189774b42f5104bf270b0;hpb=b718fd22374d64534bcfe69932cf562894abed6a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/assets/player/videojs-components/peertube-link-button.ts b/client/src/assets/player/videojs-components/peertube-link-button.ts index fed8ea33e..98434898c 100644 --- a/client/src/assets/player/videojs-components/peertube-link-button.ts +++ b/client/src/assets/player/videojs-components/peertube-link-button.ts @@ -1,14 +1,15 @@ -import { VideoJSComponentInterface, videojsUntyped } from '../peertube-videojs-typings' -import { buildVideoLink } from '../utils' -// FIXME: something weird with our path definition in tsconfig and typings -// @ts-ignore -import { Player } from 'video.js' +import videojs from 'video.js' +import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' +import { PeerTubeLinkButtonOptions } from '../peertube-videojs-typings' -const Button: VideoJSComponentInterface = videojsUntyped.getComponent('Button') +const Button = videojs.getComponent('Button') class PeerTubeLinkButton extends Button { + private shortUUID: string - constructor (player: Player, options: any) { - super(player, options) + constructor (player: videojs.Player, options?: PeerTubeLinkButtonOptions) { + super(player, options as any) + + this.shortUUID = options.shortUUID } createEl () { @@ -16,25 +17,32 @@ class PeerTubeLinkButton extends Button { } updateHref () { - this.el().setAttribute('href', buildVideoLink(this.player().currentTime())) + this.el().setAttribute('href', this.buildLink()) } handleClick () { - this.player_.pause() + this.player().pause() } private buildElement () { - const el = videojsUntyped.dom.createEl('a', { - href: buildVideoLink(), + const el = videojs.dom.createEl('a', { + href: this.buildLink(), innerHTML: 'PeerTube', - title: this.player_.localize('Go to the video page'), + title: this.player().localize('Video page (new window)'), className: 'vjs-peertube-link', target: '_blank' }) el.addEventListener('mouseenter', () => this.updateHref()) - return el + return el as HTMLButtonElement + } + + private buildLink () { + const url = buildVideoLink({ shortUUID: this.shortUUID }) + + return decorateVideoLink({ url, startTime: this.player().currentTime() }) } } -Button.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton) + +videojs.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton)