Copying to clipboard caused a scroll to the page top on iOS
authorAlexander Ebert <ebert@woltlab.com>
Thu, 4 Jul 2019 14:57:42 +0000 (16:57 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 4 Jul 2019 14:57:42 +0000 (16:57 +0200)
wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js
wcfsetup/install/files/js/WoltLabSuite/Core/Clipboard.js

index abe7e5bb3f7102f409c7f18cd902e0a1fdd50fc1..a8bcae8d97a7ffec09480536f75937191b90686b 100644 (file)
@@ -126,7 +126,7 @@ define([
                                this.container.classList.add('highlighted');
                        }.bind(this))
                }
-       }
+       };
        
        return Code;
 });
index 7d5f20b5c1bc3a72b3df8a917435c48749ab5118..fc35381cc872e3d83aaa497f3a1f3dc25dae41f6 100644 (file)
@@ -6,7 +6,7 @@
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @module     WoltLabSuite/Core/Clipboard
  */
-define([], function() {
+define(['Environment', 'Ui/Screen'], function(Environment, UiScreen) {
        "use strict";
        
        return {
@@ -18,7 +18,20 @@ define([], function() {
                                var textarea = elCreate('textarea');
                                textarea.contentEditable = true;
                                textarea.readOnly = false;
-                               textarea.style.cssText = 'position: absolute; left: -9999px; top: -9999px; width: 0; height: 0;';
+                               
+                               // iOS has some implicit restrictions that, if crossed, cause the browser to scroll to the top.
+                               var scrollDisabled = false;
+                               if (Environment.platform() === 'ios') {
+                                       scrollDisabled = true;
+                                       UiScreen.scrollDisable();
+                                       
+                                       var topPx = (~~(window.innerHeight / 4) + window.pageYOffset);
+                                       textarea.style.cssText = 'font-size: 16px; position: absolute; left: 1px; top: ' + topPx + 'px; width: 50px; height: 50px; overflow: hidden;border: 5px solid red;';
+                               }
+                               else {
+                                       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
@@ -36,6 +49,10 @@ define([], function() {
                                }
                                finally {
                                        elRemove(textarea);
+                                       
+                                       if (scrollDisabled) {
+                                               UiScreen.scrollEnable();
+                                       }
                                }
                        }