index-soutien/assets/js/donorbox-gauge.js
isUnknown 322d9136b6 PHP dynamique + cache JSON, nettoyage CSS/HTML, CI Forgejo
- Renommage classes/IDs (BEM cohérent, anglais, noms sémantiques)
- Correction HTML : h3→h2 FAQ, button>a→a[role=button] CTA mobile
- Conversion index.html → index.php (FR/EN) avec cache JSON depuis API Kirby
- Pages merci/thanks converties en PHP dynamique
- Ajout includes/cache.php + includes/config.php (cache TTL 5min)
- Ajout CI Forgejo (deploy FTP via lftp)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 08:00:58 +02:00

85 lines
2.1 KiB
JavaScript

const DONORBOX_CONFIG = {
proxyUrl: '/api/donorbox-proxy.php',
};
const RECURRING_DONORS_OFFSET = 98;
const GOAL_SUPPORTERS = 500;
async function fetchDonorboxData() {
try {
const response = await fetch(DONORBOX_CONFIG.proxyUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
throw new Error(`HTTP error ${response.status}: ${response.statusText}`);
}
const data = await response.json();
if (data.error) {
throw new Error(data.error);
}
return data;
} catch (error) {
console.error('Error fetching Donorbox data:', error);
throw error;
}
}
function updateGaugeDisplay(campaignData) {
const recurringCount = campaignData.recurring_donors_count || 0;
const totalSupport = recurringCount + RECURRING_DONORS_OFFSET;
const percentage = Math.min((totalSupport / GOAL_SUPPORTERS) * 100, 100);
const gaugeElement = document.getElementById('gauge');
if (gaugeElement) {
gaugeElement.style.setProperty(
'--pourcent',
`${percentage > 2.5 ? percentage : 2.5}%`
);
}
const countElement = document.querySelector(
'#gauge-info--supporters .value'
);
if (countElement) {
countElement.textContent = totalSupport;
}
console.log('Gauge updated:', {
recurringDonors: recurringCount,
totalSupport,
percentage: `${percentage.toFixed(1)}%`,
});
}
async function initDonorboxGauge() {
try {
console.log('Fetching Donorbox data...');
const campaignData = await fetchDonorboxData();
updateGaugeDisplay(campaignData);
} catch (error) {
console.error('Failed to update gauge:', error);
}
}
function setupAutoRefresh(intervalMinutes = 5) {
const intervalMs = intervalMinutes * 60 * 1000;
setInterval(initDonorboxGauge, intervalMs);
console.log(`Auto-refresh configured: every ${intervalMinutes} minutes`);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
initDonorboxGauge();
setupAutoRefresh(5);
});
} else {
initDonorboxGauge();
setupAutoRefresh(5);
}