var VM=VM||{},feedbackRecaptchaLoader=null;VM.Feedback={isReady:!1,isMember:!1,isAuthenticated:!1,hasFreeMembership:!0,storageKey:"",$feedback:null,$contributeFormContainer:null,$formContainer:null,$readerCommentsBar:null,recaptchaLoaded:!1,recaptchaKey:null,recaptcha:null,feedbackFormLoaded:null,onFeedbackLoaded:function(){VM.Me.getUser(function(n){VM.Feedback.setUser(n);VM.Feedback.ready()})},setUser:function(n){this.isMember=n.member||n.cms;this.isAuthenticated=n.id!==0},commentingLoaded:function(n){var t=this,i=window.setInterval(function(){t.isReady&&(window.clearInterval(i),t.$feedback.find("button[data-type='contribute']").data("comments-expanded",n).removeClass("hidden"))},75)},ready:function(){var n=$("#feedback-container").on("click",".feedback-button",this.onFeedbackButtonClicked);this.hasFreeMembership=n.data("free-membership");this.$formContainer=$("#feedback-form");this.$contributeFormContainer=$("#contribute-form");this.$feedback=$("#feedback");this.recaptchaKey=this.$formContainer.data("recaptcha");this.storageKey="VM-feedback_"+this.$formContainer.data("storagesuffix");this.$formContainer.on("submit",".feedback-form",this.onSubmit);this.isReady=!0},onFeedbackButtonClicked:function(n){var t,i,r;n.preventDefault();t=$(this);i=t.data("type");$(".feedback-button-triggered").removeClass("feedback-button-triggered");t.closest(".card-block").addClass("feedback-button-triggered");i==="contribute"?(VM.Feedback.$contributeFormContainer.removeClass("hidden"),VM.Feedback.$formContainer.addClass("hidden"),t.data("comments-expanded")?VM.Feedback.showCommentingForm():(t.addClass("loading"),VM.Comments.showComments(function(){VM.Feedback.showCommentingForm();t.removeClass("loading");t.data("comments-expanded",!0)}))):(VM.Feedback.$contributeFormContainer&&VM.Feedback.$contributeFormContainer.addClass("hidden"),t.addClass("loading"),i!=="question"||VM.Comments?VM.Feedback.loadForm(t):(r=$("
<\/div>"),r.load(VM.Feedback.$formContainer.data("modal-endpoint"),function(){$("body").append(r);VM.Feedback.loadForm(t)})));VM.Track.onGaClick.call(t)},loadForm:function(n){var t=this,i=n.attr("href")||n.data("endpoint");t.$formContainer.removeClass("hidden").load(i,function(){n.removeClass("loading");t.feedbackFormLoaded=VM.Ajax.getFunction(n.data("complete"));t.feedbackFormLoaded.call(VM.Feedback);t.$formContainer.addClass("mt-2 mb-3")})},showCommentingForm:function(){this.$contributeFormContainer.is(":empty")&&(this.$contributeFormContainer.append(VM.Comments.$loader.find(".membership-required-container")),this.$contributeFormContainer.append(VM.Comments.$form),$("#comments-disclaimer").html('We welcome your feedback and encourage you to share your thoughts. Our editors routinely review submissions and select the most thoughtful and interesting reader feedback for publication. To learn more, please read our Community Guidelines<\/a>.').appendTo(this.$contributeFormContainer),VM.Comments.$description.attr("placeholder","Add your feedback"),this.$contributeFormContainer.find(".account-modal-trigger").data("modal-set-desc","Your feedback will be submitted after you sign in or register."),VM.Comments.showForm())},recaptchaVerify:function(n){n&&($(".visible-unverified").addClass("hidden"),$(".hidden-unverified").removeClass("hidden"))},typoFormLoaded:function(){VM.Feedback.isAuthenticated?this.recaptchaVerify(!0):(feedbackRecaptchaLoader=function(){VM.Feedback.recaptcha=grecaptcha.render("feedback-recaptcha",{sitekey:VM.Feedback.recaptchaKey,callback:VM.Feedback.recaptchaVerify});VM.Feedback.recaptchaLoaded=!0;$("#recaptcha-group").removeClass("hidden")},typeof grecaptcha=="undefined"?$.getScript("https://www.google.com/recaptcha/api.js?onload=feedbackRecaptchaLoader&render=explicit"):grecaptcha.ready(feedbackRecaptchaLoader));VM.Ajax.resetValidation($("#feedback-form form"))},questionFormLoaded:function(){if(VM.Feedback.$formContainer.find("#feedback-description").attr("placeholder","Ask your question."),VM.Feedback.isAuthenticated&&(VM.Feedback.isMember||VM.Feedback.hasFreeMembership))$(".membership-required-container").addClass("hidden"),$(".membership-required-signedin").removeClass("hidden"),$("#feedback-form-container").removeClass("hidden"),VM.Ajax.resetValidation($("#feedback-form form"));else if(!VM.Feedback.hasFreeMembership){var n=$(".membership-signin-link");VM.Feedback.isAuthenticated?($(".membership-required-warning").removeClass("hidden"),n.text("Sign in with a different account")):n.text(n.data("not-logged-in"));$(".membership-required-container").removeClass("hidden")}},feedbackFormSuccess:function(){VM.Storage.setObj(VM.Feedback.storageKey,"")},onSubmit:function(n){var t,i,r;if(n.preventDefault(),t=$(this).find(".feedback-submit"),i=$(this).attr("action"),t.addClass("loading").prop("disabled",!0),$(this).valid()){if(VM.Track.onGaClick.call(t),VM.Feedback.recaptchaLoaded&&(r=grecaptcha.getResponse(VM.Feedback.recaptcha),!r))return alert("Please verify that you're a human!"),t.removeClass("loading").prop("disabled",!1),!1;$.ajax({type:"POST",url:i,data:$(this).serialize()}).done(function(n){VM.Feedback.feedbackFormSuccess();$("#feedback-form-container").html(n)}).fail(function(){$("#feedback-form-container").html("
There was a problem adding your submission.<\/div>")})}},onAccountModalOpened:function(n){if(n.hasClass("feedback-submit")){var t=$(".feedback-description").val();VM.Storage.setObj(VM.Feedback.storageKey,t)}},onLoginSuccess:function(n,t){VM.Feedback.authenticated(n,t)},onRegisteredSuccess:function(n,t){VM.Feedback.authenticated(n,t)},onRegisteredPartialSuccess:function(n,t){t.hasClass("feedback-submit")?VM.Ajax.toast("Your account requires review before you can add your submission. Don't worry, we've saved your information for later.","warning"):VM.Ajax.toast("Your account requires review before you can add your submission.","warning")},onPasswordReset:function(){VM.Feedback.authenticated(data,$trigger)},authenticated:function(n,t){if(this.setUser(n),VM.Comments&&VM.Comments.setUser(n),t.hasClass("feedback-submit")){var i=this.$formContainer.find("form");VM.Ajax.resetValidation(i);i.valid()&&(t.removeClass("account-modal-trigger"),t.click())}$(".account-modal-trigger").removeClass("account-modal-trigger");this.feedbackFormLoaded.call(this);VM.Ajax.toast("You are now signed in.","success")},showComments:function(n){n>0&&(VM.Comments.$loader.removeClass("hidden"),VM.Feedback.$readerCommentsBar.removeClass("hidden"))}};$(function(){VM.Comments&&(VM.Comments.$loader.addClass("hidden"),VM.Feedback.$readerCommentsBar=VM.Comments.$loader.prev().addClass("hidden"),VM.Comments.onCountLoadedCallback=VM.Feedback.showComments,VM.Comments.onCommentsLoadedCallback=VM.Feedback.showComments)})