redash/frontend/app/services/keyboard-shortcuts.js
2016-11-26 11:33:41 +02:00

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);
}