1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Fix copy to clipboard in Safari 10

This commit is contained in:
Dmitry Lyzo 2022-02-26 00:15:41 +03:00
parent fff4ebb3ba
commit 3990175c86

View file

@ -1,3 +1,5 @@
import browser from './browser';
/**
* Copies text to the clipboard using the textarea.
* @param {string} text - Text to copy.
@ -8,7 +10,20 @@ function textAreaCopy(text) {
textArea.value = text;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
// iOS 13.4 supports Clipboard.writeText (https://stackoverflow.com/a/61868028)
if (browser.iOS && browser.iOSVersion < 13.4) {
// https://stackoverflow.com/a/46858939
const range = document.createRange();
range.selectNodeContents(textArea);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
textArea.setSelectionRange(0, 999999);
} else {
textArea.select();
}
let ret;