/** * Phone Store — клиентский JavaScript * Интерактивные элементы интерфейса */ document.addEventListener('DOMContentLoaded', function () { // Автоматическое скрытие flash-сообщений через 4 секунды const flashes = document.querySelectorAll('.flash'); flashes.forEach(function (flash) { setTimeout(function () { flash.style.transition = 'opacity 0.4s ease, transform 0.4s ease'; flash.style.opacity = '0'; flash.style.transform = 'translateX(30px)'; setTimeout(function () { flash.remove(); }, 400); }, 4000); }); // Подтверждение очистки корзины const clearForms = document.querySelectorAll('form[action*="clear_cart"]'); clearForms.forEach(function (form) { form.addEventListener('submit', function (e) { if (!confirm('Вы уверены, что хотите очистить корзину?')) { e.preventDefault(); } }); }); // Валидация формы оформления заказа на клиенте const checkoutForm = document.getElementById('checkout-form'); if (checkoutForm) { checkoutForm.addEventListener('submit', function (e) { const name = document.getElementById('name').value.trim(); const phone = document.getElementById('phone').value.trim(); const address = document.getElementById('address').value.trim(); let errors = []; if (name.length < 2) { errors.push('Имя должно содержать не менее 2 символов'); } if (phone.length < 10) { errors.push('Введите корректный номер телефона'); } if (address.length < 5) { errors.push('Адрес должен содержать не менее 5 символов'); } if (errors.length > 0) { e.preventDefault(); alert(errors.join('\n')); } }); } // Плавное появление карточек товаров const cards = document.querySelectorAll('.product-card'); if (cards.length > 0 && 'IntersectionObserver' in window) { const observer = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (entry.isIntersecting) { entry.target.style.opacity = '1'; entry.target.style.transform = 'translateY(0)'; observer.unobserve(entry.target); } }); }, { threshold: 0.1 }); cards.forEach(function (card, index) { card.style.opacity = '0'; card.style.transform = 'translateY(20px)'; card.style.transition = 'opacity 0.4s ease ' + (index * 0.05) + 's, transform 0.4s ease ' + (index * 0.05) + 's'; observer.observe(card); }); } });