diff options
author | Chocobozzz <me@florianbigard.com> | 2019-06-12 12:40:24 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-06-12 16:44:15 +0200 |
commit | 2f4c784a92ac50cacef07f4925e284b4041422f4 (patch) | |
tree | 159e744c68c5f5cd8054b5f63eb389553e13bf56 /client/src/assets | |
parent | 011e1e6b37e15a44624b2d0e50263e16382060d2 (diff) | |
download | PeerTube-2f4c784a92ac50cacef07f4925e284b4041422f4.tar.gz PeerTube-2f4c784a92ac50cacef07f4925e284b4041422f4.tar.zst PeerTube-2f4c784a92ac50cacef07f4925e284b4041422f4.zip |
Add params to share modal
Diffstat (limited to 'client/src/assets')
-rw-r--r-- | client/src/assets/player/peertube-player-manager.ts | 2 | ||||
-rw-r--r-- | client/src/assets/player/utils.ts | 51 | ||||
-rw-r--r-- | client/src/assets/player/videojs-components/peertube-link-button.ts | 2 |
3 files changed, 46 insertions, 9 deletions
diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts index 8f6237326..083c621d2 100644 --- a/client/src/assets/player/peertube-player-manager.ts +++ b/client/src/assets/player/peertube-player-manager.ts | |||
@@ -446,7 +446,7 @@ export class PeertubePlayerManager { | |||
446 | label: player.localize('Copy the video URL at the current time'), | 446 | label: player.localize('Copy the video URL at the current time'), |
447 | listener: function () { | 447 | listener: function () { |
448 | const player = this as videojs.Player | 448 | const player = this as videojs.Player |
449 | copyToClipboard(buildVideoLink(player.currentTime())) | 449 | copyToClipboard(buildVideoLink({ startTime: player.currentTime() })) |
450 | } | 450 | } |
451 | }, | 451 | }, |
452 | { | 452 | { |
diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index 366689962..777abb568 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts | |||
@@ -27,18 +27,55 @@ function isMobile () { | |||
27 | return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) | 27 | return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) |
28 | } | 28 | } |
29 | 29 | ||
30 | function buildVideoLink (time?: number, url?: string) { | 30 | function buildVideoLink (options: { |
31 | if (!url) url = window.location.origin + window.location.pathname.replace('/embed/', '/watch/') | 31 | baseUrl?: string, |
32 | 32 | ||
33 | if (time) { | 33 | startTime?: number, |
34 | const timeInt = Math.floor(time) | 34 | stopTime?: number, |
35 | 35 | ||
36 | const params = new URLSearchParams(window.location.search) | 36 | subtitle?: string, |
37 | params.set('start', secondsToTime(timeInt)) | ||
38 | 37 | ||
39 | return url + '?' + params.toString() | 38 | loop?: boolean, |
39 | autoplay?: boolean, | ||
40 | muted?: boolean, | ||
41 | |||
42 | // Embed options | ||
43 | title?: boolean, | ||
44 | warningTitle?: boolean, | ||
45 | controls?: boolean | ||
46 | } = {}) { | ||
47 | const { baseUrl } = options | ||
48 | |||
49 | const url = baseUrl | ||
50 | ? baseUrl | ||
51 | : window.location.origin + window.location.pathname.replace('/embed/', '/watch/') | ||
52 | |||
53 | const params = new URLSearchParams(window.location.search) | ||
54 | |||
55 | if (options.startTime) { | ||
56 | const startTimeInt = Math.floor(options.startTime) | ||
57 | params.set('start', secondsToTime(startTimeInt)) | ||
58 | } | ||
59 | |||
60 | if (options.stopTime) { | ||
61 | const stopTimeInt = Math.floor(options.stopTime) | ||
62 | params.set('stop', secondsToTime(stopTimeInt)) | ||
40 | } | 63 | } |
41 | 64 | ||
65 | if (options.subtitle) params.set('subtitle', options.subtitle) | ||
66 | |||
67 | if (options.loop === true) params.set('loop', '1') | ||
68 | if (options.autoplay === true) params.set('autoplay', '1') | ||
69 | if (options.muted === true) params.set('muted', '1') | ||
70 | if (options.title === false) params.set('title', '0') | ||
71 | if (options.warningTitle === false) params.set('warningTitle', '0') | ||
72 | if (options.controls === false) params.set('controls', '0') | ||
73 | |||
74 | let hasParams = false | ||
75 | params.forEach(() => hasParams = true) | ||
76 | |||
77 | if (hasParams) return url + '?' + params.toString() | ||
78 | |||
42 | return url | 79 | return url |
43 | } | 80 | } |
44 | 81 | ||
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..4d0ea37f5 100644 --- a/client/src/assets/player/videojs-components/peertube-link-button.ts +++ b/client/src/assets/player/videojs-components/peertube-link-button.ts | |||
@@ -16,7 +16,7 @@ class PeerTubeLinkButton extends Button { | |||
16 | } | 16 | } |
17 | 17 | ||
18 | updateHref () { | 18 | updateHref () { |
19 | this.el().setAttribute('href', buildVideoLink(this.player().currentTime())) | 19 | this.el().setAttribute('href', buildVideoLink({ startTime: this.player().currentTime() })) |
20 | } | 20 | } |
21 | 21 | ||
22 | handleClick () { | 22 | handleClick () { |