(function($) { if (typeof _wpcf7 == 'undefined' || _wpcf7 === null) _wpcf7 = {}; _wpcf7 = $.extend({ cached: 0 }, _wpcf7); $(function() { _wpcf7.supportHtml5 = $.wpcf7SupportHtml5(); $('div.wpcf7 > form').wpcf7InitForm(); }); $.fn.wpcf7InitForm = function() { this.ajaxForm({ beforeSubmit: function(arr, $form, options) { $form.wpcf7ClearResponseOutput(); $form.find('[aria-invalid]').attr('aria-invalid', 'false'); $form.find('img.ajax-loader').css({ visibility: 'visible' }); return true; }, beforeSerialize: function($form, options) { $form.find('[placeholder].placeheld').each(function(i, n) { $(n).val(''); }); return true; }, data: { '_wpcf7_is_ajax_call': 1 }, dataType: 'json', success: $.wpcf7AjaxSuccess, error: function(xhr, status, error, $form) { var e = $('
').text(error.message); $form.after(e); } }); if (_wpcf7.cached) this.wpcf7OnloadRefill(); this.wpcf7ToggleSubmit(); this.find('.wpcf7-submit').wpcf7AjaxLoader(); this.find('.wpcf7-acceptance').click(function() { $(this).closest('form').wpcf7ToggleSubmit(); }); this.find('.wpcf7-exclusive-checkbox').wpcf7ExclusiveCheckbox(); this.find('.wpcf7-list-item.has-free-text').wpcf7ToggleCheckboxFreetext(); this.find('[placeholder]').wpcf7Placeholder(); if (_wpcf7.jqueryUi && ! _wpcf7.supportHtml5.date) { this.find('input.wpcf7-date[type="date"]').each(function() { $(this).datepicker({ dateFormat: 'yy-mm-dd', minDate: new Date($(this).attr('min')), maxDate: new Date($(this).attr('max')) }); }); } if (_wpcf7.jqueryUi && ! _wpcf7.supportHtml5.number) { this.find('input.wpcf7-number[type="number"]').each(function() { $(this).spinner({ min: $(this).attr('min'), max: $(this).attr('max'), step: $(this).attr('step') }); }); } }; $.wpcf7AjaxSuccess = function(data, status, xhr, $form) { if (! $.isPlainObject(data) || $.isEmptyObject(data)) return; var $responseOutput = $form.find('div.wpcf7-response-output'); $form.wpcf7ClearResponseOutput(); $form.find('.wpcf7-form-control').removeClass('wpcf7-not-valid'); $form.removeClass('invalid spam sent failed'); if (data.captcha) $form.wpcf7RefillCaptcha(data.captcha); if (data.quiz) $form.wpcf7RefillQuiz(data.quiz); if (data.invalids) { $.each(data.invalids, function(i, n) { $form.find(n.into).wpcf7NotValidTip(n.message); $form.find(n.into).find('.wpcf7-form-control').addClass('wpcf7-not-valid'); $form.find(n.into).find('[aria-invalid]').attr('aria-invalid', 'true'); }); $responseOutput.addClass('wpcf7-validation-errors'); $form.addClass('invalid'); $(data.into).trigger('invalid.wpcf7'); } else if (1 == data.spam) { $responseOutput.addClass('wpcf7-spam-blocked'); $form.addClass('spam'); $(data.into).trigger('spam.wpcf7'); } else if (1 == data.mailSent) { $responseOutput.addClass('wpcf7-mail-sent-ok'); $form.addClass('sent'); if (data.onSentOk) $.each(data.onSentOk, function(i, n) { eval(n) }); $(data.into).trigger('mailsent.wpcf7'); } else { $responseOutput.addClass('wpcf7-mail-sent-ng'); $form.addClass('failed'); $(data.into).trigger('mailfailed.wpcf7'); } if (data.onSubmit) $.each(data.onSubmit, function(i, n) { eval(n) }); $(data.into).trigger('submit.wpcf7'); if (1 == data.mailSent) $form.resetForm().clearForm(); $form.find('[placeholder].placeheld').each(function(i, n) { $(n).val($(n).attr('placeholder')); }); $responseOutput.append(data.message).slideDown('fast'); $responseOutput.attr('role', 'alert'); } $.fn.wpcf7ExclusiveCheckbox = function() { return this.find('input:checkbox').click(function() { $(this).closest('.wpcf7-checkbox').find('input:checkbox').not(this).removeAttr('checked'); }); }; $.fn.wpcf7Placeholder = function() { if (_wpcf7.supportHtml5.placeholder) return this; return this.each(function() { $(this).val($(this).attr('placeholder')); $(this).addClass('placeheld'); $(this).focus(function() { if ($(this).hasClass('placeheld')) $(this).val('').removeClass('placeheld'); }); $(this).blur(function() { if ('' == $(this).val()) { $(this).val($(this).attr('placeholder')); $(this).addClass('placeheld'); } }); }); }; $.fn.wpcf7AjaxLoader = function() { return this.each(function() { var loader = $('