From e4e1c8a19e793e34ec97fd06b96edbb972ef955b Mon Sep 17 00:00:00 2001 From: Henrik Fehlauer Date: Sun, 7 Jun 2020 18:00:00 +0000 Subject: [PATCH] Add shortcut for clear route dialog Use 'Backspace' to show the dialog allowing to clear the route. The 'Del' key could then be used in the future to possibly allow to delete individual selected items like POIs or no-go areas. --- js/index.js | 88 +++++++++++++++++++++++++++++-------------------- locales/en.json | 1 + 2 files changed, 53 insertions(+), 36 deletions(-) diff --git a/js/index.js b/js/index.js index 4cc28eb..a0ce08c 100644 --- a/js/index.js +++ b/js/index.js @@ -92,45 +92,61 @@ deleteRouteButton = L.easyButton( 'fa-trash-o', function() { - bootbox.prompt({ - size: 'small', - title: i18next.t('map.clear-route'), - inputType: 'checkbox', - inputOptions: [ - { - text: i18next.t('map.delete-route'), - value: 'route' - }, - { - text: i18next.t('map.delete-nogo-areas'), - value: 'nogo' - }, - { - text: i18next.t('map.delete-pois'), - value: 'pois' - } - ], - value: ['route'], - callback: function(result) { - if (result !== null) { - if (result.indexOf('route') !== -1) { - routing.clear(); - } - if (result.indexOf('nogo') !== -1) { - nogos.clear(); - } - if (result.indexOf('pois') !== -1) { - pois.clear(); - } - onUpdate(); - urlHash.onMapMove(); - } - } - }); + clearRoute(); }, - i18next.t('map.clear-route') + i18next.t('map.clear-route-tooltip') ); + L.DomEvent.addListener( + document, + 'keydown', + function(e) { + if (BR.Util.keyboardShortcutsAllowed(e) && e.keyCode === 8 && !$('.modal.show').length) { + // char code for 'backspace' + clearRoute(); + } + }, + this + ); + + function clearRoute() { + bootbox.prompt({ + size: 'small', + title: i18next.t('map.clear-route'), + inputType: 'checkbox', + inputOptions: [ + { + text: i18next.t('map.delete-route'), + value: 'route' + }, + { + text: i18next.t('map.delete-nogo-areas'), + value: 'nogo' + }, + { + text: i18next.t('map.delete-pois'), + value: 'pois' + } + ], + value: ['route'], + callback: function(result) { + if (result !== null) { + if (result.indexOf('route') !== -1) { + routing.clear(); + } + if (result.indexOf('nogo') !== -1) { + nogos.clear(); + } + if (result.indexOf('pois') !== -1) { + pois.clear(); + } + onUpdate(); + urlHash.onMapMove(); + } + } + }); + } + function updateRoute(evt) { router.setOptions(evt.options); diff --git a/locales/en.json b/locales/en.json index c1aceca..cd27425 100644 --- a/locales/en.json +++ b/locales/en.json @@ -80,6 +80,7 @@ "attribution-osm-long": "OpenStreetMap contributors", "attribution-osm-short": "OpenStreetMap", "clear-route": "Clear route data", + "clear-route-tooltip": "Clear route data (Backspace key)", "copyright": "Copyright", "cycling": "Cycling", "delete-last-point": "Delete last point (Z key)",