MCPcopy Create free account
hub / github.com/error311/FileRise / wireModalA11y

Function wireModalA11y

public/js/main.js:531–583  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

529}
530
531function wireModalA11y() {
532 if (window.__FR_FLAGS.wired.modalA11y) return;
533 window.__FR_FLAGS.wired.modalA11y = true;
534
535 document.querySelectorAll(MODAL_SELECTOR).forEach(refreshModalState);
536
537 const modalObserver = new MutationObserver((mutations) => {
538 const toRefresh = new Set();
539 const toClose = new Set();
540
541 mutations.forEach((m) => {
542 if (m.type === 'attributes') {
543 if (m.target && m.target.matches && m.target.matches(MODAL_SELECTOR)) {
544 toRefresh.add(m.target);
545 }
546 return;
547 }
548 if (m.type !== 'childList') return;
549
550 m.addedNodes.forEach((node) => {
551 if (!node || node.nodeType !== 1) return;
552 if (node.matches && node.matches(MODAL_SELECTOR)) toRefresh.add(node);
553 node.querySelectorAll?.(MODAL_SELECTOR).forEach((el) => toRefresh.add(el));
554 });
555 m.removedNodes.forEach((node) => {
556 if (!node || node.nodeType !== 1) return;
557 if (node.matches && node.matches(MODAL_SELECTOR)) toClose.add(node);
558 node.querySelectorAll?.(MODAL_SELECTOR).forEach((el) => toClose.add(el));
559 });
560 });
561
562 toClose.forEach((modal) => {
563 if (modal.__frOpen) handleModalClose(modal);
564 });
565 toRefresh.forEach(refreshModalState);
566 });
567
568 modalObserver.observe(document.body, {
569 subtree: true,
570 childList: true,
571 attributes: true,
572 attributeFilter: ['style', 'class', 'hidden']
573 });
574
575 document.addEventListener('keydown', (e) => {
576 if (e.key !== 'Escape') return;
577 const open = getOpenModals();
578 if (!open.length) return;
579 e.preventDefault();
580 e.stopPropagation();
581 closeModalElement(open[open.length - 1]);
582 }, true);
583}
584
585window.__frGetOpenModals = getOpenModals;
586window.__frIsModalOpen = () => getOpenModals().length > 0;

Callers 1

bootHeavyFunction · 0.85

Calls 3

handleModalCloseFunction · 0.85
getOpenModalsFunction · 0.85
closeModalElementFunction · 0.85

Tested by

no test coverage detected