nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

commit 0de2b1bd92af80f34cb5f5c518360e342fc64404
parent 3facc34622ac5098bace723f021609e57296a9c3
Author: Sergey Orlov <wladimirych@gmail.com>
Date:   Tue, 21 Jul 2020 21:49:42 +0200

Add workaround for bug in Chrome on Android - remove focus from input after prompt

There is a bug in Chrome on Android: after closing the prompt, it sets
focus to last active input element.

Diffstat:
Msrc/lib/clipboardCopy/index.js | 3++-
Msrc/lib/leaflet.control.track-list/track-list.js | 6+++---
Msrc/lib/notifications/index.js | 16+++++++++++++---
3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/lib/clipboardCopy/index.js b/src/lib/clipboardCopy/index.js @@ -1,5 +1,6 @@ import './style.css'; import logging from '~/lib/logging'; +import {query} from '~/lib/notifications'; function showNotification(message, mouseEvent) { var el = document.createElement('div'); @@ -41,7 +42,7 @@ function copyToClipboard(s, mouseEvent) { document.body.removeChild(ta); } if (!success) { - prompt("Copy to clipboard: Ctrl+C, Enter", s); + query("Copy to clipboard: Ctrl+C, Enter", s); } } diff --git a/src/lib/leaflet.control.track-list/track-list.js b/src/lib/leaflet.control.track-list/track-list.js @@ -19,7 +19,7 @@ import {blobFromString} from '~/lib/binary-strings'; import '~/lib/leaflet.polyline-edit'; import '~/lib/leaflet.polyline-measure'; import logging from '~/lib/logging'; -import {notify} from '~/lib/notifications'; +import {notify, query} from '~/lib/notifications'; import {fetch} from '~/lib/xhr-promise'; import config from '~/config'; import md5 from 'blueimp-md5'; @@ -623,7 +623,7 @@ L.Control.TrackList = L.Control.extend({ }, renameTrack: function(track) { - var newName = prompt('Enter new name', track.name()); + var newName = query('Enter new name', track.name()); if (newName && newName.length) { track.name(newName); } @@ -1229,7 +1229,7 @@ L.Control.TrackList = L.Control.extend({ renamePoint: function(marker) { this.stopPlacingPoint(); - var newLabel = prompt('New point name', marker.label); + var newLabel = query('New point name', marker.label); if (newLabel !== null) { this.setMarkerLabel(marker, newLabel); this._markerLayer.updateMarker(marker); diff --git a/src/lib/notifications/index.js b/src/lib/notifications/index.js @@ -5,8 +5,18 @@ function notify(message, onOk) { alertify.alert(message, onOk); } -function prompt(message, value) { - return window.prompt(message, value); +function query(message, value) { + function removeFocusFromInput() { + const activeElement = document.activeElement; + if (activeElement?.tagName === 'INPUT') { + activeElement.blur(); + } + } + + const result = window.prompt(message, value); + // There is a bug in Chrome on Android: after closing the prompt, it sets focus to last active input element + setTimeout(removeFocusFromInput, 0); + return result; } -export {notify, prompt}; +export {notify, query};