| 1 |
function submitNotify(e) { |
| 2 |
e.preventDefault(); |
| 3 |
var form = document.getElementById('notify-form'); |
| 4 |
var status = document.getElementById('notify-status'); |
| 5 |
var email = form.querySelector('input[name="email"]').value; |
| 6 |
var btn = form.querySelector('button'); |
| 7 |
btn.disabled = true; |
| 8 |
btn.textContent = 'Sending...'; |
| 9 |
status.textContent = ''; |
| 10 |
fetch('/api/email-signup', { |
| 11 |
method: 'POST', |
| 12 |
headers: {'Content-Type': 'application/json'}, |
| 13 |
body: JSON.stringify({email: email}) |
| 14 |
}).then(function(r) { |
| 15 |
if (r.ok) { |
| 16 |
status.textContent = 'You\'re on the list.'; |
| 17 |
status.className = 'notify-status success'; |
| 18 |
form.querySelector('input[name="email"]').value = ''; |
| 19 |
} else { |
| 20 |
return r.json().then(function(d) { throw new Error(d.error || 'Something went wrong'); }); |
| 21 |
} |
| 22 |
}).catch(function(err) { |
| 23 |
status.textContent = err.message; |
| 24 |
status.className = 'notify-status error'; |
| 25 |
}).finally(function() { |
| 26 |
btn.disabled = false; |
| 27 |
btn.textContent = 'Notify Me'; |
| 28 |
}); |
| 29 |
return false; |
| 30 |
} |
| 31 |
|