File size: 3,444 Bytes
7af1d37 |
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 |
document.addEventListener('DOMContentLoaded', function() {
// Initialize tooltips
const tooltipTriggers = document.querySelectorAll('[data-tooltip]');
tooltipTriggers.forEach(trigger => {
const tooltip = document.createElement('div');
tooltip.className = 'hidden bg-gray-800 text-white text-xs rounded py-1 px-2 absolute z-50';
tooltip.textContent = trigger.getAttribute('data-tooltip');
document.body.appendChild(tooltip);
trigger.addEventListener('mouseenter', () => {
const rect = trigger.getBoundingClientRect();
tooltip.style.top = `${rect.top - 30}px`;
tooltip.style.left = `${rect.left + rect.width / 2}px`;
tooltip.style.transform = 'translateX(-50%)';
tooltip.classList.remove('hidden');
});
trigger.addEventListener('mouseleave', () => {
tooltip.classList.add('hidden');
});
});
// Mock visitor counter animation
const visitorCounter = document.getElementById('visitor-counter');
if (visitorCounter) {
let count = Math.floor(Math.random() * 100) + 50;
setInterval(() => {
count += Math.floor(Math.random() * 3) - 1;
visitorCounter.textContent = count.toLocaleString() + ' Active Visitors';
}, 5000);
}
// Form submission handling
const forms = document.querySelectorAll('form');
forms.forEach(form => {
form.addEventListener('submit', function(e) {
e.preventDefault();
const submitButton = form.querySelector('button[type="submit"]');
if (submitButton) {
const originalText = submitButton.textContent;
submitButton.innerHTML = '<i data-feather="loader" class="animate-spin mr-2 w-4 h-4"></i> Processing...';
feather.replace();
// Simulate API call
setTimeout(() => {
submitButton.textContent = originalText;
// Show success message
alert('Form submitted successfully!');
}, 1500);
}
});
});
// Mobile menu toggle (if exists)
const mobileMenuButton = document.getElementById('mobile-menu-button');
const mobileMenu = document.getElementById('mobile-menu');
if (mobileMenuButton && mobileMenu) {
mobileMenuButton.addEventListener('click', () => {
mobileMenu.classList.toggle('hidden');
});
}
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Initialize all feather icons
feather.replace();
});
// Debounce function for resize/scroll events
function debounce(func, wait = 20, immediate = true) {
let timeout;
return function() {
const context = this, args = arguments;
const later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
} |