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.

toggle: Add register_event_handlers to toggle prototype.

Shubham Padiadd4fc4285a20
diff --git a/web/src/components.ts b/web/src/components.ts
index 6afb8a81f1d..397fa0f9d4d 100644
--- a/web/src/components.ts
+++ b/web/src/components.ts
@@ -23,6 +23,7 @@ export type Toggle = {
value: () => string | undefined;
get: () => JQuery;
goto: (name: string) => void;
+ register_event_handlers: () => void;
};
export function toggle(opts: {
@@ -115,10 +116,14 @@ export function toggle(opts: {
return false;
}
- meta.$ind_tab.on("click", function () {
- const idx = Number($(this).attr("data-tab-id"));
- select_tab(idx);
- });
+ function register_event_handlers(): void {
+ meta.$ind_tab.off("click");
+ meta.$ind_tab.on("click", function () {
+ const idx = Number($(this).attr("data-tab-id"));
+ select_tab(idx);
+ });
+ }
+ register_event_handlers();
keydown_util.handle({
$elem: meta.$ind_tab,
@@ -186,6 +191,8 @@ export function toggle(opts: {
select_tab(idx);
}
},
+
+ register_event_handlers,
};
return prototype;
diff --git a/web/tests/components.test.js b/web/tests/components.test.js
index 47854ed79ab..f2af52b7f1f 100644
--- a/web/tests/components.test.js
+++ b/web/tests/components.test.js
@@ -73,6 +73,12 @@ const ind_tab = (function () {
}
};
+ $self.off = (name) => {
+ if (name === "click") {
+ env.click_f = undefined;
+ }
+ };
+
$self.removeClass = (c) => {
for (const $tab of env.tabs) {
$tab.removeClass(c);