Spaces:
Running
Running
File size: 12,192 Bytes
296e4a0 | 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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | // Main JavaScript for MileTruck Project
document.addEventListener('DOMContentLoaded', function() {
// Initialize components
initializeStatsCounter();
initializeFleetGallery();
initializePartnerLogos();
initializeFleetNavigation();
// Add smooth scroll to 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) {
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: 'smooth'
});
}
});
});
});
// Stats Counter Animation
function initializeStatsCounter() {
const statElements = document.querySelectorAll('.stat-counter');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const element = entry.target;
const target = parseFloat(element.getAttribute('data-target'));
const suffix = element.textContent.includes('مليون') ? ' مليون' :
element.textContent.includes('مليار') ? ' مليار' :
element.textContent.includes(' ألف') ? ' ألف' : '';
let start = 0;
const duration = 2000; // 2 seconds
const increment = target / (duration / 16); // 60fps
const timer = setInterval(() => {
start += increment;
if (start >= target) {
element.textContent = formatNumber(target) + suffix;
clearInterval(timer);
} else {
element.textContent = formatNumber(Math.floor(start)) + suffix;
}
}, 16);
observer.unobserve(element);
}
});
}, { threshold: 0.5 });
statElements.forEach(el => observer.observe(el));
}
function formatNumber(num) {
if (num >= 1000000) {
return (num / 1000000).toFixed(1).replace('.0', '');
}
return num.toLocaleString('en-US');
}
// Fleet Gallery Initialization
function initializeFleetGallery() {
const fleetData = [
{
category: 'traila',
type: 'تريلا',
name: 'تريلا سطحة محورين',
image: 'https://www.shahen-sa.com/assets/images/home/truck-images/traila/flatbed-trailer-2axles.webp',
length: 'طول المقطورة حتى 13.5 متر',
capacity: 'حمولة قصوى 25 طن'
},
{
category: 'traila',
type: 'تريلا',
name: 'تريلا سطحة ثلاث محاور',
image: 'https://www.shahen-sa.com/assets/images/home/truck-images/traila/flatbed-trailer-3axles.webp',
length: 'طول المقطورة حتى 13.5 متر',
capacity: 'حمولة قصوى 30 طن'
},
{
category: 'traila',
type: 'تريلا',
name: 'تريلا ستارة',
image: 'https://www.shahen-sa.com/assets/images/home/truck-images/traila/curtain-trailer.webp',
length: 'طول المقطورة حتى 13.5 متر',
capacity: 'حمولة قصوى 25 طن'
},
{
category: 'traila',
type: 'تريلا',
name: 'تريلا جوانب عالية',
image: 'https://www.shahen-sa.com/assets/images/home/truck-images/traila/high-sided-trailer.webp',
length: 'طول المقطورة حتى 15 متر',
capacity: 'حمولة قصوى 20 طن'
},
{
category: 'six',
type: 'سقس',
name: 'سقس جوانب عالية',
image: 'https://www.shahen-sa.com/assets/images/home/truck-images/six/sax-high-sided.webp',
length: 'الطول حتى 8 متر',
capacity: 'حمولة قصوى 13 طن'
},
{
category: 'six',
type: 'سقس',
name: 'سقس ثلاجة',
image: 'https://www.shahen-sa.com/assets/images/home/truck-images/six/sax-refrigerated.webp',
length: 'الطول حتى 8 متر',
capacity: 'حمولة قصوى 10 طن'
},
{
category: 'lorry',
type: 'لوري',
name: 'لوري شبك',
image: 'https://www.shahen-sa.com/assets/images/home/truck-images/lorry/Lorry-Cage-Truck-7M.webp',
length: 'الطول حتى 7.5 متر',
capacity: 'حمولة قصوى 8 طن'
},
{
category: 'lorry',
type: 'لوري',
name: 'لوري جاف (مغلق)',
image: 'https://www.shahen-sa.com/assets/images/home/truck-images/lorry/closed-lorry.webp',
length: 'الطول حتى 6.5 متر',
capacity: 'حمولة قصوى 6 طن'
},
{
category: 'dyna',
type: 'دينا',
name: 'دينا شبك',
image: 'https://www.shahen-sa.com/assets/images/home/truck-images/dyna/open-dyna.webp',
length: 'الطول حتى 6 متر',
capacity: 'حمولة قصوى 4 طن'
},
{
category: 'pickup',
type: 'بكب',
name: 'بكب',
image: 'https://www.shahen-sa.com/assets/images/home/truck-images/pickup/Pickup-Truck.webp',
length: 'الطول حتى 5 متر',
capacity: 'حمولة قصوى 2 طن'
}
];
const container = document.querySelector('.fleet-container');
function renderFleetItems(filter = 'all') {
container.innerHTML = '';
const filteredFleet = filter === 'all'
? fleetData
: fleetData.filter(item => item.category === filter);
filteredFleet.forEach((item, index) => {
const fleetCard = document.createElement('div');
fleetCard.className = `fleet-card bg-white rounded-xl shadow-lg overflow-hidden hover:shadow-xl transition-shadow duration-300`;
fleetCard.style.animationDelay = `${index * 100}ms`;
fleetCard.innerHTML = `
<div class="relative h-48 overflow-hidden">
<img src="${item.image}" alt="${item.name}" class="w-full h-full object-cover hover:scale-110 transition-transform duration-500">
<div class="absolute top-3 right-3 bg-primary text-white px-3 py-1 rounded-full text-sm">
${item.type}
</div>
</div>
<div class="p-6">
<h3 class="text-xl font-semibold mb-2 text-dark">${item.name}</h3>
<div class="space-y-2 text-gray-600">
<div class="flex items-center">
<i data-feather="maximize" class="w-4 h-4 ml-2"></i>
<span>${item.length}</span>
</div>
<div class="flex items-center">
<i data-feather="package" class="w-4 h-4 ml-2"></i>
<span>${item.capacity}</span>
</div>
</div>
<button class="mt-4 w-full bg-gray-100 hover:bg-primary hover:text-white text-primary font-medium py-2 rounded-lg transition-colors duration-300 flex items-center justify-center">
<i data-feather="shopping-cart" class="ml-2"></i>
طلب هذه المركبة
</button>
</div>
`;
container.appendChild(fleetCard);
});
// Re-initialize feather icons for new elements
feather.replace();
}
window.renderFleetItems = renderFleetItems;
renderFleetItems(); // Initial render
}
// Fleet Navigation
function initializeFleetNavigation() {
const categoryButtons = document.querySelectorAll('.fleet-category-btn');
categoryButtons.forEach(button => {
button.addEventListener('click', function() {
// Remove active class from all buttons
categoryButtons.forEach(btn => {
btn.classList.remove('active', 'bg-primary', 'text-white');
btn.classList.add('bg-gray-100', 'hover:bg-gray-200');
});
// Add active class to clicked button
this.classList.add('active', 'bg-primary', 'text-white');
this.classList.remove('bg-gray-100', 'hover:bg-gray-200');
// Filter fleet items
const category = this.getAttribute('data-category');
renderFleetItems(category);
});
});
}
// Partner Logos
function initializePartnerLogos() {
const partnerLogos = [
'Partner (1).png', 'Partner (2).png', 'Partner (3).png', 'Partner (4).png',
'Partner (5).png', 'Partner (6).png', 'Partner (7).png', 'Partner (8).png',
'Partner (9).png', 'Partner (10).png', 'Partner (11).png', 'Partner (12).png',
'Partner (13).png', 'Partner (14).png', 'Partner (15).png', 'Partner (16).png',
'Partner (17).png', 'Partner (18).png', 'Partner (19).png', 'Partner (20).png'
];
const baseUrl = 'https://www.shahen-sa.com/assets/images/home/partnerlogos/';
const container = document.querySelector('.partner-logos-container');
// Create double set for seamless scrolling
for (let i = 0; i < 2; i++) {
partnerLogos.forEach(logo => {
const logoDiv = document.createElement('div');
logoDiv.className = 'partner-logo';
logoDiv.innerHTML = `
<img src="${baseUrl}${logo}" alt="شريك" class="max-w-full max-h-full object-contain">
`;
container.appendChild(logoDiv);
});
}
}
// Form handling for quote request
function handleQuoteRequest(e) {
e.preventDefault();
const formData = {
name: document.getElementById('name').value,
company: document.getElementById('company').value,
email: document.getElementById('email').value,
phone: document.getElementById('phone').value,
service: document.getElementById('service').value,
details: document.getElementById('details').value
};
// In a real application, you would send this to a server
console.log('Quote request submitted:', formData);
// Show success message
alert('تم استلام طلبك بنجاح! سيتصل بك فريقنا خلال 24 ساعة عمل.');
// Reset form
e.target.reset();
}
// Add form submission handler if form exists
document.addEventListener('DOMContentLoaded', function() {
const quoteForm = document.getElementById('quote-form');
if (quoteForm) {
quoteForm.addEventListener('submit', handleQuoteRequest);
}
});
// Mobile menu toggle (for components that might need it)
function toggleMobileMenu() {
const mobileMenu = document.querySelector('.mobile-menu');
if (mobileMenu) {
mobileMenu.classList.toggle('hidden');
}
}
// Lazy loading for images
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.classList.remove('lazy');
imageObserver.unobserve(img);
}
});
});
document.querySelectorAll('img.lazy').forEach(img => imageObserver.observe(img));
} |