don't autofocus colorpicker input fields on small touch devices

This commit is contained in:
tophf 2017-11-25 16:46:57 +03:00
parent 71b2ab14a0
commit 326dc5fb86

View File

@ -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;