From 58b949c4b364bbf54da58e09e5d5c89c5fb7df73 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 4 Jul 2019 16:57:42 +0200 Subject: [PATCH] Copying to clipboard caused a scroll to the page top on iOS --- .../files/js/WoltLabSuite/Core/Bbcode/Code.js | 2 +- .../files/js/WoltLabSuite/Core/Clipboard.js | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js index abe7e5bb3f..a8bcae8d97 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js @@ -126,7 +126,7 @@ define([ this.container.classList.add('highlighted'); }.bind(this)) } - } + }; return Code; }); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Clipboard.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Clipboard.js index 7d5f20b5c1..fc35381cc8 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Clipboard.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Clipboard.js @@ -6,7 +6,7 @@ * @license GNU Lesser General Public License * @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(); + } } } -- 2.20.1