2018-04-04 16:36:49 +02:00
|
|
|
/*
|
|
|
|
See hotkey.js for handlers that are more app-wide.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var 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) {
|
|
|
|
opts.elem.keydown(function (e) {
|
|
|
|
var key = e.which || e.keyCode;
|
|
|
|
|
2018-12-04 19:15:31 +01:00
|
|
|
if (e.altKey || e.ctrlKey || e.shiftKey) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-04 16:36:49 +02:00
|
|
|
var key_name = keys[key];
|
|
|
|
|
|
|
|
if (!key_name) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!opts.handlers[key_name]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var handled = opts.handlers[key_name]();
|
|
|
|
|
|
|
|
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;
|