ts: Migrate header.js to typescript.

Added strict if block check to make sure `labelID` is defined at
runtime.
This commit is contained in:
xoldyckk 2023-03-31 21:21:37 +05:30 committed by Tim Abbott
parent 7c023042cf
commit c575d62d5a
1 changed files with 7 additions and 2 deletions

View File

@ -1,7 +1,9 @@
import $ from "jquery";
$(() => {
function on_tab_menu_selection_change(event) {
function on_tab_menu_selection_change(
event?: JQuery.ChangeEvent<HTMLElement> | JQuery.ClickEvent<HTMLElement>,
): void {
// Pass event to open menu and if it is undefined, we close the menu.
if (!event) {
$("#top-menu-submenu-backdrop").css("height", "0px");
@ -15,7 +17,7 @@ $(() => {
}
}
function on_top_menu_tab_unselect_click() {
function on_top_menu_tab_unselect_click(): void {
// Close the menu.
$("#top-menu-tab-close").prop("checked", true);
on_tab_menu_selection_change();
@ -64,6 +66,9 @@ $(() => {
e.preventDefault();
e.stopPropagation();
const labelID = $(e.currentTarget).attr("for");
if (labelID === undefined) {
throw new Error("Current target of this event must have for attribute defined.");
}
$(`#${CSS.escape(labelID)}`).trigger("click");
}
});