This commit is contained in:
23
public/ts/ui/modal.ts
Normal file
23
public/ts/ui/modal.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
let activeModal: HTMLElement | null = null;
|
||||
let backdrop: HTMLElement | null = null;
|
||||
|
||||
function ensureBackdrop() {
|
||||
if (backdrop) return backdrop;
|
||||
backdrop = document.createElement('div');
|
||||
backdrop.className = 'modal-backdrop';
|
||||
backdrop.addEventListener('click', hideModal);
|
||||
document.body.appendChild(backdrop);
|
||||
return backdrop;
|
||||
}
|
||||
|
||||
export function showModal(content: HTMLElement) {
|
||||
const bd = ensureBackdrop();
|
||||
if (!content.parentElement) bd.appendChild(content);
|
||||
activeModal = content;
|
||||
bd.classList.add('show');
|
||||
}
|
||||
|
||||
export function hideModal() {
|
||||
if (backdrop) backdrop.classList.remove('show');
|
||||
activeModal = null;
|
||||
}
|
||||
Reference in New Issue
Block a user