mirror of
https://github.com/valitydev/redash.git
synced 2024-11-08 18:03:54 +00:00
26 lines
560 B
JavaScript
26 lines
560 B
JavaScript
import { each } from 'underscore';
|
|
import Mousetrap from 'mousetrap';
|
|
import 'mousetrap/plugins/global-bind/mousetrap-global-bind';
|
|
|
|
|
|
function KeyboardShortcuts() {
|
|
this.bind = function bind(keymap) {
|
|
each(keymap, (fn, key) => {
|
|
Mousetrap.bindGlobal(key, (e) => {
|
|
e.preventDefault();
|
|
fn();
|
|
});
|
|
});
|
|
};
|
|
|
|
this.unbind = function unbind(keymap) {
|
|
each(keymap, (fn, key) => {
|
|
Mousetrap.unbind(key);
|
|
});
|
|
};
|
|
}
|
|
|
|
export default function (ngModule) {
|
|
ngModule.service('KeyboardShortcuts', KeyboardShortcuts);
|
|
}
|