Skip to content

Commit

Permalink
Merge pull request #303 from stesie/mute-opacity
Browse files Browse the repository at this point in the history
Allow to mute route display
  • Loading branch information
nrenner authored Jun 7, 2020
2 parents 32d4a26 + 64202a4 commit b181649
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions js/control/OpacitySlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
new BR.OpacitySliderControl({
id: 'route',
title: i18next.t('map.opacity-slider'),
muteKeyCode: 77, // m
callback: L.bind(routing.setOpacity, routing)
})
);
Expand Down

0 comments on commit b181649

Please sign in to comment.