diff --git a/js/control/OpacitySlider.js b/js/control/OpacitySlider.js index 0aaf5de..14f0439 100644 --- a/js/control/OpacitySlider.js +++ b/js/control/OpacitySlider.js @@ -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() { diff --git a/js/index.js b/js/index.js index 1256073..ed4f200 100644 --- a/js/index.js +++ b/js/index.js @@ -284,6 +284,7 @@ new BR.OpacitySliderControl({ id: 'route', title: i18next.t('map.opacity-slider'), + muteKeyCode: 77, // m callback: L.bind(routing.setOpacity, routing) }) );