toggle: Add register_event_handlers to toggle prototype.

This is a preparatory commit to combine user settings panels into
one. We need to re-register event handlers since they get destroyed
when the settings modal is closed. After re-opening the modal,
clicking the tabs would not do anything unless we re-register our
event handlers.
This commit is contained in:
Shubham Padia
2024-06-05 08:25:31 +00:00
committed by Tim Abbott
parent 78630b6395
commit dd4fc4285a
2 changed files with 17 additions and 4 deletions

View File

@@ -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;