Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
112 lines (98 loc) · 3.48 KB
/
Copy pathscript.js
File metadata and controls
112 lines (98 loc) · 3.48 KB
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
/* ============================================
MicroPropPlants.com - Main Script
============================================ */
(function () {
'use strict';
/* --- Mobile Navigation --- */
const hamburger = document.getElementById('hamburger');
const mobileNav = document.getElementById('mobile-nav');
if (hamburger && mobileNav) {
hamburger.addEventListener('click', function () {
const isOpen = mobileNav.classList.toggle('open');
hamburger.setAttribute('aria-expanded', String(isOpen));
});
// Close on mobile link click
mobileNav.querySelectorAll('a').forEach(function (link) {
link.addEventListener('click', function () {
mobileNav.classList.remove('open');
hamburger.setAttribute('aria-expanded', 'false');
});
});
}
/* --- Contact Form --- */
const contactForm = document.getElementById('contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function (e) {
e.preventDefault();
// Custom validation
var isValid = true;
contactForm.querySelectorAll('[required]').forEach(function (field) {
field.classList.remove('field-error');
if (!field.value.trim()) {
field.classList.add('field-error');
isValid = false;
}
});
// Basic email format check
var emailField = contactForm.querySelector('input[type="email"]');
if (emailField && emailField.value.trim()) {
var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(emailField.value.trim())) {
emailField.classList.add('field-error');
isValid = false;
}
}
if (!isValid) {
var firstError = contactForm.querySelector('.field-error');
if (firstError) { firstError.focus(); }
return;
}
var btn = contactForm.querySelector('.form-submit');
btn.textContent = 'Sending…';
btn.disabled = true;
// Simulate form submission (replace with real endpoint as needed)
setTimeout(function () {
contactForm.innerHTML =
'<div class="form-success">' +
'<div class="form-success-icon">✅</div>' +
'<h3 class="form-success-heading">Message Received!</h3>' +
'<p>Thank you for reaching out. We\'ll get back to you within 1–2 business days.</p>' +
'</div>';
}, 1000);
});
}
/* --- Smooth scroll for hash links not handled by CSS --- */
document.querySelectorAll('a[href^="#"]').forEach(function (anchor) {
anchor.addEventListener('click', function (e) {
var hash = this.getAttribute('href');
var target;
try {
target = document.querySelector(hash);
} catch (_) {
return;
}
if (target) {
e.preventDefault();
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});
});
/* --- Intersection Observer for fade-in animations --- */
if ('IntersectionObserver' in window) {
const observer = new IntersectionObserver(
function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.1, rootMargin: '0px 0px -40px 0px' }
);
document.querySelectorAll('.product-card, .step-card, .feature-card, .about-icon-card').forEach(function (el) {
el.classList.add('fade-in');
observer.observe(el);
});
}
})();