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)",