ts: Convert portico/tabbed-instructions.js to TypeScript.

This commit is contained in:
sbansal1999 2023-03-12 11:35:40 +05:30 committed by Tim Abbott
parent 213d0f4990
commit 5047f1a81d
1 changed files with 10 additions and 3 deletions

View File

@ -1,8 +1,11 @@
import $ from "jquery";
import * as blueslip from "../blueslip";
import * as common from "../common";
export function detect_user_os() {
export type UserOS = "android" | "ios" | "mac" | "windows" | "linux";
export function detect_user_os(): UserOS {
if (/android/i.test(navigator.userAgent)) {
return "android";
}
@ -21,7 +24,7 @@ export function detect_user_os() {
return "mac"; // if unable to determine OS return Mac by default
}
export function activate_correct_tab($codeSection) {
export function activate_correct_tab($codeSection: JQuery<HTMLElement>): void {
const user_os = detect_user_os();
const desktop_os = new Set(["mac", "linux", "windows"]);
const $li = $codeSection.find("ul.nav li");
@ -56,7 +59,11 @@ export function activate_correct_tab($codeSection) {
if (!$active_list_items.length) {
$li.first().addClass("active");
const language = $li.first()[0].dataset.language;
if (language) {
$blocks.filter("[data-language=" + language + "]").addClass("active");
} else {
blueslip.error("Tabbed instructions widget has no tabs to activate!");
}
}
}