Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
72 lines (68 loc) · 2.4 KB
/
Copy pathscript.js
File metadata and controls
72 lines (68 loc) · 2.4 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
(function () {
var btn = document.getElementById('menuBtn');
var nav = document.getElementById('nav');
btn.addEventListener('click', function () {
var open = nav.classList.toggle('open');
btn.setAttribute('aria-expanded', open);
});
nav.addEventListener('click', function (e) {
if (e.target.tagName === 'A') {
nav.classList.remove('open');
btn.setAttribute('aria-expanded', 'false');
}
});
var chips = document.querySelectorAll('.chip');
var cards = document.querySelectorAll('.card[data-skills]');
var open = document.querySelector('.card.open');
var empty = document.getElementById('empty');
chips.forEach(function (chip) {
chip.addEventListener('click', function () {
var f = chip.dataset.filter, shown = 0;
chips.forEach(function (c) {
var on = c === chip;
c.classList.toggle('on', on);
c.setAttribute('aria-pressed', on);
});
cards.forEach(function (card) {
var match = f === 'all' || card.dataset.skills.split(' ').indexOf(f) > -1;
card.hidden = !match;
if (match) shown++;
});
open.hidden = f !== 'all';
empty.hidden = shown > 0;
});
});
document.getElementById('yr').textContent = new Date().getFullYear();
var WORKER_URL = 'https://testers.devtem.org/api/v1/';
var form = document.getElementById('reqForm');
var rbtn = document.getElementById('reqBtn');
var status = document.getElementById('reqStatus');
form.addEventListener('submit', function (e) {
e.preventDefault();
status.className = 'status';
if (!form.checkValidity()) { form.reportValidity(); return; }
var data = {};
new FormData(form).forEach(function (v, k) { data[k] = v; });
data.authorised = form.elements.authorised.checked;
rbtn.disabled = true;
status.textContent = 'Sending...';
fetch(WORKER_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
}).then(function (r) {
return r.json().catch(function () { return {}; }).then(function (body) {
if (!r.ok) {
console.error('Form failed:', r.status, body);
throw new Error(body.error || 'HTTP ' + r.status);
}
window.location.href = '/thanks.html';
});
}).catch(function (error) {
rbtn.disabled = false;
status.className = 'status err';
status.textContent = 'Could not send (' + error.message + '). Try again.';
console.error(error);
});
});
})();