// /js/submit_sale_modal.js (function () { const modal = document.getElementById('submitSaleModal'); const frame = document.getElementById('submitSaleFrame'); const closeBtn= document.getElementById('btnSubmitSaleClose'); if (!modal) return; function openModal() { if (frame && frame.tagName === 'IFRAME') frame.src = 'submit_sale.php'; modal.classList.remove('hidden'); modal.classList.add('flex'); modal.setAttribute('aria-hidden', 'false'); if (closeBtn) closeBtn.focus(); document.documentElement.style.overflow = 'hidden'; } function closeModal() { modal.classList.add('hidden'); modal.classList.remove('flex'); modal.setAttribute('aria-hidden', 'true'); document.documentElement.style.overflow = ''; } // Open window document.addEventListener('click', function (e) { const a = e.target.closest('a[data-open-submit-sale]'); if (!a) return; e.preventDefault(); openModal(); }); // Close window if (closeBtn) closeBtn.addEventListener('click', closeModal); // Close window modal.addEventListener('click', function (e) { if (e.target === modal) closeModal(); }); // Close window document.addEventListener('keydown', function (e) { if (e.key === 'Escape' && !modal.classList.contains('hidden')) closeModal(); }); /* ---- post-sale story share ------------------------------------------------- The share UI lives on the parent page (partials/share_card_popup.php, driven by js/share_card.js) rather than in the iframe: the sale modal is torn down the moment the sale lands, which took the share button with it. There is NO way from mobile web to push an image straight into the Stories composer — instagram-stories:// needs a native pasteboard/intent payload, and the Content Publishing API needs a Professional account + Meta app review. So: use the OS share sheet where it exists, else save-then-open. Expect the fallback often. */ window.addEventListener('message', function (ev) { const msg = ev.data || {}; if (msg.type === 'submit-sale:success' || msg.type === 'submit-sale:cancel') { closeModal(); if (msg.type === 'submit-sale:success') { // Toast first, but never let it take the share prompt down with it — an // undefined Toast on some page would throw and the card would never open. try { Toast.success('Lead marked as SOLD successfully!'); } catch (e) {} if (msg.share && window.ShareCard) { window.ShareCard.open(msg.share.type || 'Lead'); } } } }); })();