|
1 | | -import { CountUp } from 'countup.js'; |
2 | | - |
3 | | -const countUpOptions = { |
4 | | - separator: ' ', |
5 | | - decimal: ',', |
6 | | - suffix: ' €', |
7 | | - duration: 1.5, |
8 | | -}; |
9 | | - |
10 | | -let amountCountUp = null; |
11 | | -let lastDonorCount = null; |
12 | | - |
13 | | -function initCountUp() { |
14 | | - if (!amountCountUp) { |
15 | | - const amountEl = document.getElementById('card-amount'); |
16 | | - if (amountEl && typeof CountUp !== 'undefined') { |
17 | | - const startVal = window.currentAmount / 100; |
18 | | - amountCountUp = new CountUp('card-amount', startVal, countUpOptions); |
19 | | - if (!amountCountUp.error) { |
20 | | - amountCountUp.start(); |
21 | | - } |
22 | | - } |
23 | | - } |
24 | | -} |
25 | | - |
26 | 1 | function updateCardWidget() { |
27 | 2 | const currentAmountUnit = window.currentAmount / 100; |
28 | 3 | const goal = window.goalAmount || 1; |
29 | 4 | const percentage = Math.min(100, Math.round((currentAmountUnit / goal) * 100)); |
30 | 5 |
|
| 6 | + const amountEl = document.getElementById('card-amount'); |
31 | 7 | const barFill = document.getElementById('card-bar-fill'); |
32 | 8 | const percentEl = document.getElementById('card-percentage'); |
33 | 9 | const donorsEl = document.getElementById('card-donors'); |
34 | 10 |
|
35 | | - // Animate amount with CountUp |
36 | | - initCountUp(); |
37 | | - if (amountCountUp) { |
38 | | - amountCountUp.update(currentAmountUnit); |
39 | | - } else { |
40 | | - const amountEl = document.getElementById('card-amount'); |
41 | | - if (amountEl) amountEl.textContent = currentAmountUnit.toLocaleString('fr-FR') + ' €'; |
42 | | - } |
43 | | - |
| 11 | + if (amountEl) amountEl.textContent = currentAmountUnit.toLocaleString('fr-FR') + ' €'; |
44 | 12 | if (barFill) barFill.style.width = percentage + '%'; |
45 | 13 | if (percentEl) percentEl.textContent = percentage + '%'; |
46 | | - |
47 | | - // Animate donor count change |
48 | | - const newDonorCount = window.donorCount ?? 0; |
49 | | - if (donorsEl) { |
50 | | - if (lastDonorCount !== null && newDonorCount !== lastDonorCount) { |
51 | | - donorsEl.classList.add('card-widget__pulse'); |
52 | | - setTimeout(() => donorsEl.classList.remove('card-widget__pulse'), 600); |
53 | | - } |
54 | | - donorsEl.textContent = newDonorCount; |
55 | | - } |
56 | | - lastDonorCount = newDonorCount; |
| 14 | + if (donorsEl) donorsEl.textContent = window.donorCount ?? 0; |
57 | 15 | } |
58 | 16 |
|
59 | 17 | export default updateCardWidget; |
60 | | - |
0 commit comments