Files
zulip/static/js/keydown_util.js
Armaan Ahluwalia 6d255efe4c app: Prepare JS files for consumption by webpack.
This commit prepares the frontend code to be consumed by webpack.

It is a hack: In theory, modules should be declaring and importing the
modules they depend on and the globals they expose directly.

However, that requires significant per-module work, which we don't
really want to block moving our toolchain to webpack on.

So we expose the modules by setting window.varName = varName; as
needed in the js files.
2018-07-05 10:53:36 +02:00

47 lines
809 B
JavaScript

var keydown_util = (function () {
var exports = {};
/*
See hotkey.js for handlers that are more app-wide.
*/
var keys = {
13: 'enter_key',
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;
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();
e.stopPropagation();
}
});
};
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = keydown_util;
}
window.keydown_util = keydown_util;