-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
616 lines (537 loc) · 26.2 KB
/
Copy pathscript.js
File metadata and controls
616 lines (537 loc) · 26.2 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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
// Book Request Function
function requestBook(bookTitle) {
// Redirect directly to the Google Form for getting books
window.open('https://forms.gle/LeDorPLgUH9xrAD46', '_blank');
}
// Wait for the DOM to be fully loaded
document.addEventListener('DOMContentLoaded', function () {
// Mobile Navigation Toggle
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
if (hamburger && navLinks) {
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('active');
hamburger.classList.toggle('active');
});
// Close mobile menu when clicking outside
document.addEventListener('click', (e) => {
if (!hamburger.contains(e.target) && !navLinks.contains(e.target)) {
navLinks.classList.remove('active');
hamburger.classList.remove('active');
}
});
}
// Sticky Header
const header = document.getElementById('header');
const scrollThreshold = 50;
window.addEventListener('scroll', function () {
if (window.scrollY > scrollThreshold) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
});
// Active Navigation Link
const sections = document.querySelectorAll('section');
const navItems = document.querySelectorAll('.nav-links a');
window.addEventListener('scroll', function () {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (window.pageYOffset >= (sectionTop - 150)) {
current = section.getAttribute('id');
}
});
navItems.forEach(item => {
item.classList.remove('active');
if (item.getAttribute('href').substring(1) === current) {
item.classList.add('active');
}
});
});
// Smooth scrolling for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
// Close mobile menu if open
navLinks.classList.remove('active');
hamburger.classList.remove('active');
}
});
});
// Navbar scroll effect
const navbar = document.querySelector('.navbar');
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll <= 0) {
navbar.classList.remove('scroll-up');
return;
}
if (currentScroll > lastScroll && !navbar.classList.contains('scroll-down')) {
// Scroll Down
navbar.classList.remove('scroll-up');
navbar.classList.add('scroll-down');
} else if (currentScroll < lastScroll && navbar.classList.contains('scroll-down')) {
// Scroll Up
navbar.classList.remove('scroll-down');
navbar.classList.add('scroll-up');
}
lastScroll = currentScroll;
});
// Intersection Observer for fade-in animations
const observerOptions = {
root: null,
threshold: 0.1,
rootMargin: '0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in');
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Add fade-in animation to elements
document.querySelectorAll('.counter-item, .program-card, .involvement-card').forEach(el => {
observer.observe(el);
});
// Newsletter form submission
const newsletterForm = document.querySelector('.newsletter-form');
if (newsletterForm) {
newsletterForm.addEventListener('submit', (e) => {
e.preventDefault();
const email = newsletterForm.querySelector('input[type="email"]').value;
// Here you would typically send this to your backend
// For now, we'll just show a success message
alert('Thank you for subscribing to our newsletter!');
newsletterForm.reset();
});
}
// Counter Animation
function animateCounter(element, target, duration = 2000) {
let start = 0;
const increment = target / (duration / 16); // ~60fps
const counter = element.querySelector('.counter');
function updateCounter() {
start += increment;
if (start < target) {
counter.textContent = Math.floor(start) + '+';
requestAnimationFrame(updateCounter);
} else {
counter.textContent = target + '+';
}
}
updateCounter();
}
// Initialize counters when they come into view
const counterItems = document.querySelectorAll('.counter-item');
const counterObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const counter = entry.target.querySelector('.counter');
const textValue = counter.textContent.trim();
const target = parseInt(textValue.replace('+', '')) || 0;
animateCounter(entry.target, target);
counterObserver.unobserve(entry.target);
}
});
}, { threshold: 0.5 });
counterItems.forEach(item => counterObserver.observe(item));
// Team member hover effect
const teamMembers = document.querySelectorAll('.team-member');
teamMembers.forEach(member => {
member.addEventListener('mouseenter', () => {
member.querySelector('.member-overlay').style.opacity = '1';
});
member.addEventListener('mouseleave', () => {
member.querySelector('.member-overlay').style.opacity = '0';
});
});
// Form handling with formsubmit.co
const forms = document.querySelectorAll('form');
forms.forEach(form => {
form.addEventListener('submit', async (e) => {
e.preventDefault();
const submitButton = form.querySelector('button[type="submit"]');
const originalText = submitButton.textContent;
submitButton.textContent = 'Sending...';
submitButton.disabled = true;
try {
const formData = new FormData(form);
const response = await fetch(form.action, {
method: 'POST',
body: formData,
headers: {
'Accept': 'application/json'
}
});
if (response.ok) {
showMessage(form, 'Thank you for your submission!', 'success');
form.reset();
} else {
throw new Error('Something went wrong');
}
} catch (error) {
showMessage(form, 'Something went wrong. Please try again.', 'error');
} finally {
submitButton.textContent = originalText;
submitButton.disabled = false;
}
});
});
// Show success/error message
function showMessage(form, message, type) {
const messageDiv = document.createElement('div');
messageDiv.className = `${type}-message`;
messageDiv.textContent = message;
// Remove any existing messages
const existingMessage = form.querySelector(`.${type}-message`);
if (existingMessage) {
existingMessage.remove();
}
form.appendChild(messageDiv);
// Remove message after 3 seconds
setTimeout(() => {
messageDiv.remove();
}, 3000);
}
// Intersection Observer for fade-in animations
const fadeElements = document.querySelectorAll('.vision-card, .mission-card, .member-card, .program-card');
const fadeObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in');
fadeObserver.unobserve(entry.target);
}
});
}, { threshold: 0.1 });
fadeElements.forEach(el => fadeObserver.observe(el));
// Add scroll-to-top button
const scrollTopButton = document.createElement('button');
scrollTopButton.innerHTML = '↑';
scrollTopButton.className = 'scroll-to-top';
document.body.appendChild(scrollTopButton);
scrollTopButton.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// Show/hide scroll-to-top button
window.addEventListener('scroll', () => {
if (window.pageYOffset > 300) {
scrollTopButton.classList.add('visible');
} else {
scrollTopButton.classList.remove('visible');
}
});
// Add CSS for scroll-to-top button
const style = document.createElement('style');
style.textContent = `
.scroll-to-top {
position: fixed;
bottom: 20px;
right: 20px;
background: var(--primary-color);
color: white;
width: 40px;
height: 40px;
border-radius: 50%;
border: none;
cursor: pointer;
opacity: 0;
transition: opacity 0.3s, transform 0.3s;
transform: translateY(100px);
z-index: 1000;
}
.scroll-to-top.visible {
opacity: 1;
transform: translateY(0);
}
.scroll-to-top:hover {
background: var(--secondary-color);
}
`;
document.head.appendChild(style);
// Modal logic for Get Books
function openGetBooksModal() {
document.getElementById('bookCategoriesModal').style.display = 'block';
}
function closeGetBooksModal() {
document.getElementById('bookCategoriesModal').style.display = 'none';
}
// Close modal when clicking outside or pressing Escape
window.addEventListener('click', function (event) {
const modal = document.getElementById('bookCategoriesModal');
if (event.target === modal) {
closeGetBooksModal();
}
});
window.addEventListener('keydown', function (event) {
if (event.key === 'Escape') {
closeGetBooksModal();
}
});
// AI Chatbot Functionality
const chatbotData = {
"about pageforward": {
response: "PageForward is a student-driven non-profit organization focused on creating a sustainable future through education. We collect, redistribute, and recycle educational materials like books and notebooks, making them accessible to underprivileged students while reducing environmental impact. Our mission extends beyond recycling - we're creating a movement of conscious education that respects both learning and our environment.",
actions: ["Our Team", "Our Programs", "Environmental Impact"]
},
"mission": {
response: "Our mission is to collect, redistribute, and recycle educational materials, making them accessible to underprivileged students while reducing environmental impact and promoting sustainable practices in education.",
actions: ["Our Vision", "Programs", "Get Involved"]
},
"vision": {
response: "Our vision is to create a world where every student has access to quality education materials while promoting environmental sustainability through the reuse and recycling of educational resources.",
actions: ["Our Mission", "Environmental Impact", "Team"]
},
"team": {
response: "Our passionate team includes:\n\n👨💼 **Abdul Rahim** - President: Leading the change in sustainable education\n👨💼 **Ammar Jaffar** - Vice President: Innovation meets sustainability\n📢 **Ehtisham Niyat** - Lead Communication & Marketing: Connecting hearts through education\n📚 **Zen Ul Aabdin** - Lead Collection Officer: Every book has a story to continue\n💻 **Inayat Rahim** - Tech Lead: Technology for sustainable tomorrow",
actions: ["Contact Team", "Join Team", "Programs"]
},
"programs": {
response: "We offer four main programs:\n\n📚 **Book Collection**: Donate your used books to help students in need while reducing waste\n♻️ **Notebook Recycling**: We repurpose used notebooks to create new educational materials\n🤝 **Student Support**: Financial assistance and resources for underprivileged students\n👥 **Community Engagement**: Join our volunteer program and make a difference in your community",
actions: ["Donate Books", "Get Books", "Volunteer"]
},
"donate books": {
response: "Thank you for wanting to donate books! You can donate through our online form. We accept:\n\n📖 Fiction and Non-Fiction books\n📚 Textbooks\n👶 Children's Books\n📖 Reference Books\n\nWe offer both pickup and drop-off options. Your donated books will directly help students in need while promoting sustainability.",
actions: ["Donation Form", "Pickup Options", "What Books Accepted"]
},
"get books": {
response: "You can request free educational books through our Get Books program! We provide:\n\n📚 School Textbooks\n📓 Notebooks\n📖 Storybooks\n📚 Reference Books\n\nWe offer home delivery and self-pickup options. Simply fill out our request form with your details and book requirements.",
actions: ["Request Form", "Delivery Options", "Book Categories"]
},
"volunteer": {
response: "Join our volunteer program and make a real difference! Volunteers help with:\n\n📦 Book collection and sorting\n🚚 Distribution logistics\n📢 Community outreach\n💻 Digital initiatives\n🌱 Environmental awareness campaigns\n\nNo experience required - just passion for education and sustainability!",
actions: ["Volunteer Form", "Volunteer Roles", "Time Commitment"]
},
"environmental impact": {
response: "Our environmental impact includes:\n\n🌳 **Trees Saved**: 20+ trees saved through book reuse\n♻️ **Waste Reduction**: Reducing paper waste significantly\n🌱 **Sustainable Practices**: Promoting eco-friendly education\n🌍 **Awareness**: Building environmental consciousness in communities\n\nEvery book we save contributes to a greener planet!",
actions: ["Our Stats", "How It Works", "Join Movement"]
},
"contact": {
response: "📧 **Email**: pageforwardnonprofit@gmail.com\n📱 **Phone**: +92 3318955500\n\n**Social Media:**\n📘 Facebook: PageForward\n📷 Instagram: @pageforward.nonprofit\n💼 LinkedIn: PageForward\n\nFeel free to reach out with any questions or to learn more about our initiatives!",
actions: ["Send Message", "Follow Social Media", "Visit Office"]
},
"stats": {
response: "Our current impact:\n\n📚 **10+** Books Redistributed\n🌳 **20+** Trees Saved\n🎓 **10+** Students Helped\n📓 **10+** Notebooks Recycled\n\nThese numbers grow every day thanks to our amazing community support!",
actions: ["Environmental Impact", "Help Grow Stats", "Share Impact"]
},
"president message": {
response: "**President Abdul Rahim's Message:**\n\n\"At PageForward, we believe that education is not just about learning; it's about creating a sustainable future for generations to come. Every book we save, every student we help, and every tree we protect contributes to this vision. Join us in this noble cause of making education accessible while preserving our planet.\"\n\n- Abdul Rahim, President PageForward",
actions: ["Meet Team", "Our Vision", "Join Us"]
}
};
const chatbot = {
isOpen: false,
init() {
this.bindEvents();
},
bindEvents() {
const toggle = document.getElementById('chatbot-toggle');
const close = document.getElementById('chatbot-close');
const input = document.getElementById('chatbot-input');
const send = document.getElementById('chatbot-send');
toggle.addEventListener('click', () => this.toggleChat());
close.addEventListener('click', () => this.closeChat());
send.addEventListener('click', () => this.sendMessage());
input.addEventListener('keypress', (e) => {
if (e.key === 'Enter') this.sendMessage();
});
// Close chatbot when clicking outside
document.addEventListener('click', (e) => {
const container = document.getElementById('chatbot-container');
if (!container.contains(e.target) && this.isOpen) {
this.closeChat();
}
});
},
toggleChat() {
const window = document.getElementById('chatbot-window');
if (this.isOpen) {
this.closeChat();
} else {
window.classList.add('active');
this.isOpen = true;
document.getElementById('chatbot-input').focus();
}
},
closeChat() {
const window = document.getElementById('chatbot-window');
window.classList.remove('active');
this.isOpen = false;
},
sendMessage() {
const input = document.getElementById('chatbot-input');
const message = input.value.trim();
if (!message) return;
this.addMessage(message, 'user');
input.value = '';
// Show typing indicator
this.showTyping();
// Process message after delay
setTimeout(() => {
this.hideTyping();
this.processMessage(message);
}, 1000);
},
addMessage(content, type) {
const messages = document.getElementById('chatbot-messages');
const messageDiv = document.createElement('div');
messageDiv.className = `message ${type}-message`;
if (type === 'bot') {
messageDiv.innerHTML = `
<div class="message-content">
${this.formatMessage(content.response || content)}
${content.actions ? this.createQuickActions(content.actions) : ''}
</div>
`;
} else {
messageDiv.innerHTML = `
<div class="message-content">
<p>${content}</p>
</div>
`;
}
messages.appendChild(messageDiv);
messages.scrollTop = messages.scrollHeight;
},
formatMessage(text) {
// Convert markdown-style formatting to HTML
return text
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/\n\n/g, '</p><p>')
.replace(/\n/g, '<br>')
.replace(/^/, '<p>')
.replace(/$/, '</p>');
},
createQuickActions(actions) {
return `
<div class="quick-actions">
${actions.map(action =>
`<button class="quick-action-btn" onclick="chatbot.handleQuickAction('${action}')">${action}</button>`
).join('')}
</div>
`;
},
handleQuickAction(action) {
this.addMessage(action, 'user');
setTimeout(() => {
this.processMessage(action);
}, 500);
},
showTyping() {
const messages = document.getElementById('chatbot-messages');
const typingDiv = document.createElement('div');
typingDiv.className = 'message bot-message';
typingDiv.id = 'typing-indicator';
typingDiv.innerHTML = `
<div class="message-content typing-indicator">
<div class="typing-dots">
<span></span>
<span></span>
<span></span>
</div>
</div>
`;
messages.appendChild(typingDiv);
messages.scrollTop = messages.scrollHeight;
},
hideTyping() {
const typing = document.getElementById('typing-indicator');
if (typing) typing.remove();
},
processMessage(message) {
const lowerMessage = message.toLowerCase();
// Find matching response
let response = null;
for (const [key, value] of Object.entries(chatbotData)) {
if (lowerMessage.includes(key) || this.fuzzyMatch(lowerMessage, key)) {
response = value;
break;
}
}
// If no specific match, try broader matching
if (!response) {
// Check for general greetings
if (this.isGreeting(lowerMessage)) {
response = {
response: "Hello! 👋 Welcome to PageForward! I'm here to help you with any questions about our organization, programs, or how you can get involved. What would you like to know?",
actions: ["About PageForward", "Our Programs", "Donate Books", "Get Books", "Volunteer"]
};
}
// Check for help requests
else if (this.isHelpRequest(lowerMessage)) {
response = {
response: "I'm here to help! 🤝 Here's what I can assist you with regarding PageForward:",
actions: ["About PageForward", "Our Programs", "Donate Books", "Get Books", "Volunteer", "Contact", "Environmental Impact", "Our Team"]
};
}
// Check for thank you messages
else if (this.isThankYou(lowerMessage)) {
response = {
response: "You're very welcome! 😊 I'm glad I could help. Is there anything else you'd like to know about PageForward?",
actions: ["Our Programs", "Get Involved", "Contact"]
};
}
// Default fallback response
else {
response = {
response: "I'd be happy to help you learn more about PageForward! 📚 Here are some topics I can assist with:",
actions: ["About PageForward", "Our Programs", "Donate Books", "Get Books", "Volunteer", "Contact", "Environmental Impact", "Our Team"]
};
}
}
this.addMessage(response, 'bot');
},
isGreeting(message) {
const greetings = ['hello', 'hi', 'hey', 'good morning', 'good afternoon', 'good evening', 'greetings'];
return greetings.some(greeting => message.includes(greeting));
},
isHelpRequest(message) {
const helpWords = ['help', 'assist', 'support', 'guide', 'information', 'tell me'];
return helpWords.some(word => message.includes(word));
},
isThankYou(message) {
const thankWords = ['thank', 'thanks', 'appreciate', 'grateful'];
return thankWords.some(word => message.includes(word));
},
fuzzyMatch(input, keyword) {
// Expanded fuzzy matching for common variations
const variations = {
'about pageforward': ['about', 'pageforward', 'what is', 'who are', 'organization', 'company', 'info', 'information'],
'donate books': ['donate', 'donation', 'give books', 'book donation', 'contribute books', 'share books'],
'get books': ['get books', 'request books', 'need books', 'free books', 'book request', 'obtain books'],
'volunteer': ['volunteer', 'join', 'help', 'participate', 'get involved', 'work with'],
'contact': ['contact', 'email', 'phone', 'reach', 'get in touch', 'communicate'],
'team': ['team', 'members', 'staff', 'people', 'who works', 'leadership'],
'programs': ['programs', 'services', 'what do you do', 'activities', 'initiatives', 'projects'],
'environmental impact': ['environment', 'trees', 'sustainability', 'impact', 'green', 'eco', 'planet'],
'mission': ['mission', 'purpose', 'goal', 'objective', 'aim'],
'vision': ['vision', 'future', 'dream', 'aspiration'],
'stats': ['stats', 'statistics', 'numbers', 'data', 'impact numbers', 'achievements'],
'president message': ['president', 'abdul rahim', 'leader', 'ceo', 'head']
};
if (variations[keyword]) {
return variations[keyword].some(variation => input.includes(variation));
}
return false;
}
};
// Initialize chatbot
chatbot.init();
// Make functions globally available
window.openGetBooksModal = openGetBooksModal;
window.closeGetBooksModal = closeGetBooksModal;
window.chatbot = chatbot;
});