1/** 2 * B2B Enterprises - Main JavaScript 3 */ 4 5// Initialize Materialize components when document is ready 6document.addEventListener('DOMContentLoaded', function() { 7 // Initialize sidenav 8 var elems = document.querySelectorAll('.sidenav'); 9 var instances = M.Sidenav.init(elems); 10 11 // Initialize dropdown menus 12 var dropdowns = document.querySelectorAll('.dropdown-trigger'); 13 var options = { 14 coverTrigger: false, 15 constrainWidth: false 16 }; 17 var instances = M.Dropdown.init(dropdowns, options); 18 19 // Initialize collapsible elements 20 var collapsibles = document.querySelectorAll('.collapsible'); 21 var instances = M.Collapsible.init(collapsibles); 22 23 // Initialize modals 24 var modals = document.querySelectorAll('.modal'); 25 var instances = M.Modal.init(modals); 26 27 // Initialize tooltips 28 var tooltips = document.querySelectorAll('.tooltipped'); 29 var instances = M.Tooltip.init(tooltips); 30 31 // Initialize form selects 32 var selects = document.querySelectorAll('select'); 33 var instances = M.FormSelect.init(selects); 34 35 // Initialize tabs 36 var tabs = document.querySelectorAll('.tabs'); 37 var instance = M.Tabs.init(tabs); 38 39 // Initialize carousels/sliders if used 40 var carousels = document.querySelectorAll('.carousel'); 41 var options = { 42 fullWidth: true, 43 indicators: true 44 }; 45 var instances = M.Carousel.init(carousels, options); 46 47 // Back to top button functionality 48 const backToTopButton = document.querySelector('.back-to-top'); 49 50 if (backToTopButton) { 51 // Show/hide back to top button based on scroll position 52 window.addEventListener('scroll', function() { 53 if (window.pageYOffset > 300) { 54 backToTopButton.classList.add('show'); 55 } else { 56 backToTopButton.classList.remove('show'); 57 } 58 }); 59 60 // Smooth scroll to top when button is clicked 61 backToTopButton.addEventListener('click', function(e) { 62 e.preventDefault(); 63 window.scrollTo({ 64 top: 0, 65 behavior: 'smooth' 66 }); 67 }); 68 } 69}); 70 71// Smooth scrolling for anchor links 72document.querySelectorAll('a[href^="#"]').forEach(anchor => { 73 anchor.addEventListener('click', function(e) { 74 if (this.getAttribute('href') !== '#!' && this.getAttribute('href') !== '#') { 75 e.preventDefault(); 76 77 const target = document.querySelector(this.getAttribute('href')); 78 if (target) { 79 target.scrollIntoView({ 80 behavior: 'smooth' 81 }); 82 } 83 } 84 }); 85}); 86 87// Form validation for contact form 88function validateContactForm() { 89 const nameField = document.getElementById('name'); 90 const emailField = document.getElementById('email'); 91 const phoneField = document.getElementById('phone'); 92 const messageField = document.getElementById('message'); 93 let isValid = true; 94 95 // Reset error messages 96 document.querySelectorAll('.error-message').forEach(element => { 97 element.textContent = ''; 98 }); 99 100 // Validate name 101 if (!nameField.value.trim()) { 102 document.getElementById('name-error').textContent = 'Please enter your name'; 103 isValid = false; 104 } 105 106 // Validate email 107 const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 108 if (!emailPattern.test(emailField.value.trim())) { 109 document.getElementById('email-error').textContent = 'Please enter a valid email address'; 110 isValid = false; 111 } 112 113 // Validate phone (optional but if provided, must be valid) 114 if (phoneField.value.trim()) { 115 const phonePattern = /^[\d\s\+\-\(\)]{8,20}$/; 116 if (!phonePattern.test(phoneField.value.trim())) { 117 document.getElementById('phone-error').textContent = 'Please enter a valid phone number'; 118 isValid = false; 119 } 120 } 121 122 // Validate message 123 if (!messageField.value.trim() || messageField.value.trim().length < 10) { 124 document.getElementById('message-error').textContent = 'Please enter a message (at least 10 characters)'; 125 isValid = false; 126 } 127 128 return isValid; 129} 130 131// Add form validation event listener if the contact form exists 132const contactForm = document.getElementById('contact-form'); 133if (contactForm) { 134 contactForm.addEventListener('submit', function(e) { 135 if (!validateContactForm()) { 136 e.preventDefault(); 137 } 138 }); 139}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.