-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
198 lines (158 loc) · 6.67 KB
/
script.js
File metadata and controls
198 lines (158 loc) · 6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
let totalDonations = 0; // Total donations (donations)
let currentGoal = 0; // User-selected goal
let currentProgress = 0; // Number of button presses (progress)
let goalSet = false; // Track if a goal is set
// Populate the goal selection dropdown (1 to 20)
document.addEventListener("DOMContentLoaded", function () {
let goalSelection = document.getElementById("goal-selection");
for (let i = 1; i <= 20; i++) {
let option = document.createElement("option");
option.value = i;
option.textContent = `${i} Donations`;
goalSelection.appendChild(option);
}
// Hide the "Please select a goal" message when the user selects an option
goalSelection.addEventListener("change", function () {
document.getElementById("goal-warning").style.display = "none";
});
});
// Toggle profile popup
function toggleProfile() {
document.getElementById("profile-popup").classList.toggle("active");
}
// Close the profile popup
function closeProfile() {
document.getElementById("profile-popup").classList.remove("active");
}
// Function to set a new goal
function setNewGoal() {
let goalSelection = document.getElementById("goal-selection").value;
let goalWarning = document.getElementById("goal-warning");
if (!goalSelection) {
goalWarning.textContent = "Please select a goal.";
goalWarning.style.display = "block";
// Show warning message
return;
} else {
goalWarning.style.display = "none"; // Hide warning if selection is valid
}
currentGoal = parseInt(goalSelection);
currentProgress = 0;
goalSet = true;
// Update progress bar to the maximum value
let progressBar = document.getElementById("progress-bar");
progressBar.max = currentGoal;
progressBar.value = currentProgress;
document.getElementById("progress-text").textContent = `${currentProgress} / ${currentGoal} donations`;
// Disable dropdown and button until goal is achieved
document.getElementById("goal-selection").disabled = true;
document.getElementById("set-goal-btn").disabled = true;
}
// Function to add a donation (button press)
function addDonation() {
// Increase total button presses
let donationAmount = parseInt(document.getElementById("donation-amount").value) || 0;
if (donationAmount <= 0) {
showPopupMessage("Please enter a valid donation amount.");
return;
}
// Update total donation amount
totalDonations += donationAmount;
document.getElementById("total-donations").textContent = `$${totalDonations}`;
document.getElementById("total-donations").textContent = totalDonations;
if (!goalSet) {
document.getElementById("goal-warning").textContent = "You can set a goal!";
document.getElementById("goal-warning").style.display = "block";
return;
}
// Increase progress by one per button press. For the donation progress
currentProgress++;
if (currentProgress > currentGoal) {
currentProgress = currentGoal; // Prevent exceeding the goal
}
let progressBar = document.getElementById("progress-bar");
progressBar.value = currentProgress;
document.getElementById("progress-text").textContent = `${currentProgress} / ${currentGoal} donations`;
// Check if goal is achieved
if (currentProgress >= currentGoal) {
awardBadge();
allowNewGoal(); // Enable setting a new goal
}
}
// Function to award a trophy when a goal is reached
function awardBadge() {
let achievementDiv = document.getElementById("achievements");
let trophy = document.createElement("i");
trophy.className = "bx bxs-trophy";
trophy.style.color = "gold";
trophy.style.fontSize = "24px";
trophy.style.marginLeft = "10px";
achievementDiv.appendChild(trophy);
let tooltip = document.createElement("span");
tooltip.className = "tooltip";
tooltip.textContent = "Goal Achieved! ";
}
// Allow user to set a new goal after the previous one is achieved
function allowNewGoal() {
goalSet = false;
// Enable dropdown and button for setting a new goal
document.getElementById("goal-selection").disabled = false;
document.getElementById("set-goal-btn").disabled = false;
document.getElementById("goal-warning").textContent = " Goal Achieved! Set a new goal!";
document.getElementById("goal-warning").style.color = "green";
document.getElementById("goal-warning").style.display = "block";
// Reset progress bar for next goal
document.getElementById("progress-bar").value = 0;
document.getElementById("progress-text").textContent = `0 / ${currentGoal} donations`;
}
// Opens the donation form
function openDonationForm(event) {
event.stopPropagation();
document.getElementById("donation-form-popup").style.display = "block";
}
// Submit donation and update progress
function submitDonation() {
let amount = parseInt(document.getElementById("donation-amount").value);
let goalWarning = document.getElementById("goal-warning");
if (isNaN(amount) || amount <= 0) {
goalWarning.textContent = "Please enter a valid donation amount.";
goalWarning.style.display = "block";
return;
} else {
goalWarning.style.display = "none";
}
addDonation(amount); // Call the function to update total and progress
alert(" Thank you for your donation!. Pls click on the profile icon to see your status"); // Show success message
// Reset form & close popup
document.getElementById("donation-amount").value = "";
closeDonationForm();
}
// Close donation form
function closeDonationForm() {
document.getElementById("donation-form-popup").style.display = "none";
}
let currentIndex = 0;
function moveSlide(direction) {
const gridWrapper = document.querySelector(".grid-wrapper");
const slides = document.querySelectorAll(".grid1-slide");
const totalSlides = slides.length;
currentIndex += direction;
if (currentIndex >= totalSlides) {
currentIndex = 0;
} else if (currentIndex < 0) {
currentIndex = totalSlides - 1;
}
gridWrapper.style.transform = `translateX(-${currentIndex * 100}%)`;
}
// Auto-slide every 20 seconds
const totalSlides = document.querySelectorAll(".grid1-slide").length;
if (totalSlides > 1) {
setInterval(() => moveSlide(1), 20000);
}
// Select all FAQ items
const faqItems = document.querySelectorAll(".faq-item");
faqItems.forEach((item) => {
item.addEventListener("click", () => {
item.classList.toggle("active");
});
});