From aa583b9353c0363a3d90ab6306f361ad7a18a0a4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 17 Dec 2018 18:49:30 +0100 Subject: [PATCH] Make WoltLabSuite/Core/Clipboard compatible with iOS --- .../install/files/js/WoltLabSuite/Core/Clipboard.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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")); } -- 2.20.1