Spaces:
Running
Running
File size: 7,087 Bytes
fad96f6 |
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 |
// Mobile Menu Toggle
function toggleMobileMenu() {
const mobileMenu = document.getElementById('mobile-menu');
mobileMenu.classList.toggle('hidden');
}
// Smooth Scroll for Anchor 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'
});
}
});
});
// Form Submission Handler
document.querySelectorAll('form').forEach(form => {
form.addEventListener('submit', async (e) => {
e.preventDefault();
const submitButton = form.querySelector('button[type="submit"]');
const originalText = submitButton.textContent;
// Show loading state
submitButton.innerHTML = '<span class="loading"></span> Processing...';
submitButton.disabled = true;
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 2000));
// Show success message
submitButton.textContent = '✓ Success!';
submitButton.classList.add('bg-green-600');
// Reset form after delay
setTimeout(() => {
form.reset();
submitButton.textContent = originalText;
submitButton.classList.remove('bg-green-600');
submitButton.disabled = false;
}, 3000);
});
});
// Intersection Observer for Animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe elements for animation
document.addEventListener('DOMContentLoaded', () => {
const animatedElements = document.querySelectorAll('.service-card, .testimonial-card, .blog-card');
animatedElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
});
// Dynamic Year in Footer
const currentYear = new Date().getFullYear();
const yearElements = document.querySelectorAll('.current-year');
yearElements.forEach(el => {
el.textContent = currentYear;
});
// Phone Number Formatting
const phoneInputs = document.querySelectorAll('input[type="tel"]');
phoneInputs.forEach(input => {
input.addEventListener('input', function(e) {
let phone = e.target.value.replace(/\D/g, '');
let formatted = phone;
if (phone.length >= 6) {
formatted = `(${phone.slice(0, 3)}) ${phone.slice(3, 6)}-${phone.slice(6, 10)}`;
} else if (phone.length >= 3) {
formatted = `(${phone.slice(0, 3)}) ${phone.slice(3)}`;
}
e.target.value = formatted;
});
});
// Insurance Checker
function checkInsurance() {
const insuranceChecker = document.createElement('div');
insuranceChecker.innerHTML = `
<div class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
<div class="bg-gray-800 p-8 rounded-2xl max-w-md w-full mx-4">
<h3 class="text-2xl font-bold mb-4">Check Your Insurance</h3>
<input type="text" placeholder="Enter Insurance Provider" class="form-input mb-4">
<input type="text" placeholder="Policy Number (Optional)" class="form-input mb-6">
<div class="flex gap-4">
<button onclick="this.parentElement.parentElement.parentElement.remove()" class="flex-1 py-3 bg-gray-700 hover:bg-gray-600 rounded-lg transition-colors">
Cancel
</button>
<button onclick="checkCoverage(this)" class="flex-1 py-3 bg-primary-600 hover:bg-primary-700 rounded-lg transition-colors">
Check Coverage
</button>
</div>
</div>
</div>
`;
document.body.appendChild(insuranceChecker);
}
function checkCoverage(button) {
button.innerHTML = '<span class="loading"></span> Checking...';
button.disabled = true;
setTimeout(() => {
const modal = button.closest('.fixed');
modal.innerHTML = `
<div class="bg-gray-800 p-8 rounded-2xl max-w-md w-full mx-4 text-center">
<i data-feather="check-circle" class="w-16 h-16 text-green-400 mx-auto mb-4"></i>
<h3 class="text-2xl font-bold mb-2">Coverage Confirmed!</h3>
<p class="text-gray-300 mb-6">Your insurance covers 80% of preventive care and 50% of major procedures.</p>
<button onclick="this.parentElement.parentElement.parentElement.remove()" class="py-3 bg-primary-600 hover:bg-primary-700 rounded-lg transition-colors px-8">
Great!
</button>
</div>
`;
feather.replace();
}, 2000);
}
// Add click event to insurance check button
document.addEventListener('DOMContentLoaded', () => {
const insuranceButton = document.querySelector('button[onclick="checkInsurance()"]');
if (insuranceButton) {
insuranceButton.addEventListener('click', checkInsurance);
}
});
// Real-time Form Validation
function validateForm() {
const inputs = document.querySelectorAll('.form-input');
inputs.forEach(input => {
input.addEventListener('blur', function() {
if (this.value.trim() === '' && this.hasAttribute('required')) {
this.classList.add('border-red-500');
this.classList.remove('border-green-500');
} else if (this.value.trim() !== '') {
this.classList.add('border-green-500');
this.classList.remove('border-red-500');
}
});
input.addEventListener('input', function() {
if (this.classList.contains('border-red-500') && this.value.trim() !== '') {
this.classList.remove('border-red-500');
this.classList.add('border-green-500');
}
});
});
}
// Initialize validation
validateForm();
// Dark mode detection and persistence
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
window.toggleDarkMode = function() {
if (document.documentElement.classList.contains('dark')) {
document.documentElement.classList.remove('dark');
localStorage.theme = 'light';
} else {
document.documentElement.classList.add('dark');
localStorage.theme = 'dark';
}
}; |