summaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorAdam Carpenter <atc@53hor.net>2020-03-19 21:08:44 -0400
committerAdam Carpenter <atc@53hor.net>2020-03-19 21:08:44 -0400
commit7cba160564448a520c14a098ce4dd30c4bc2f06c (patch)
treec6b797032b27577d22668da5763b1372a173ad00 /src/js
parentd318994d1e8684db3874c6987ed5e4cc3be66b2b (diff)
downloadcarpentertutoring-7cba160564448a520c14a098ce4dd30c4bc2f06c.tar.xz
carpentertutoring-7cba160564448a520c14a098ce4dd30c4bc2f06c.zip
cleaned up js
Diffstat (limited to 'src/js')
-rw-r--r--src/js/index.js50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/js/index.js b/src/js/index.js
index 21adad5..0697b51 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -1,12 +1,9 @@
-
/*
* Adds an event listener to all burgers to toggle navbar menu on click.
*/
document.addEventListener('DOMContentLoaded', function () {
- // get all navbar-burger elements
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
- // check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
// add a click event on each of them
$navbarBurgers.forEach(function(el) {
@@ -23,11 +20,34 @@ document.addEventListener('DOMContentLoaded', function () {
}
});
-document.forms.inquiry.onsubmit = function() {
+const disableErrorBox = function() {
+ document.getElementById("errorBox").style.display = "none";
+}
+
+const disableSuccessBox = function() {
+ document.getElementById("successBox").style.display = "none";
+}
+
+const enableErrorBox = function(message) {
let errorBox = document.getElementById("errorBox");
- let successBox = document.getElementById("successBox");
- errorBox.style.display = "none";
- successBox.style.display = "none";
+ let aTag = document.createElement('a');
+ aTag.setAttribute("href", "mailto:amy@carpentertutoring.com");
+ aTag.innerText = message + " Click here to send through your mail client.";
+ while (errorBox.hasChildNodes()) { errorBox.removeChild(errorBox.lastChild); }
+ errorBox.appendChild(aTag);
+ errorBox.style.display = "block";
+}
+
+const enableSuccessBox = function() {
+ document.getElementById("successBox").style.display = "block";
+}
+
+/*
+ * Adds mail sender to form submit.
+ */
+document.forms.inquiry.onsubmit = function() {
+ disableErrorBox();
+ disableSuccessBox();
let form = document.forms.inquiry;
let name = form.elements.name.value;
let fromEmail = form.elements.from.value;
@@ -40,20 +60,12 @@ document.forms.inquiry.onsubmit = function() {
Subject : "Inquiry: " + name,
Body : body,
}).then( message => {
- if (message != "OK") {
- let link = "<a href=mailto:amy@carpentertutoring> Click here to send through your mail client.</a>"
- let aTag = document.createElement('a');
- aTag.setAttribute("href", "mailto:amy@carpentertutoring.com");
- aTag.innerText = message + " Click here to send through your mail client.";
- while (errorBox.hasChildNodes()) {
- errorBox.removeChild(errorBox.lastChild);
- }
- errorBox.appendChild(aTag);
- errorBox.style.display = "block";
+ if (message == "OK") {
+ form.reset();
+ enableSuccessBox();
}
else {
- form.reset();
- successBox.style.display = "block";
+ enableErrorBox(message);
}
}
);