Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

ui_init: Initialize hotkey handlers after other libraries are initialized.

Aman Agrawal2d31b5292776
diff --git a/static/js/hotkey.js b/static/js/hotkey.js
index be0a6398596..29e644732a0 100644
--- a/static/js/hotkey.js
+++ b/static/js/hotkey.js
@@ -998,12 +998,6 @@ export function process_keydown(e) {
return process_hotkey(e, hotkey);
}
-$(document).on("keydown", (e) => {
- if (process_keydown(e)) {
- e.preventDefault();
- }
-});
-
export function process_keypress(e) {
const hotkey = get_keypress_hotkey(e);
if (!hotkey) {
@@ -1012,8 +1006,16 @@ export function process_keypress(e) {
return process_hotkey(e, hotkey);
}
-$(document).on("keypress", (e) => {
- if (process_keypress(e)) {
- e.preventDefault();
- }
-});
+export function initialize() {
+ $(document).on("keydown", (e) => {
+ if (process_keydown(e)) {
+ e.preventDefault();
+ }
+ });
+
+ $(document).on("keypress", (e) => {
+ if (process_keypress(e)) {
+ e.preventDefault();
+ }
+ });
+}
diff --git a/static/js/ui_init.js b/static/js/ui_init.js
index a0669a15678..f87a098f18c 100644
--- a/static/js/ui_init.js
+++ b/static/js/ui_init.js
@@ -35,6 +35,7 @@ import * as emojisets from "./emojisets";
import * as gear_menu from "./gear_menu";
import * as giphy from "./giphy";
import * as hashchange from "./hashchange";
+import * as hotkey from "./hotkey";
import * as hotspots from "./hotspots";
import * as i18n from "./i18n";
import * as invite from "./invite";
@@ -687,6 +688,7 @@ export function initialize_everything() {
user_status_ui.initialize();
fenced_code.initialize(generated_pygments_data);
message_edit_history.initialize();
+ hotkey.initialize();
$("#app-loading").addClass("loaded");
}