From 8e78c858c15d80c30498f3ffbac7b15faae81ad3 Mon Sep 17 00:00:00 2001 From: Henrik Fehlauer Date: Sat, 30 May 2020 18:00:00 +0000 Subject: [PATCH] Add shortcut to toggle color coding button Press 'C' repeatedly to switch between the various color coding options. When the last one is reached, we show the regular route again. --- js/plugin/RoutingPathQuality.js | 11 +++++++++-- locales/en.json | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/js/plugin/RoutingPathQuality.js b/js/plugin/RoutingPathQuality.js index 1ed5e11..76dd6bc 100644 --- a/js/plugin/RoutingPathQuality.js +++ b/js/plugin/RoutingPathQuality.js @@ -1,6 +1,7 @@ BR.RoutingPathQuality = L.Control.extend({ options: { shortcut: { + toggle: 67, // char code for 'c' muteKeyCode: 77 // char code for 'm' } }, @@ -140,7 +141,7 @@ BR.RoutingPathQuality = L.Control.extend({ }); } - if (this.options.shortcut.muteKeyCode) { + if (this.options.shortcut.muteKeyCode || this.options.shortcut.toggle) { L.DomEvent.addListener(document, 'keydown', this._keydownListener, this); L.DomEvent.addListener(document, 'keyup', this._keyupListener, this); } @@ -192,10 +193,16 @@ BR.RoutingPathQuality = L.Control.extend({ }, _keydownListener: function(e) { - if (BR.Util.keyboardShortcutsAllowed(e) && this._active && e.keyCode === this.options.shortcut.muteKeyCode) { + if (!BR.Util.keyboardShortcutsAllowed(e)) { + return; + } + if (this._active && e.keyCode === this.options.shortcut.muteKeyCode) { this._muted = true; this._deactivate(this.routingPathButton); } + if (!this._muted && e.keyCode === this.options.shortcut.toggle) { + this.routingPathButton.button.click(); + } }, _keyupListener: function(e) { diff --git a/locales/en.json b/locales/en.json index 9c900f0..e5b1a67 100644 --- a/locales/en.json +++ b/locales/en.json @@ -122,9 +122,9 @@ "preview": "Preview", "privacy": "Privacy", "reverse-route": "Reverse route", - "route-quality-altitude": "Altitude coding", - "route-quality-cost": "Cost coding", - "route-quality-incline": "Incline coding", + "route-quality-altitude": "Altitude coding (C key to toggle)", + "route-quality-cost": "Cost coding (C key to toggle)", + "route-quality-incline": "Incline coding (C key to toggle)", "strava-biking": "Show Strava biking segments", "strava-running": "Show Strava running segments", "zoomInTitle": "Zoom in (+ key)",