From 9dd53e9305ee9e320efe859d256d6af92498f8b7 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 26 Sep 2016 13:03:50 +0200 Subject: [PATCH] Improved overlay behavior for iOS --- .../files/js/WoltLabSuite/Core/Ui/Dialog.js | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js index bed77c574d..42b4012d7a 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js @@ -10,12 +10,12 @@ define( [ 'enquire', 'Ajax', 'Core', 'Dictionary', 'Environment', 'Language', 'ObjectMap', 'Dom/ChangeListener', - 'Dom/Traverse', 'Dom/Util', 'Ui/Confirmation', 'Ui/SimpleDropdown' + 'Dom/Traverse', 'Dom/Util', 'Ui/Confirmation', 'Ui/Screen', 'Ui/SimpleDropdown' ], function( enquire, Ajax, Core, Dictionary, Environment, Language, ObjectMap, DomChangeListener, - DomTraverse, DomUtil, UiConfirmation, UiSimpleDropdown + DomTraverse, DomUtil, UiConfirmation, UiScreen, UiSimpleDropdown ) { "use strict"; @@ -227,7 +227,23 @@ define( this._createDialog(id, html, options); } - return _dialogs.get(id); + var data = _dialogs.get(id); + + // iOS breaks `position: fixed` when input elements or `contenteditable` + // are focused, this will freeze the screen and force Safari to scroll + // to the input field + if (Environment.platform() === 'ios') { + UiScreen.scrollDisable(); + + window.setTimeout((function () { + var input = elBySel('input, textarea', data.content); + if (input !== null) { + input.focus(); + } + }).bind(this), 200); + } + + return data; }, /** @@ -557,6 +573,10 @@ define( data = _dialogs.get(_activeDialog); elData(_container, 'close-on-click', (data.backdropCloseOnClick ? 'true' : 'false')); } + + if (Environment.platform() === 'ios') { + UiScreen.scrollEnable(); + } }, /** -- 2.20.1