Add shortcut to toggle elevation chart

Press 'E' to show/hide the elevation chart.
This commit is contained in:
Henrik Fehlauer 2020-06-14 18:00:00 +00:00
parent 844a9038ee
commit b8b1e436e6
3 changed files with 15 additions and 1 deletions

View file

@ -910,6 +910,8 @@
id="elevation-btn"
aria-expanded="false"
aria-label="Toggle elevation chart"
data-i18n="[title]footer.elevation-chart"
title="Toggle elevation chart"
>
<span class="fa fa-area-chart"></span>
</button>

View file

@ -7,7 +7,10 @@ BR.Elevation = L.Control.Elevation.extend({
bottom: 30,
left: 60
},
theme: 'steelblue-theme'
theme: 'steelblue-theme',
shortcut: {
toggle: 69 // char code for 'e'
}
},
onAdd: function(map) {
@ -30,6 +33,8 @@ BR.Elevation = L.Control.Elevation.extend({
L.DomEvent.on(this._container, 'mouseup', this._dragEndHandler, this);
}
L.DomEvent.addListener(document, 'keydown', this._keydownListener, this);
return container;
},
@ -64,5 +69,11 @@ BR.Elevation = L.Control.Elevation.extend({
layer.on('mouseout', this._hidePositionMarker.bind(this));
}
},
_keydownListener: function(e) {
if (BR.Util.keyboardShortcutsAllowed(e) && e.keyCode === this.options.shortcut.toggle) {
$('#elevation-btn').click();
}
}
});

View file

@ -42,6 +42,7 @@
"ascend": "Ascend",
"cost": "Cost",
"distance": "Distance",
"elevation-chart": "Toggle elevation chart (E key)",
"energy-per-100km": "Energy per 100 km",
"hours": "hours",
"hours-abbrev": "h",