| 37 | |
| 38 | // Scan STL Home + AI Config Test: delegated click handlers (Server/Docker - main block may run late) |
| 39 | function _attachEarlyButtonHandlers() { |
| 40 | if (!document.body || document.body._earlyButtonHandlersAttached) return; |
| 41 | document.body._earlyButtonHandlersAttached = true; |
| 42 | document.body.addEventListener('click', function _earlyDelegated(e) { |
| 43 | if (!e.target || !e.target.closest) return; |
| 44 | if (e.target.closest('#scan-stl-home-button')) { |
| 45 | var btn = document.getElementById('scan-stl-home-button'); |
| 46 | if (btn && btn.style.display === 'none') return; |
| 47 | e.preventDefault(); |
| 48 | e.stopPropagation(); |
| 49 | if (typeof window.runScanSTLHome === 'function') window.runScanSTLHome(); |
| 50 | else window._pendingScanStlHome = true; |
| 51 | return; |
| 52 | } |
| 53 | if (e.target.closest('#test-ai-config')) { |
| 54 | e.preventDefault(); |
| 55 | e.stopPropagation(); |
| 56 | if (typeof window.testAIConfigFromDialog === 'function') window.testAIConfigFromDialog(); |
| 57 | return; |
| 58 | } |
| 59 | }); |
| 60 | } |
| 61 | if (document.readyState === 'loading') { |
| 62 | document.addEventListener('DOMContentLoaded', _attachEarlyButtonHandlers); |
| 63 | } else { |