2018-04-04 16:36:49 +02:00
|
|
|
/*
|
|
|
|
See hotkey.js for handlers that are more app-wide.
|
|
|
|
*/
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const keys = {
|
2018-04-21 14:59:03 +02:00
|
|
|
13: 'enter_key',
|
2018-04-04 16:36:49 +02:00
|
|
|
37: 'left_arrow',
|
|
|
|
38: 'up_arrow',
|
|
|
|
39: 'right_arrow',
|
|
|
|
40: 'down_arrow',
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.handle = function (opts) {
|
2020-07-02 01:45:54 +02:00
|
|
|
opts.elem.keydown((e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const key = e.which || e.keyCode;
|
2018-04-04 16:36:49 +02:00
|
|
|
|
2018-12-04 19:15:31 +01:00
|
|
|
if (e.altKey || e.ctrlKey || e.shiftKey) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const key_name = keys[key];
|
2018-04-04 16:36:49 +02:00
|
|
|
|
|
|
|
if (!key_name) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!opts.handlers[key_name]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const handled = opts.handlers[key_name]();
|
2018-04-04 16:36:49 +02:00
|
|
|
|
|
|
|
if (handled) {
|
|
|
|
e.preventDefault();
|
2018-06-09 08:06:49 +02:00
|
|
|
e.stopPropagation();
|
2018-04-04 16:36:49 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.keydown_util = exports;
|