Make WoltLabSuite/Core/Clipboard compatible with iOS
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 17 Dec 2018 17:49:30 +0000 (18:49 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 17 Dec 2018 17:57:11 +0000 (18:57 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Clipboard.js

index 36ff575b6c4bee63b886a64e8060162ae97cbb4a..2969031cbb964cb2a8a1e83555bd9df233e329fd 100644 (file)
@@ -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"));
                                        }