Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
337 lines (256 loc) · 10.6 KB
/
Copy pathscript.js
File metadata and controls
337 lines (256 loc) · 10.6 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*dropping animation*/
var c = document.getElementById("canvas-club");
var ctx = c.getContext("2d");
var w = c.width = window.innerWidth;
var h = c.height = window.innerHeight;
var clearColor = 'rgba(0, 0, 0, .1)';
var max = 30;
var drops = [];
function random(min, max) {
return Math.random() * (max - min) + min;
}
function O() { }
O.prototype = {
init: function () {
this.x = random(0, w);
this.y = 0;
this.color = 'hsl(0, 100%, 50%)'; // রঙ লাল করা হয়েছে
this.w = 2;
this.h = 1;
this.vy = random(4, 5);
this.vw = 3;
this.vh = 1;
this.size = 2;
this.hit = random(h * .8, h * .9);
this.a = 1;
this.va = .96;
},
draw: function () {
if (this.y > this.hit) {
ctx.beginPath();
ctx.moveTo(this.x, this.y - this.h / 2);
ctx.bezierCurveTo(
this.x + this.w / 2, this.y - this.h / 2,
this.x + this.w / 2, this.y + this.h / 2,
this.x, this.y + this.h / 2);
ctx.bezierCurveTo(
this.x - this.w / 2, this.y + this.h / 2,
this.x - this.w / 2, this.y - this.h / 2,
this.x, this.y - this.h / 2);
ctx.strokeStyle = 'hsla(0, 100%, 50%, ' + this.a + ')'; // রঙ লাল করা হয়েছে
ctx.stroke();
ctx.closePath();
} else {
ctx.fillStyle = this.color;
ctx.fillRect(this.x, this.y, this.size, this.size * 5);
}
this.update();
},
update: function () {
if (this.y < this.hit) {
this.y += this.vy;
} else {
if (this.a > .03) {
this.w += this.vw;
this.h += this.vh;
if (this.w > 100) {
this.a *= this.va;
this.vw *= .98;
this.vh *= .98;
}
} else {
this.init();
}
}
}
}
function resize() {
w = c.width = window.innerWidth;
h = c.height = window.innerHeight;
}
function setup() {
for (var i = 0; i < max; i++) {
(function (j) {
setTimeout(function () {
var o = new O();
o.init();
drops.push(o);
}, j * 200)
}(i));
}
}
function anim() {
ctx.fillStyle = clearColor;
ctx.fillRect(0, 0, w, h);
for (var i in drops) {
drops[i].draw();
}
requestAnimationFrame(anim);
}
window.addEventListener("resize", resize);
setup();
anim();
/*nav er element highlight*/
const sections = document.querySelectorAll("section");
const navLinks = document.querySelectorAll(".nav ul li a");
function setActive() {
let current = "";
sections.forEach(section => {
const sectionTop = section.offsetTop - 120; // header height adjust
const sectionHeight = section.clientHeight;
if (pageYOffset >= sectionTop && pageYOffset < sectionTop + sectionHeight) {
current = section.getAttribute("id");
}
});
// যদি শেষ section এ পৌঁছে যাই, তাহলে current এ সেট করো
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 2) {
current = sections[sections.length - 1].getAttribute("id");
}
navLinks.forEach(link => {
link.classList.remove("active");
if (link.getAttribute("href") === "#" + current) {
link.classList.add("active");
}
});
}
// scroll হলে কাজ করবে
window.addEventListener("scroll", setActive);
// page load হলে সাথে সাথে কাজ করবে
window.addEventListener("load", setActive);
//donar filter+reg korle donar section e add hobe
document.addEventListener("DOMContentLoaded", () => {
const donorForm = document.getElementById("donarform");
const donorList = document.getElementById("donorlist");
const searchForm = document.getElementById("searchForm");
const resetBtn = document.getElementById("resetBtn");
const noResult = document.getElementById("noResult");
// localStorage থেকে donor load করা
let donorsData = JSON.parse(localStorage.getItem("donors")) || [];
// donor card বানানোর ফাংশন
function createDonorCard(donor) {
const donorCard = document.createElement("div");
donorCard.classList.add("pro");
donorCard.setAttribute("data-blood", donor.bloodGroup);
donorCard.setAttribute("data-upojela", donor.upozila);
donorCard.innerHTML = `
<img src="${donor.photo}" alt="">
<div class="des">
<span class="inf">Donar</span>
<h4>Name: <span class="info">${donor.name}</span></h4>
<h4>Blood: <span class="info">${donor.bloodGroup}</span></h4>
<h4><span class="info">${donor.age} years old</span></h4>
<h4>Upozila: <span class="info">${donor.upozila}</span></h4>
<h4>Address: <span class="info">${donor.address}</span></h4>
<h4>Number: <span class="info">${donor.mobile}</span></h4>
<a href="#"><button
onclick="window.open('https://wa.me/88${donor.mobile}?text=Assalamu%20alaikum%2C%20ami%20aapnar%20donation%20niye%20book%20korte%20chai.')">Book Now</button></a>
</div>
`;
donorList.insertBefore(donorCard, noResult);
}
// localStorage থেকে সব donor load করা
donorsData.forEach(donor => createDonorCard(donor));
// 🔹 Donor Registration Form Submit
donorForm.addEventListener("submit", function (e) {
e.preventDefault();
const photoInput = document.getElementById("photo");
const bloodGroup = document.getElementById("bloodGroup").value;
const name = document.getElementById("name").value;
const upozila = document.getElementById("upozilaReg").value;
const age = document.getElementById("age").value;
const address = document.getElementById("address").value;
const mobile = document.getElementById("mobile").value;
const email = document.getElementById("email").value; // থাকবে কিন্তু card এ দেখাবো না
// Image Base64 convert
const reader = new FileReader();
reader.onload = function (event) {
let photoURL = event.target.result;
// donor object
const newDonor = { photo: photoURL, bloodGroup, name, upozila, age, address, mobile, email };
// localStorage এ save
donorsData.push(newDonor);
localStorage.setItem("donors", JSON.stringify(donorsData));
// donor card তৈরি
createDonorCard(newDonor);
donorForm.reset();
donorList.scrollIntoView({ behavior: "smooth", block: "start" });
};
if (photoInput.files && photoInput.files[0]) {
reader.readAsDataURL(photoInput.files[0]); // Base64 save হবে
}
});
// 🔹 Donor Search Form Submit
searchForm.addEventListener("submit", function (e) {
e.preventDefault();
const bloodGroup = document.getElementById("blood_group").value.trim();
const upozila = document.getElementById("upozilaSearch").value.trim();
const donors = donorList.querySelectorAll(".pro");
let found = false;
donors.forEach(donor => {
const donorBlood = donor.getAttribute("data-blood")?.trim();
const donorUpozila = donor.getAttribute("data-upojela")?.trim();
const matchBlood = bloodGroup === "" || donorBlood === bloodGroup;
const matchUpozila = upozila === "" || donorUpozila === upozila;
if (matchBlood && matchUpozila) {
donor.style.display = "block";
found = true;
} else {
donor.style.display = "none";
}
});
noResult.style.display = found ? "none" : "block";
donorList.scrollIntoView({ behavior: "smooth", block: "start" });
});
// 🔹 Reset Button
resetBtn.addEventListener("click", function () {
document.getElementById("blood_group").value = "";
document.getElementById("upozilaSearch").value = "";
const donors = donorList.querySelectorAll(".pro");
donors.forEach(donor => donor.style.display = "block");
noResult.style.display = "none";
donorList.scrollIntoView({ behavior: "smooth", block: "start" });
});
});
//sign up and profile setup
// Smooth scroll to signup form
document.getElementById("signupBtn").addEventListener("click", () => {
document.querySelector("#donate").scrollIntoView({ behavior: "smooth" });
});
// Temporary "database"
let users = [];
let currentUser = null;
// Handle donor registration (signup)
document.getElementById("donarform").addEventListener("submit", function(e) {
e.preventDefault();
const email = document.querySelector("#email").value;
const password = document.querySelector("#password").value;
const name = document.querySelector("#name").value;
const photoInput = document.querySelector("#photo");
let photoURL = "default.jpg";
if (photoInput.files && photoInput.files[0]) {
photoURL = URL.createObjectURL(photoInput.files[0]);
}
// Save new user
users.push({ email, password, name, photo: photoURL });
alert("Signup successful! এখন Login করুন।");
// Clear form
this.reset();
});
// Handle login
document.getElementById("loginBtn").addEventListener("click", () => {
const email = prompt("Enter your email:");
const password = prompt("Enter your password:");
const user = users.find(u => u.email === email && u.password === password);
if (user) {
currentUser = user;
alert("Login successful!");
// Hide login/signup
document.getElementById("loginBtn").style.display = "none";
document.getElementById("signupBtn").style.display = "none";
// Show profile menu
document.getElementById("profileMenu").style.display = "inline-block";
document.getElementById("navProfilePic").src = user.photo;
} else {
alert("Invalid email or password!");
}
});