document.addEventListener('DOMContentLoaded', function() { // Function to escape HTML entities function escapeHtml(text) { if (!text) return ''; var div = document.createElement('div'); div.textCOntent= text; return div.innerHTML; } // Function to render campaign based on display format function renderCampaign(campaign) { let html = ''; let displayFormat = campaign.display_format || 'text-only'; let title = escapeHtml(campaign.title); let description = escapeHtml(campaign.description); let callToAction = escapeHtml(campaign.call_to_action); let link = escapeHtml(campaign.link); // Check if required image URL is available for the display format, fallback to text-only if not if (displayFormat === 'small-with-description' && !campaign.img_small_url) { displayFormat = 'text-only'; } else if (displayFormat === 'banner-only' && !campaign.img_banner_url) { displayFormat = 'text-only'; } else if ((displayFormat === 'big-only' || displayFormat === 'big-with-description' || displayFormat === 'big-with-title-description-button') && !campaign.img_big_url) { displayFormat = 'text-only'; } html = `
${title}
`; switch(displayFormat) { case 'text-only': html += `
${description}
`; break; case 'small-with-description': html += `
${campaign.img_small_cid ? `
` : ''}
${description}
`; break; case 'banner-only': html += `
`; break; case 'big-only': html += `
`; break; case 'big-with-description': html += `
`; html += `
${description}
`; break; case 'big-with-title-description-button': html += `