File Manager
Editing: script.js
// Mobile Navigation Toggle const hamburger = document.getElementById('hamburger'); const navMenu = document.getElementById('navMenu'); hamburger.addEventListener('click', () => { hamburger.classList.toggle('active'); navMenu.classList.toggle('active'); }); // Close mobile menu when clicking on a link document.querySelectorAll('.nav-menu a').forEach(link => { link.addEventListener('click', () => { hamburger.classList.remove('active'); navMenu.classList.remove('active'); }); }); // Form Validation function validateContactForm() { const form = document.getElementById('contactForm'); if (!form) return true; const name = document.getElementById('name'); const email = document.getElementById('email'); const message = document.getElementById('message'); let isValid = true; // Reset errors document.querySelectorAll('.error').forEach(el => el.remove()); document.querySelectorAll('.form-group input, .form-group textarea').forEach(el => { el.style.borderColor = '#e2e8f0'; }); // Name validation if (!name.value.trim()) { showError(name, 'Name is required'); isValid = false; } // Email validation if (!email.value.trim()) { showError(email, 'Email is required'); isValid = false; } else if (!isValidEmail(email.value)) { showError(email, 'Please enter a valid email'); isValid = false; } // Message validation if (!message.value.trim()) { showError(message, 'Message is required'); isValid = false; } if (isValid) { // Form submission would go here alert('Thank you for your message! We will get back to you soon.'); form.reset(); } return false; // Prevent actual form submission for demo } function showError(input, message) { const formGroup = input.parentElement; input.style.borderColor = '#ef4444'; const error = document.createElement('div'); error.className = 'error'; error.style.color = '#ef4444'; error.style.fontSize = '0.875rem'; error.style.marginTop = '0.25rem'; error.textContent = message; formGroup.appendChild(error); } function isValidEmail(email) { const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; return re.test(email); } // Smooth scrolling for 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 - 100, behavior: 'smooth' }); } }); }); // Product filtering/sorting (can be extended based on needs) function filterProducts(category) { const products = document.querySelectorAll('.product-card'); products.forEach(product => { if (category === 'all' || product.dataset.category === category) { product.style.display = 'block'; } else { product.style.display = 'none'; } }); } // Initialize any page-specific functionality document.addEventListener('DOMContentLoaded', function() { // Add any initialization code here // Contact form submission const contactForm = document.getElementById('contactForm'); if (contactForm) { contactForm.onsubmit = validateContactForm; } // Add loading state to buttons document.querySelectorAll('.btn').forEach(button => { button.addEventListener('click', function() { if (this.type === 'submit' || this.classList.contains('submit-btn')) { this.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Processing...'; this.disabled = true; // Re-enable after 2 seconds for demo setTimeout(() => { this.innerHTML = 'Submit'; this.disabled = false; }, 2000); } }); }); });
💾 Save
⬅ Back