|
1 | | -// Contact page: topic pills and the client-side "message sent" state. |
2 | | -// The form is not wired to a backend yet, so submit only swaps the panels. |
3 | 1 | (function () { |
4 | 2 | var form = document.querySelector('[data-contact-form]'); |
5 | 3 | if (!form) { |
|
8 | 6 |
|
9 | 7 | var topicInput = form.querySelector('[data-contact-topic]'); |
10 | 8 | var pills = form.querySelectorAll('[data-topic]'); |
11 | | - var sent = document.querySelector('[data-contact-sent]'); |
12 | | - var sentTopic = sent.querySelector('[data-contact-sent-topic]'); |
13 | | - var reset = sent.querySelector('[data-contact-reset]'); |
14 | | - |
15 | | - function currentPill() { |
16 | | - return form.querySelector('[data-topic][aria-pressed="true"]'); |
17 | | - } |
18 | | - |
19 | | - function selectTopic(id) { |
20 | | - pills.forEach(function (pill) { |
21 | | - pill.setAttribute('aria-pressed', String(pill.getAttribute('data-topic') === id)); |
22 | | - }); |
23 | | - topicInput.value = id; |
24 | | - } |
25 | 9 |
|
26 | 10 | pills.forEach(function (pill) { |
27 | 11 | pill.addEventListener('click', function () { |
28 | | - selectTopic(pill.getAttribute('data-topic')); |
| 12 | + var id = pill.getAttribute('data-topic'); |
| 13 | + pills.forEach(function (other) { |
| 14 | + other.setAttribute('aria-pressed', String(other === pill)); |
| 15 | + }); |
| 16 | + topicInput.value = id; |
29 | 17 | }); |
30 | 18 | }); |
31 | | - |
32 | | - form.addEventListener('submit', function (event) { |
33 | | - event.preventDefault(); |
34 | | - var pill = currentPill(); |
35 | | - sentTopic.textContent = pill ? pill.textContent : ''; |
36 | | - form.hidden = true; |
37 | | - sent.hidden = false; |
38 | | - sent.querySelector('h2').focus({ preventScroll: true }); |
39 | | - }); |
40 | | - |
41 | | - reset.addEventListener('click', function () { |
42 | | - form.reset(); |
43 | | - selectTopic(pills[0].getAttribute('data-topic')); |
44 | | - sent.hidden = true; |
45 | | - form.hidden = false; |
46 | | - form.querySelector('input:not([type="hidden"])').focus(); |
47 | | - }); |
48 | 19 | })(); |
0 commit comments