// Custom Scripts for Primal Template // jQuery(function($) { "use strict"; /* --------- Wow Init ------ */ new WOW().init(); /*----- Preloader ----- */ $(window).load(function() { setTimeout(function() { $('#loading').fadeOut('slow', function() { }); }, 3000); }); /*----- Subscription Form ----- */ var _isFocus = false; var checkInput = function(selector) { if ($(selector).val().length == 0) { $(selector).parent().addClass("has-error"); if (!_isFocus) { $(selector).focus(); _isFocus = true; return true; } } else { $(selector).parent().removeClass("has-error"); return false; } } $('.contact-form').submit(function(e) { e.preventDefault(); _isFocus = false; var btn = $("#submit_contact_form"); var btnDisable = function() { btn.val("Enviando..."); btn.prop("disabled", true) } var btnEnable = function() { btn.val("Enviar"); btn.prop("disabled", false) } btnDisable(); $(".error-message").hide(); $(".success-message").hide(); if ( (!checkInput("#name") & !checkInput("#email") & !checkInput("#message") & !checkInput("#g-recaptcha-response")) == false ) { btnEnable(); $(".error-message").text("Alguns campos não foram preenchidos.").fadeIn(); return; } var postdata = $('.contact-form').serialize(); $.ajax({ type: 'POST', url: '/submit', data: postdata, dataType: 'json', success: function(json) { if (!json.error) { grecaptcha.reset(); $('.contact-form').trigger("reset"); $(".success-message").text("Sua mensagem foi enviado com sucesso!").fadeIn(); } else { $.each(json.invalid_input, function(item, i){ console.log(item); console.log(i); }) $(".error-message").text("Alguns campos não foram preenchidos.").fadeIn(); } btnEnable(); }, fail: function() { btnEnable(); } }); }); });