From: Tim Düsterhus Date: Mon, 17 Dec 2018 17:49:30 +0000 (+0100) Subject: Make WoltLabSuite/Core/Clipboard compatible with iOS X-Git-Tag: 5.2.0_Alpha_1~420^2~5^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=aa583b9353c0363a3d90ab6306f361ad7a18a0a4;p=GitHub%2FWoltLab%2FWCF.git Make WoltLabSuite/Core/Clipboard compatible with iOS --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Clipboard.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Clipboard.js index 36ff575b6c..2969031cbb 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Clipboard.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Clipboard.js @@ -16,11 +16,19 @@ define([], function() { } else if (window.getSelection) { var textarea = elCreate('textarea'); - textarea.style.cssText = 'position: absolute; left: -9999px; width: 0;'; + textarea.contentEditable = true; + textarea.readOnly = false; + textarea.style.cssText = 'position: absolute; left: -9999px; top: -9999px; width: 0; height: 0;'; document.body.appendChild(textarea); try { + // see: https://stackoverflow.com/a/34046084/782822 textarea.value = text; - textarea.select(); + var range = document.createRange(); + range.selectNodeContents(textarea); + var selection = window.getSelection(); + selection.removeAllRanges(); + selection.addRange(range); + textarea.setSelectionRange(0, 999999); if (!document.execCommand('copy')) { return Promise.reject(new Error("execCommand('copy') failed")); }