import '../scss/accessible-docs-popup.scss'; import Popup from './parts/popup-window'; import { setLinkHref } from'./parts/helpers'; import handleSubmitAccessibleDocs from './parts/accessible-docs-handler'; const initAccessibleDocsPopupLogic = () => { // @ts-ignore if ( accessible_docs_object.is_popup_enabled !== '1') { return; } // Initialize popups const popupInstance = new Popup(); popupInstance.init(); document.body.addEventListener('click', (event: MouseEvent) => { const target = event.target as HTMLElement; // Find the closest element (either the clicked element itself or its ancestor) const link = target.closest('a:not(.js-accessible-docs-link)') as HTMLAnchorElement | null; if (link && link.href.includes('.pdf')) { event.preventDefault(); setLinkHref(link.href); popupInstance.openOnePopup('.accessible-docs-popup', 50); } // Handle clicks on buttons with the class js-accessible-docs-submit const button = target.closest('.js-accessible-docs-submit') as HTMLButtonElement | null; if (button) { event.preventDefault(); handleSubmitAccessibleDocs(); } }); }; document.addEventListener('DOMContentLoaded', initAccessibleDocsPopupLogic, false); export {};