mirror of
https://github.com/valitydev/redash.git
synced 2024-11-09 02:06:49 +00:00
24 lines
491 B
JavaScript
24 lines
491 B
JavaScript
import { each } from 'underscore';
|
|
import Mousetrap from 'mousetrap';
|
|
|
|
function KeyboardShortcuts() {
|
|
this.bind = function bind(keymap) {
|
|
each(keymap, (fn, key) => {
|
|
Mousetrap.bind(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);
|
|
}
|