( filePath: string, type: string, updateUrl = true, trigger?: HTMLElement )
| 899 | * @param trigger - The element that triggered the modal (for focus return) |
| 900 | */ |
| 901 | export async function openFileModal( |
| 902 | filePath: string, |
| 903 | type: string, |
| 904 | updateUrl = true, |
| 905 | trigger?: HTMLElement |
| 906 | ): Promise<void> { |
| 907 | const modal = document.getElementById("file-modal"); |
| 908 | const title = document.getElementById("modal-title"); |
| 909 | const installDropdown = document.getElementById("install-dropdown"); |
| 910 | const installBtnMain = document.getElementById( |
| 911 | "install-btn-main" |
| 912 | ) as HTMLAnchorElement | null; |
| 913 | const installVscode = document.getElementById( |
| 914 | "install-vscode" |
| 915 | ) as HTMLAnchorElement | null; |
| 916 | const installInsiders = document.getElementById( |
| 917 | "install-insiders" |
| 918 | ) as HTMLAnchorElement | null; |
| 919 | const copyBtn = document.getElementById("copy-btn"); |
| 920 | const installCommandBtn = document.getElementById("install-command-btn"); |
| 921 | const downloadBtn = document.getElementById("download-btn"); |
| 922 | const closeBtn = document.getElementById("close-modal"); |
| 923 | if (!modal || !title) return; |
| 924 | |
| 925 | modal.classList.remove("details-mode"); |
| 926 | |
| 927 | currentFilePath = filePath; |
| 928 | currentFileType = type; |
| 929 | currentViewMode = "raw"; |
| 930 | |
| 931 | // Track trigger element for focus return |
| 932 | triggerElement = |
| 933 | trigger || triggerElement || (document.activeElement as HTMLElement); |
| 934 | |
| 935 | // Update URL for deep linking |
| 936 | if (updateUrl) { |
| 937 | updateHash(filePath); |
| 938 | } |
| 939 | |
| 940 | if (!originalDocumentTitle) { |
| 941 | originalDocumentTitle = document.title; |
| 942 | } |
| 943 | |
| 944 | // Show modal with loading state |
| 945 | const fallbackName = getFileName(filePath); |
| 946 | updateModalTitle(fallbackName, filePath); |
| 947 | modal.classList.remove("hidden"); |
| 948 | modal.classList.add("visible"); |
| 949 | |
| 950 | // Set focus to close button for accessibility |
| 951 | setTimeout(() => { |
| 952 | closeBtn?.focus(); |
| 953 | }, 0); |
| 954 | |
| 955 | // Handle plugins differently - show as item list |
| 956 | if (type === "plugin") { |
| 957 | const modalContent = getModalContent(); |
| 958 | if (!modalContent) return; |
no test coverage detected