/** * Dailymotion Pro – Admin Video Embed * * Entry point for the Admin Video Embed page behavior. This file wires together * small modules that handle preview updates, state toggles, feedback, popups, * and contextual API actions. It initializes listeners on DOM ready and * exposes a couple of small helpers to the global scope for compatibility with * inline event handlers in PHP templates. */ import { configureWizardApi } from './Admin/SetupWizard/WizardApi'; import { addListeners } from './Admin/VideoEmbed/Listeners'; import { closePopupSimple, hidePopup, showPopup } from './Admin/VideoEmbed/Popup'; declare const dmProAdminEmbed: { apiUrl: string; wpNonce: string }; // Expose global helper used by inline onclick attributes in PHP views (popup Cancel/close) const closePopupAll = (): void => { closePopupSimple(); hidePopup('confirmConnectContextual'); }; (window as unknown as { closePopup?: () => void }).closePopup = closePopupAll; // Initialize once DOM is ready and add outside-click close for the overlay function init(): void { configureWizardApi(dmProAdminEmbed); addListeners(); ['confirmDisableContextual', 'confirmSaveContextual', 'confirmConnectContextual'].forEach((id) => { const overlay = document.getElementById(id); if (overlay) { overlay.addEventListener('click', (event) => { if (event.target === overlay) { closePopupAll(); } }); } }); const contextualToggle = document.getElementById('contextual_embed') as HTMLInputElement | null; const isConnected = contextualToggle?.dataset.connected === '1'; if (contextualToggle && !isConnected) { contextualToggle.addEventListener('change', (event) => { if (!contextualToggle.checked) return; event.stopImmediatePropagation(); event.stopPropagation(); contextualToggle.checked = false; showPopup('confirmConnectContextual'); }, true); } } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); }