سامانه صدور فاکتور و حسابداری

fix: ensure visible modal close buttons and backdrop dismiss dynamic dialogs

davoodmehraban89 committed Oct 11, 2026 at 20:05 UTC 9316e027ee13e022156046ecd3c3168a1c554997
1 file changed +24
js/ux-hardening-r2.js
+24
@@ -57,6 +57,30 @@
57 const modals=[...document.querySelectorAll('.modal-backdrop.active')];if(!modals.length)return false;const m=modals[modals.length-1],cancel=[...m.querySelectorAll('button')].find(b=>/انصراف|بستن|لغو|✕/.test(b.textContent||''));if(cancel){cancel.click();return true}m.classList.remove('active');return true;
58 }
59 window.finoraCloseTopModal=closeTopModal;
60 + // A delegated close contract also covers late-rendered organization/access dialogs.
61 + // Execute before inline handlers so one broken/stale onclick cannot trap the user.
62 + function dismissModal(modal){
63 + if(!modal?.classList.contains('modal-backdrop'))return false;
64 + modal.classList.remove('active');
65 + modal.setAttribute('aria-hidden','true');
66 + const focused=document.activeElement;
67 + if(focused&&modal.contains(focused)&&typeof focused.blur==='function')focused.blur();
68 + return true;
69 + }
70 + document.addEventListener('click',e=>{
71 + const target=e.target instanceof Element?e.target:null;
72 + if(!target)return;
73 + const modal=target.closest('.modal-backdrop.active');
74 + if(!modal)return;
75 + const button=target.closest('button');
76 + const closeButton=!!button&&modal.contains(button)&&(button.matches('[data-finora-close-modal]')||/^(?:✕|×|\u2715)?\s*(?:بستن|انصراف)\s*(?:✕|×)?$/.test((button.textContent||'').trim()));
77 + if(closeButton||target===modal){
78 + e.preventDefault();
79 + e.stopImmediatePropagation();
80 + dismissModal(modal);
81 + }
82 + },true);
83 +
84 const THEME_CSS=`body.finora-theme-dark{--bg:#07111f;--surface:#0f1b2d;--card:#122238;--text:#e6edf7;--text-muted:#9db0c9;--border:#263a55;--primary:#22b8c7;color:var(--text);background:var(--bg)}body.finora-theme-dark .card,body.finora-theme-dark .modal-card,body.finora-theme-dark input,body.finora-theme-dark select,body.finora-theme-dark textarea{background:#122238!important;color:#e6edf7!important;border-color:#2b405d!important}body.finora-theme-dark table th,body.finora-theme-dark table td{border-color:#2b405d!important}body.finora-theme-dark .form-row[style*="background"]{background:#0d1a2c!important}`;
85 function ensureThemeCss(){if($('finora-theme-r2-css'))return;const s=document.createElement('style');s.id='finora-theme-r2-css';s.textContent=THEME_CSS;document.head.appendChild(s)}
86 function resolveTheme(mode){if(mode==='dark'||mode==='light')return mode;const h=new Date().getHours();return h>=7&&h<19?'light':'dark'}