Created
November 29, 2017 17:07
-
-
Save dbarison/2a33d174848ddf52085f8680d7f4d62f 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
mailchimp : => | |
$response = $("#response") | |
$response_text = $response.find('.response-text') | |
$("form#mcsubscribe").bind("ajax:beforeSend", (evt, xhr, settings) -> | |
$response_text.data "origText", $response_text.text() | |
$response_text.text "Loading ...." | |
$response.fadeIn() | |
return | |
).bind("ajax:success", (evt, data, status, xhr) -> | |
$form = $(this) | |
$form.find("input[type=\"email\"]").val "" | |
$response.fadeIn() | |
$response_text.html data.message | |
ga 'send', 'event', 'Newsletter', 'click' | |
return | |
).bind("ajax:complete", (evt, xhr, status) -> | |
return | |
).bind "ajax:error", (evt, xhr, status, error) -> | |
errors = undefined | |
errorText = undefined | |
errorList = undefined | |
try | |
# Populate errorText with the comment errors | |
errors = $.parseJSON(xhr.responseText) | |
catch err | |
# If the responseText is not valid JSON (like if a 500 exception was thrown), populate errors with a generic error message. | |
errors = message: "Please reload the page and try again" | |
# Build an unordered list from the list of errors | |
errorText = "There were errors with the submission. Please reload the page and try again." | |
errorList = "<ul>" | |
for error of errors | |
errorList += "<li>" + error + ": " + errors[error] + "</li> " | |
errorList += "</ul>" | |
# Insert error list into form | |
# console.log error | |
$response.removeClass('alert-info') | |
$response.removeClass('alert-success') | |
$response.addClass('alert-danger') | |
$response.fadeIn() | |
$response_text.html errorText | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment