-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (63 loc) · 2.26 KB
/
index.js
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
const emailField = document.getElementById("emailInput");
const modalTitle = document.getElementById("modalTitle");
const modalBody = document.getElementById("modalBody");
const modalEmail = document.getElementById("modalEmail");
function submitEmail() {
// Get email from form
var email = emailField.value;
if (email.match(/.+\@.+\..+/g) != null) {
// Hide warning div
$('#emailWarning').attr("hidden", true);
// Show modal div, display waiting
$('#loadingIcon').removeAttr("hidden");
modalTitle.innerHTML = "Please Wait";
modalBody.innerHTML = modalEmail.value = "";
$('#myModal').modal('show');
// Send email address to mailing list endpoint
var urlstring = "https://nextjs.ucsbieee.org/api/mailing-list/add";
var settings = {
"async": true,
"crossDomain": true,
"url": urlstring,
"method": "POST",
"data": {
email: email
}
};
$.ajax(settings).done(function (response) {
console.log(response);
if (response.success) {
// Valid, show success screen
$('#loadingIcon').attr("hidden", true);
modalTitle.innerHTML = "Success!";
modalBody.innerHTML = "Success! We will add you to the mailing list shortly!";
modalEmail.innerHTML = "Email: " + response.email;
emailField.value = "";
setTimeout(function () {
$('#myModal').modal('hide');
}, 5000);
}
});
} else {
// Show warning div
$('#emailWarning').removeAttr("hidden");
}
}
function appendDomain(domain) {
// Get email from form
var email = emailField.value;
// Get part before @ symbol
var emailPrefix = email.substr(0, email.indexOf('@'));
if (emailPrefix == "") {
// There was no @ symbol, just append the email domain
var newEmail = email + "@" + domain;
} else {
// There was an @ symbol, append email domain to emailPrefix
var newEmail = emailPrefix + "@" + domain;
}
emailField.value = newEmail;
}
function clearEmail() {
emailField.value = "";
emailField.focus();
}