Merge pull request #303 from stesie/mute-opacity

Allow to mute route display
This commit is contained in:
Norbert Renner 2020-06-07 14:18:54 +02:00 committed by GitHub
commit b181649dff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View file

@ -44,6 +44,33 @@ BR.OpacitySlider = L.Class.extend({
this.getElement().title = this.options.title;
this.options.callback(value / 100);
if (this.options.muteKeyCode) {
L.DomEvent.addListener(document, 'keydown', this._keydownListener, this);
L.DomEvent.addListener(document, 'keyup', this._keyupListener, this);
}
},
_keydownListener: function(e) {
// Suppress shortcut handling when a text input field is focussed
if (document.activeElement.type == 'text' || document.activeElement.type == 'textarea') {
return;
}
if (e.keyCode === this.options.muteKeyCode && !e.repeat) {
this.options.callback(0);
}
},
_keyupListener: function(e) {
// Suppress shortcut handling when a text input field is focussed
if (document.activeElement.type == 'text' || document.activeElement.type == 'textarea') {
return;
}
if (e.keyCode === this.options.muteKeyCode && !e.repeat) {
this.options.callback(this.input.val() / 100);
}
},
getElement: function() {

View file

@ -284,6 +284,7 @@
new BR.OpacitySliderControl({
id: 'route',
title: i18next.t('map.opacity-slider'),
muteKeyCode: 77, // m
callback: L.bind(routing.setOpacity, routing)
})
);