Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove jQuery #35

Merged
merged 7 commits into from
Mar 6, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Contact form thank you message
  • Loading branch information
tomanistor committed Feb 26, 2018
commit ce75017ffd77e9e5b76944ec5c27c30fe4ff178d
92 changes: 91 additions & 1 deletion layouts/partials/scripts/contact.min.js
Original file line number Diff line number Diff line change
@@ -1 +1,91 @@
$("#form-contact").addEventListener("submit",function(e){e.preventDefault();var t=$("input[name=name]").value,a=$("input[name=email").value,n=$("input[name=_subject").value,s=$("textarea[name=message]").value,i=new XMLHttpRequest,m={name:t,_replyto:a,email:a,_subject:n,message:s};i.open("POST","https://formspree.io/{{ .Site.Params.email }}",!0),i.setRequestHeader("Content-Type","application/json; charset=UTF-8"),i.send(JSON.stringify(m))});
$('#form-contact').addEventListener('submit', function(e) {
e.preventDefault();

// Store form field values
var name = $("input[name=name]").value;
var email = $("input[name=email").value;
var subject = $("input[name=_subject").value;
var message = $("textarea[name=message]").value;

// AJAX request
var request = new XMLHttpRequest();
var data = {
name:name,
_replyto:email,
email:email,
_subject:subject,
message:message,
}

// Send to Formspree
request.open('POST', 'https://formspree.io/{{ .Site.Params.email }}', true);
request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
// Call function when the state changes
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
console.log(request.responseText);

// Reset form
$('#form-contact').reset();

var submit = $('#form-submit');
var thanks = $('#form-thankyou');

function thankYouFadeIn() {
// Fade out submit button
submit.visibility = 'hidden';
submit.classList.add('hide');
submit.classList.remove('show');

// Fade in thank you message
thanks.visibility = 'visible';
thanks.classList.add('show');
thanks.classList.remove('hide');
setTimeout(thankYouFadeOut, 4000);
};

function thankYouFadeOut() {
// Fade out thank you message
thanks.visibility = 'hidden';
thanks.classList.add('hide');
thanks.classList.remove('show');

// Fade in submit button
submit.visibility = 'visible';
submit.classList.add('show');
submit.classList.remove('hide');
};

thankYouFadeIn();
}
}
request.send(JSON.stringify(data));


// $.ajax({
// url:"https://formspree.io/{{ .Site.Params.email }}",
// method:"POST",
// data:{
// name:name,
// _replyto:email,
// email:email,
// _subject:subject,
// message:message,
// },
// dataType:"json",
// success:function() {
// console.log("Form successfully sent");
// // Reset form
// $("#form-contact").get(0).reset();
// // Fade out submit button, fade in thank you message, then fade out message and fade in submit button
// $("#form-submit").fadeOut(function(){
// $("#form-thankyou").fadeIn(function(){
// $("#form-thankyou").delay(4000).fadeOut(function(){
// $("#form-submit").fadeIn();
// });
// });
// });
// }
// });

});