File size: 4,186 Bytes
35daaf1 3d84f48 35daaf1 761fbc1 3d84f48 761fbc1 3d84f48 35daaf1 3d84f48 761fbc1 | 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 | // Initialize service worker for PWA functionality
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js').then(registration => {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(err => {
console.log('ServiceWorker registration failed: ', err);
});
});
}
// Handle location permission request
document.addEventListener('DOMContentLoaded', () => {
const locationBtn = document.getElementById('get-location');
if (locationBtn) {
locationBtn.addEventListener('click', () => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
position => {
console.log('Position:', position);
// In a real app, you would send this to your backend
},
error => {
console.error('Error getting location:', error);
alert('Could not get your location. Please enable location services or enter it manually.');
},
{ enableHighAccuracy: true, timeout: 10000, maximumAge: 0 }
);
} else {
alert('Geolocation is not supported by your browser.');
}
});
}
});
// Mock API calls for demo purposes
async function fetchServices() {
try {
// In a real app, this would be a fetch to your backend API
const mockServices = [
{ id: 1, name: 'Towing', icon: 'truck', description: 'Vehicle towing services' },
{ id: 2, name: 'Mechanic', icon: 'tool', description: 'On-site mechanic assistance' },
{ id: 3, name: 'Jump Start', icon: 'battery', description: 'Battery jump start service' },
{ id: 4, name: 'Fuel Delivery', icon: 'droplet', description: 'Emergency fuel delivery' }
];
return mockServices;
} catch (error) {
console.error('Error fetching services:', error);
return [];
}
}
// Parallax effect
function setupParallax() {
const hero = document.querySelector('.hero-section');
if (hero) {
window.addEventListener('scroll', () => {
const scrollPosition = window.pageYOffset;
hero.style.backgroundPositionY = scrollPosition * 0.5 + 'px';
});
}
}
// Animate services on scroll
function animateServices() {
const servicesGrid = document.getElementById('services-grid');
if (servicesGrid) {
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
entry.target.style.opacity = 1;
entry.target.style.transform = 'translateY(0)';
}
});
}, { threshold: 0.1 });
const cards = servicesGrid.children;
Array.from(cards).forEach((card, index) => {
card.style.opacity = 0;
card.style.transform = 'translateY(20px)';
card.style.transition = `all 0.5s ease ${index * 0.1}s`;
observer.observe(card);
});
}
}
// Initialize the app
document.addEventListener('DOMContentLoaded', async () => {
console.log('MYUG App initialized');
setupParallax();
animateServices();
initImageSlider();
// Load services
const services = await fetchServices();
console.log('Services loaded:', services);
// Add futuristic hover effects to all cards
document.querySelectorAll('.service-card').forEach(card => {
card.classList.add('futuristic-card');
});
});
function initImageSlider() {
const sliders = document.querySelectorAll('.image-slider');
sliders.forEach((slider, index) => {
const images = slider.querySelectorAll('img');
let current = 0;
setInterval(() => {
images[current].style.opacity = 0;
current = (current + 1) % images.length;
images[current].style.opacity = 1;
}, 5000);
});
}
|