From d96bc497427fdf2f18166bfcebadea751bed2936 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 7 Oct 2024 09:34:32 +0200 Subject: [PATCH] Fix fullscreen copy It seems we can't copy element outside the fullscreen element --- client/src/assets/player/peertube-player.ts | 12 ++++++------ client/src/root-helpers/utils.ts | 8 +++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/client/src/assets/player/peertube-player.ts b/client/src/assets/player/peertube-player.ts index d4d4d4a7b..12c8b5e84 100644 --- a/client/src/assets/player/peertube-player.ts +++ b/client/src/assets/player/peertube-player.ts @@ -502,7 +502,7 @@ export class PeerTubePlayer { { label: player.localize('Copy the video URL'), listener: function () { - copyToClipboard(buildVideoLink({ shortUUID })) + copyToClipboard(buildVideoLink({ shortUUID }), player.el() as HTMLElement) } }, { @@ -510,17 +510,17 @@ export class PeerTubePlayer { listener: function () { const url = buildVideoLink({ shortUUID }) - copyToClipboard(decorateVideoLink({ url, startTime: player.currentTime() })) + copyToClipboard(decorateVideoLink({ url, startTime: player.currentTime() }), player.el() as HTMLElement) } }, { icon: 'code', label: player.localize('Copy embed code'), listener: () => { - copyToClipboard(buildVideoOrPlaylistEmbed({ - embedUrl: self.currentLoadOptions.embedUrl, - embedTitle: self.currentLoadOptions.embedTitle - })) + copyToClipboard( + buildVideoOrPlaylistEmbed({ embedUrl: self.currentLoadOptions.embedUrl, embedTitle: self.currentLoadOptions.embedTitle }), + player.el() as HTMLElement + ) } } ] diff --git a/client/src/root-helpers/utils.ts b/client/src/root-helpers/utils.ts index af94ed6ca..7addfadc4 100644 --- a/client/src/root-helpers/utils.ts +++ b/client/src/root-helpers/utils.ts @@ -1,13 +1,15 @@ -function copyToClipboard (text: string) { +function copyToClipboard (text: string, container?: HTMLElement) { + if (!container) container = document.body + const el = document.createElement('textarea') el.value = text el.setAttribute('readonly', '') el.style.position = 'absolute' el.style.left = '-9999px' - document.body.appendChild(el) + container.appendChild(el) el.select() document.execCommand('copy') - document.body.removeChild(el) + container.removeChild(el) } function wait (ms: number) {