Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
149 lines (125 loc) · 4.9 KB
/
Copy pathscript.js
File metadata and controls
149 lines (125 loc) · 4.9 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
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
/**
* RMB Arkansas Central — script.js
* Mobile navigation · Accordion reasons · Form handling (Web3Forms)
*/
(function () {
'use strict';
/* ══════════════════════════════════
MOBILE NAV TOGGLE
══════════════════════════════════ */
var toggle = document.getElementById('nav-toggle');
var menu = document.getElementById('nav-menu');
if (toggle && menu) {
toggle.addEventListener('click', function () {
var isOpen = menu.classList.toggle('open');
toggle.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
});
// Close nav when a link is clicked (mobile)
menu.querySelectorAll('a').forEach(function (link) {
link.addEventListener('click', function () {
menu.classList.remove('open');
toggle.setAttribute('aria-expanded', 'false');
});
});
// Close on outside click
document.addEventListener('click', function (e) {
if (!menu.contains(e.target) && !toggle.contains(e.target)) {
menu.classList.remove('open');
toggle.setAttribute('aria-expanded', 'false');
}
});
}
/* ══════════════════════════════════
WHY JOIN ACCORDION
══════════════════════════════════ */
var reasonHeaders = document.querySelectorAll('.reason-header');
reasonHeaders.forEach(function (header) {
header.addEventListener('click', function () {
var item = header.closest('.reason-item');
var isOpen = item.classList.contains('open');
// Close all
document.querySelectorAll('.reason-item').forEach(function (ri) {
ri.classList.remove('open');
var h = ri.querySelector('.reason-header');
if (h) h.setAttribute('aria-expanded', 'false');
});
// Toggle clicked
if (!isOpen) {
item.classList.add('open');
header.setAttribute('aria-expanded', 'true');
}
});
// Keyboard accessibility
header.addEventListener('keydown', function (e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
header.click();
}
});
});
/* ══════════════════════════════════
CONTACT FORM — Web3Forms
══════════════════════════════════ */
var form = document.getElementById('inquiry-form');
var successEl = document.getElementById('form-success');
var errorEl = document.getElementById('form-error');
var submitBtn = document.getElementById('submit-btn');
if (form) {
form.addEventListener('submit', async function (e) {
e.preventDefault();
// Client-side validation: highlight empty required fields
var fields = form.querySelectorAll('[required]');
var valid = true;
fields.forEach(function (f) {
f.style.borderColor = '';
if (!f.value.trim()) {
f.style.borderColor = '#FC8181';
valid = false;
}
});
if (!valid) {
var firstEmpty = form.querySelector('[required]');
if (firstEmpty && !firstEmpty.value.trim()) firstEmpty.focus();
return;
}
// Email format check
var emailField = form.querySelector('#email');
if (emailField && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(emailField.value)) {
emailField.style.borderColor = '#FC8181';
emailField.focus();
return;
}
// Disable button during submission
var originalText = submitBtn ? submitBtn.textContent : 'Request Information';
if (submitBtn) {
submitBtn.disabled = true;
submitBtn.textContent = 'Sending\u2026';
}
// Hide any previous error
if (errorEl) errorEl.style.display = 'none';
try {
var formData = new FormData(form);
var response = await fetch('https://api.web3forms.com/submit', {
method: 'POST',
body: formData
});
var data = await response.json();
if (data.success) {
// Hide all form fields and show success message
form.querySelectorAll('.form-group, .form-submit').forEach(function (el) {
el.style.display = 'none';
});
if (successEl) successEl.style.display = 'block';
} else {
throw new Error(data.message || 'Submission failed');
}
} catch (err) {
if (errorEl) errorEl.style.display = 'block';
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.textContent = originalText;
}
}
});
}
})();