diff options
author | Wicklow <123956049+wickloww@users.noreply.github.com> | 2023-03-14 08:32:16 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 09:32:16 +0100 |
commit | cadc1a1b0b1f8c22afbf31cb07759706131f29c4 (patch) | |
tree | 58d226340b6cdeb13815461651d710c1bb5871bf /client/src/root-helpers | |
parent | e72ace5a506904a67290e347e962ddf930d2b9f9 (diff) | |
download | PeerTube-cadc1a1b0b1f8c22afbf31cb07759706131f29c4.tar.gz PeerTube-cadc1a1b0b1f8c22afbf31cb07759706131f29c4.tar.zst PeerTube-cadc1a1b0b1f8c22afbf31cb07759706131f29c4.zip |
Add an option to provide responsive embed (#5690)
* Add option to provide responsive embed
* Fix typo
* More understandable parameter
Diffstat (limited to 'client/src/root-helpers')
-rw-r--r-- | client/src/root-helpers/video.ts | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/client/src/root-helpers/video.ts b/client/src/root-helpers/video.ts index 107ba1eba..01feddbdc 100644 --- a/client/src/root-helpers/video.ts +++ b/client/src/root-helpers/video.ts | |||
@@ -3,19 +3,34 @@ import { HTMLServerConfig, Video, VideoPrivacy } from '@shared/models' | |||
3 | function buildVideoOrPlaylistEmbed (options: { | 3 | function buildVideoOrPlaylistEmbed (options: { |
4 | embedUrl: string | 4 | embedUrl: string |
5 | embedTitle: string | 5 | embedTitle: string |
6 | responsive?: boolean | ||
6 | }) { | 7 | }) { |
7 | const { embedUrl, embedTitle } = options | 8 | const { embedUrl, embedTitle, responsive = false } = options |
8 | 9 | ||
9 | const iframe = document.createElement('iframe') | 10 | const iframe = document.createElement('iframe') |
10 | 11 | ||
11 | iframe.title = embedTitle | 12 | iframe.title = embedTitle |
12 | iframe.width = '560' | 13 | iframe.width = responsive ? '100%' : '560' |
13 | iframe.height = '315' | 14 | iframe.height = responsive ? '100%' : '315' |
14 | iframe.src = embedUrl | 15 | iframe.src = embedUrl |
15 | iframe.frameBorder = '0' | 16 | iframe.frameBorder = '0' |
16 | iframe.allowFullscreen = true | 17 | iframe.allowFullscreen = true |
17 | iframe.sandbox.add('allow-same-origin', 'allow-scripts', 'allow-popups') | 18 | iframe.sandbox.add('allow-same-origin', 'allow-scripts', 'allow-popups') |
18 | 19 | ||
20 | if (responsive) { | ||
21 | const wrapper = document.createElement('div') | ||
22 | |||
23 | wrapper.style.position = 'relative' | ||
24 | wrapper.style['padding-top'] = '56.25%' | ||
25 | |||
26 | iframe.style.position = 'absolute' | ||
27 | iframe.style.inset = '0' | ||
28 | |||
29 | wrapper.appendChild(iframe) | ||
30 | |||
31 | return wrapper.outerHTML | ||
32 | } | ||
33 | |||
19 | return iframe.outerHTML | 34 | return iframe.outerHTML |
20 | } | 35 | } |
21 | 36 | ||