Files
zulip/static/js/keydown_util.js
Anders Kaseorg 6ec808b8df js: Add "use strict" directive to CommonJS files.
ES and TypeScript modules are strict by default and don’t need this
directive.  ESLint will remind us to add it to new CommonJS files and
remove it from ES and TypeScript modules.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-31 22:09:46 -07:00

43 lines
758 B
JavaScript

"use strict";
/*
See hotkey.js for handlers that are more app-wide.
*/
const keys = {
13: "enter_key",
37: "left_arrow",
38: "up_arrow",
39: "right_arrow",
40: "down_arrow",
};
exports.handle = function (opts) {
opts.elem.on("keydown", (e) => {
const key = e.which || e.keyCode;
if (e.altKey || e.ctrlKey || e.shiftKey) {
return;
}
const key_name = keys[key];
if (!key_name) {
return;
}
if (!opts.handlers[key_name]) {
return;
}
const handled = opts.handlers[key_name]();
if (handled) {
e.preventDefault();
e.stopPropagation();
}
});
};
window.keydown_util = exports;