File size: 6,950 Bytes
54469c9
 
 
7f226bd
54469c9
 
 
 
 
7f226bd
54469c9
7f226bd
 
 
 
 
 
54469c9
 
 
 
 
7f226bd
 
54469c9
 
 
7f226bd
 
 
54469c9
 
 
 
 
7f226bd
54469c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f226bd
54469c9
 
 
 
 
7f226bd
54469c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f226bd
 
54469c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a02783a
54469c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a02783a
54469c9
 
 
 
 
 
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
// Shared JavaScript for Leo's Voice Website

// Initialize Feather Icons
document.addEventListener('DOMContentLoaded', function() {
    if (typeof feather !== 'undefined') {
        feather.replace();
    }
    
    // Smooth scrolling for anchor links
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            const targetId = this.getAttribute('href');
            if (targetId === '#') return;
            
            const targetElement = document.querySelector(targetId);
            if (targetElement) {
                const headerHeight = document.querySelector('leo-navbar')?.offsetHeight || 80;
                const targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset - headerHeight;
                
                window.scrollTo({
                    top: targetPosition,
                    behavior: 'smooth'
                });
                
                // Update URL without page jump
                history.pushState(null, null, targetId);
            }
        });
    });
    
    // Navbar scroll effect
    const navbar = document.querySelector('leo-navbar');
    if (navbar) {
        let lastScrollTop = 0;
        
        window.addEventListener('scroll', function() {
            const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
            const navbarShadow = navbar.querySelector('.navbar-container');
            
            if (scrollTop > 100) {
                navbarShadow.classList.add('shadow-lg', 'bg-white/95', 'backdrop-blur-sm');
                navbarShadow.classList.remove('bg-transparent');
            } else {
                navbarShadow.classList.remove('shadow-lg', 'bg-white/95', 'backdrop-blur-sm');
                navbarShadow.classList.add('bg-transparent');
            }
            
            lastScrollTop = scrollTop;
        });
    }
    
    // Parallax effect for hero background
    const heroSection = document.querySelector('.relative.bg-gradient-to-br');
    if (heroSection) {
        window.addEventListener('scroll', function() {
            const scrolled = window.pageYOffset;
            const rate = scrolled * -0.5;
            const bgElement = heroSection.querySelector('.absolute.inset-0');
            if (bgElement) {
                bgElement.style.transform = `translateY(${rate}px)`;
            }
        });
    }
    
    // Intersection Observer for fade-in animations
    const observerOptions = {
        threshold: 0.1,
        rootMargin: '0px 0px -50px 0px'
    };
    
    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.classList.add('animate-fade-in-up');
            }
        });
    }, observerOptions);
    
    // Observe all sections and cards
    document.querySelectorAll('section, .bg-white.rounded-2xl').forEach(el => {
        observer.observe(el);
    });
    
    // Newsletter form submission
    const newsletterForm = document.getElementById('newsletterForm');
    if (newsletterForm) {
        newsletterForm.addEventListener('submit', function(e) {
            e.preventDefault();
            const email = this.querySelector('input[type="email"]').value;
            
            // Simulate form submission
            const submitBtn = this.querySelector('button[type="submit"]');
            const originalText = submitBtn.innerHTML;
            
            submitBtn.innerHTML = '<i data-feather="check" class="inline mr-2"></i> Subscribed!';
            submitBtn.disabled = true;
            submitBtn.classList.add('bg-green-600');
            
            // Reset after 3 seconds
            setTimeout(() => {
                submitBtn.innerHTML = originalText;
                submitBtn.disabled = false;
                submitBtn.classList.remove('bg-green-600');
                this.reset();
            }, 3000);
            
            // In a real app, you would send this to your backend
            console.log('Newsletter subscription:', email);
        });
    }
    
    // Donation amount selection
    const donationAmounts = document.querySelectorAll('[data-donation-amount]');
    donationAmounts.forEach(amount => {
        amount.addEventListener('click', function() {
            donationAmounts.forEach(a => a.classList.remove('border-primary-600', 'bg-primary-50'));
            this.classList.add('border-primary-600', 'bg-primary-50');
            
            const customAmount = document.getElementById('customAmount');
            if (customAmount) {
                customAmount.value = this.getAttribute('data-donation-amount');
            }
        });
    });
    
    // Custom donation amount input
    const customAmountInput = document.getElementById('customAmount');
    if (customAmountInput) {
        customAmountInput.addEventListener('input', function() {
            donationAmounts.forEach(a => a.classList.remove('border-primary-600', 'bg-primary-50'));
        });
    }
});

// Debounce function for scroll events
function debounce(func, wait) {
    let timeout;
    return function executedFunction(...args) {
        const later = () => {
            clearTimeout(timeout);
            func(...args);
        };
        clearTimeout(timeout);
        timeout = setTimeout(later, wait);
    };
}

// Copy to clipboard functionality
function copyToClipboard(text) {
    navigator.clipboard.writeText(text).then(() => {
        // Show success message
        const toast = document.createElement('div');
        toast.className = 'fixed bottom-4 right-4 bg-green-500 text-white px-6 py-3 rounded-xl shadow-lg z-50 animate-fade-in-up';
        toast.innerHTML = '<i data-feather="check" class="inline mr-2"></i> Copied to clipboard!';
        document.body.appendChild(toast);
        feather.replace();
        
        setTimeout(() => {
            toast.remove();
        }, 3000);
    }).catch(err => {
        console.error('Failed to copy: ', err);
    });
}

// Form validation helper
function validateEmail(email) {
    const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    return re.test(email);
}

// Add active class to current page in navigation
function setActiveNavLink() {
    const currentPath = window.location.pathname;
    const navLinks = document.querySelectorAll('nav a');
    
    navLinks.forEach(link => {
        const linkPath = link.getAttribute('href');
        if (linkPath === currentPath || (currentPath.includes(linkPath) && linkPath !== '/')) {
            link.classList.add('text-primary-600', 'font-bold');
            link.classList.remove('text-gray-700');
        }
    });
}

// Initialize when DOM is loaded
if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', setActiveNavLink);
} else {
    setActiveNavLink();
}