From 326dc5fb860e7c714d22070d9f0a178f7a464fcb Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 25 Nov 2017 16:46:57 +0300 Subject: [PATCH] don't autofocus colorpicker input fields on small touch devices --- vendor-overwrites/colorpicker/colorpicker.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/vendor-overwrites/colorpicker/colorpicker.js b/vendor-overwrites/colorpicker/colorpicker.js index 5616ff84..b1a7b264 100644 --- a/vendor-overwrites/colorpicker/colorpicker.js +++ b/vendor-overwrites/colorpicker/colorpicker.js @@ -34,6 +34,8 @@ CodeMirror.defineExtension('colorpicker', function () { const $hsl = {}; const $hexLettercase = {}; + const allowInputFocus = !('ontouchstart' in document) || window.innerHeight > 800; + const dragging = { saturationPointerPos: {x: 0, y: 0}, hueKnobPos: 0, @@ -348,9 +350,9 @@ CodeMirror.defineExtension('colorpicker', function () { const inputs = $inputs[currentFormat]; const lastInput = inputs[inputs.length - 1]; if (which === 9 && shift && el === inputs[0]) { - lastInput.focus(); + maybeFocus(lastInput); } else if (which === 9 && !shift && el === lastInput) { - inputs[0].focus(); + maybeFocus(inputs[0]); } else if (which !== 9 && !shift) { setFromFormatElement({shift: which === 33 || shift}); } else { @@ -456,7 +458,7 @@ CodeMirror.defineExtension('colorpicker', function () { } } $inputGroups[format].dataset.active = ''; - $inputs[format][0].focus(); + maybeFocus($inputs[format][0]); currentFormat = format; } @@ -882,6 +884,12 @@ CodeMirror.defineExtension('colorpicker', function () { } } + function maybeFocus(el) { + if (allowInputFocus) { + el.focus(); + } + } + function focusNoScroll(el) { if (el) { const {scrollY: y, scrollX: x} = window;