Last active
September 26, 2019 16:06
-
-
Save WebReflection/dc9bf96e1e81e02131ce585a30a6e4cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// nullify the global reference while instrumenting the form | |
StaticEmail = (function (StaticEmail) { | |
contact.addEventListener('submit', function (event) { | |
event.preventDefault(); | |
var from = contact.from.value.trim(); | |
var md = contact.md.value.trim(); | |
if (from && md) { | |
contact.submit.disabled = true; | |
StaticEmail({ | |
path: '/api/paperboy', | |
subject: 'Contact from ' + from, | |
from: from, | |
md: md | |
}) | |
.then( | |
thanks, | |
function (error) { | |
// this check is to make code testable via http-server | |
if ( | |
error.message === 'Method Not Allowed' | |
// handle 405 errors as either OK (75%) or errors | |
// if you don't want errors, comment the following line | |
&& Math.random() < .75 | |
) | |
thanks(); | |
else { | |
alert(error); | |
contact.submit.disabled = false; | |
} | |
} | |
); | |
} | |
}); | |
function thanks() { | |
var div = document.createElement('div'); | |
div.textContent = 'Thank You!'; | |
contact.parentNode.replaceChild(div, contact); | |
} | |
}(StaticEmail)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment