2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
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 = {
|
2020-07-15 01:29:15 +02:00
|
|
|
13: "enter_key",
|
|
|
|
37: "left_arrow",
|
|
|
|
38: "up_arrow",
|
|
|
|
39: "right_arrow",
|
|
|
|
40: "down_arrow",
|
2018-04-04 16:36:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.handle = function (opts) {
|
2020-07-20 21:26:58 +02:00
|
|
|
opts.elem.on("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;
|