Improved the iOS WebKit click detection inside the editor margin
authorAlexander Ebert <ebert@woltlab.com>
Mon, 7 Dec 2020 17:16:08 +0000 (18:16 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 7 Dec 2020 17:16:08 +0000 (18:16 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js

index 24fe65fabe2f296dca74e57629c8128bde23aca1..ad68c7eebdfd5a06fb5c5d0c7cfd990835dc25fe 100644 (file)
@@ -482,14 +482,18 @@ $.Redactor.prototype.WoltLabCaret = function() {
                
                _handleEditorClick: function (event) {
                        var clientY = event.clientY;
+
+                       // Treat this as a collapsed selection instead, because the iOS Safari
+                       // breaks event delegation and refuses to trigger click-style events
+                       // for non-link/non-input elements. Thanks Apple.
+                       var isIosTouch = _iOS && _touchstartTarget === event.target && this.utils.isBlockTag(_touchstartTarget.nodeName);
+                       
+                       if (clientY === undefined && isIosTouch) {
+                               clientY = event.changedTouches[0].clientY;
+                       }
+                       
                        if (!this.selection.get().isCollapsed) {
-                               if (_isSafari && _iOS && _touchstartTarget === event.target && this.utils.isBlockTag(_touchstartTarget.nodeName)) {
-                                       // Treat this as a collapsed selection instead, because the iOS Safari
-                                       // breaks event delegation and refuses to trigger click-style events
-                                       // for non-link/non-input elements. Thanks Apple.
-                                       clientY = event.changedTouches[0].clientY;
-                               }
-                               else {
+                               if (!isIosTouch || clientY === undefined) {
                                        // ignore text selection
                                        return;
                                }