diff options
Diffstat (limited to 'src/js/index.js')
-rw-r--r-- | src/js/index.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/js/index.js b/src/js/index.js new file mode 100644 index 0000000..21adad5 --- /dev/null +++ b/src/js/index.js @@ -0,0 +1,63 @@ + +/* + * 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) { + el.addEventListener('click', function () { + // get the target from the 'data-target' attribute + const target = el.dataset.target; + const $target = document.getElementById(target); + + // toggle the 'is-active' class on both the 'navbar-burger' and the 'navbar-menu' + el.classList.toggle('is-active'); + $target.classList.toggle('is-active'); + }); + }); + } +}); + +document.forms.inquiry.onsubmit = function() { + let errorBox = document.getElementById("errorBox"); + let successBox = document.getElementById("successBox"); + errorBox.style.display = "none"; + successBox.style.display = "none"; + let form = document.forms.inquiry; + let name = form.elements.name.value; + let fromEmail = form.elements.from.value; + let body = form.elements.body.value; + + Email.send({ + SecureToken : "cec9bc04-de48-48fd-b1ad-a95cffb41468", + To : "atc@53hor.net", + From : fromEmail, + 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"; + } + else { + form.reset(); + successBox.style.display = "block"; + } + } + ); + + return false; +} + |