// Mobile Travel Agent Profile - Interactive Features
document.addEventListener('DOMContentLoaded', () => {
// Initialize Lucide icons
if (typeof lucide !== 'undefined') {
lucide.createIcons();
}
// Mobile menu functionality
const mobileMenuBtn = document.querySelector('[onclick="toggleMobileMenu()"]');
const mobileMenu = document.getElementById('mobileMenu');
if (mobileMenuBtn && mobileMenu) {
// Close menu when clicking outside
document.addEventListener('click', (e) => {
if (!mobileMenu.contains(e.target) && !mobileMenuBtn.contains(e.target)) {
mobileMenu.classList.add('hidden');
}
});
// Close menu on resize if open
window.addEventListener('resize', () => {
if (window.innerWidth >= 768) {
mobileMenu.classList.add('hidden');
}
});
}
// Navbar scroll behavior
let lastScroll = 0;
const navbar = document.getElementById('navbar');
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
// Add/remove shadow based on scroll
if (currentScroll > 50) {
navbar.classList.add('shadow-md');
} else {
navbar.classList.remove('shadow-md');
}
// Hide/show navbar on scroll (optional enhancement)
if (currentScroll > lastScroll && currentScroll > 100) {
navbar.style.transform = 'translateY(-100%)';
} else {
navbar.style.transform = 'translateY(0)';
}
navbar.style.transition = 'transform 0.3s ease-in-out';
lastScroll = currentScroll;
});
// Intersection Observer for scroll animations
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
const fadeInObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
// Add stagger animation to children if applicable
const staggerContainer = entry.target.querySelector('.stagger-children');
if (staggerContainer) {
staggerContainer.classList.add('animate');
}
fadeInObserver.unobserve(entry.target);
}
});
}, observerOptions);
// Observe elements with animation classes
document.querySelectorAll('.card-hover, .process-step, .testimonial-card').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.6s ease-out, transform 0.6s ease-out';
fadeInObserver.observe(el);
});
// Form handling
const contactForm = document.getElementById('contactForm');
if (contactForm) {
contactForm.addEventListener('submit', handleFormSubmit);
}
// Destination select enhancement
const destinationSelect = document.querySelector('select');
if (destinationSelect) {
destinationSelect.addEventListener('change', function() {
if (this.value && this.value !== 'Select a destination type') {
this.classList.add('text-gray-900');
}
});
}
// Smooth scroll polyfill for older browsers
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
const headerOffset = 80;
const elementPosition = targetElement.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
// Close mobile menu if open
if (mobileMenu && !mobileMenu.classList.contains('hidden')) {
mobileMenu.classList.add('hidden');
}
}
});
});
// Lazy loading for images (if any are added dynamically)
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
if (img.dataset.src) {
img.src = img.dataset.src;
img.removeAttribute('data-src');
img.addEventListener('load', () => {
img.style.opacity = '1';
});
}
observer.unobserve(img);
}
});
});
document.querySelectorAll('img[data-src]').forEach(img => {
img.style.opacity = '0';
img.style.transition = 'opacity 0.3s';
imageObserver.observe(img);
});
// Active navigation highlighting
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('nav a[href^="#"]');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (pageYOffset >= sectionTop - 200) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('text-primary');
link.classList.add('text-gray-600');
if (link.getAttribute('href') === `#${current}`) {
link.classList.remove('text-gray-600');
link.classList.add('text-primary');
}
});
});
// Testimonial slider (if more testimonials are added)
let currentTestimonial = 0;
const testimonials = document.querySelectorAll('.testimonial-card');
if (testimonials.length > 3) {
setInterval(() => {
testimonials.forEach((t, index) => {
if (index === currentTestimonial) {
t.style.transform = 'scale(1.05)';
t.style.opacity = '1';
} else {
t.style.transform = 'scale(1)';
t.style.opacity = '0.7';
}
});
currentTestimonial = (currentTestimonial + 1) % testimonials.length;
}, 5000);
}
console.log('Mobile Travel Agent Profile loaded successfully');
});
// Form submission handler
function handleFormSubmit(e) {
e.preventDefault();
const form = e.target;
const submitBtn = form.querySelector('button[type="submit"]');
const originalText = submitBtn.innerHTML;
// Simulate form submission
submitBtn.disabled = true;
submitBtn.innerHTML = 'Sending...';
setTimeout(() => {
// Success state
submitBtn.classList.remove('bg-primary', 'hover:bg-teal-700');
submitBtn.classList.add('bg-green-600');
submitBtn.innerHTML = 'Message Sent!';
if (typeof lucide !== 'undefined') {
lucide.createIcons();
}
// Reset form after delay
setTimeout(() => {
form.reset();
submitBtn.disabled = false;
submitBtn.classList.remove('bg-green-600');
submitBtn.classList.add('bg-primary', 'hover:bg-teal-700');
submitBtn.innerHTML = originalText;
if (typeof lucide !== 'undefined') {
lucide.createIcons();
}
}, 3000);
}, 1500);
}
// Utility function for debouncing
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Handle window resize with debounce
const handleResize = debounce(() => {
// Recalculate any necessary layouts
console.log('Window resized, layouts adjusted');
}, 250);
window.addEventListener('resize', handleResize);