(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') }); }); } this.find('.wpcf7-character-count').wpcf7charactercount(); this.find('.wpcf7-validates-as-url').change(function() { $(this).wpcf7normalizeurl(); }); }; $.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(); $form.find('[placeholder].placeheld').each(function(i, n) { $(n).val($(n).attr('placeholder')); }); $responseoutput.append(data.message).slidedown('fast'); $responseoutput.attr('role', 'alert'); $.wpcf7updatescreenreaderresponse($form, data); }; $.fn.wpcf7exclusivecheckbox = function() { return this.find('input:checkbox').click(function() { var name = $(this).attr('name'); $(this).closest('form').find('input:checkbox[name="' + name + '"]').not(this).prop('checked', false); }); }; $.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 = $('') .attr({ src: _wpcf7.loaderurl, alt: _wpcf7.sending }) .css('visibility', 'hidden'); $(this).after(loader); }); }; $.fn.wpcf7togglesubmit = function() { return this.each(function() { var form = $(this); if (this.tagname.tolowercase() != 'form') form = $(this).find('form').first(); if (form.hasclass('wpcf7-acceptance-as-validation')) return; var submit = form.find('input:submit'); if (! submit.length) return; var acceptances = form.find('input:checkbox.wpcf7-acceptance'); if (! acceptances.length) return; submit.removeattr('disabled'); acceptances.each(function(i, n) { n = $(n); if (n.hasclass('wpcf7-invert') && n.is(':checked') || ! n.hasclass('wpcf7-invert') && ! n.is(':checked')) submit.attr('disabled', 'disabled'); }); }); }; $.fn.wpcf7togglecheckboxfreetext = function() { return this.each(function() { var $wrap = $(this).closest('.wpcf7-form-control'); if ($(this).find(':checkbox, :radio').is(':checked')) { $(this).find(':input.wpcf7-free-text').prop('disabled', false); } else { $(this).find(':input.wpcf7-free-text').prop('disabled', true); } $wrap.find(':checkbox, :radio').change(function() { var $cb = $('.has-free-text', $wrap).find(':checkbox, :radio'); var $freetext = $(':input.wpcf7-free-text', $wrap); if ($cb.is(':checked')) { $freetext.prop('disabled', false).focus(); } else { $freetext.prop('disabled', true); } }); }); }; $.fn.wpcf7charactercount = function() { return this.each(function() { var $count = $(this); var name = $count.attr('data-target-name'); var down = $count.hasclass('down'); var starting = parseint($count.attr('data-starting-value'), 10); var maximum = parseint($count.attr('data-maximum-value'), 10); var minimum = parseint($count.attr('data-minimum-value'), 10); var updatecount = function($target) { var length = $target.val().length; var count = down ? starting - length : length; $count.attr('data-current-value', count); $count.text(count); if (maximum && maximum < length) { $count.addclass('too-long'); } else { $count.removeclass('too-long'); } if (minimum && length < minimum) { $count.addclass('too-short'); } else { $count.removeclass('too-short'); } }; $count.closest('form').find(':input[name="' + name + '"]').each(function() { updatecount($(this)); $(this).keyup(function() { updatecount($(this)); }); }); }); }; $.fn.wpcf7normalizeurl = function() { return this.each(function() { var val = $.trim($(this).val()); if (! val.match(/^[a-z][a-z0-9.+-]*:/i)) { // check the scheme part val = val.replace(/^\/+/, ''); val = 'http://' + val; } $(this).val(val); }); }; $.fn.wpcf7notvalidtip = function(message) { return this.each(function() { var $into = $(this); $into.find('span.wpcf7-not-valid-tip').remove(); $into.append('' + message + ''); if ($into.is('.use-floating-validation-tip *')) { $('.wpcf7-not-valid-tip', $into).mouseover(function() { $(this).wpcf7fadeout(); }); $(':input', $into).focus(function() { $('.wpcf7-not-valid-tip', $into).not(':hidden').wpcf7fadeout(); }); } }); }; $.fn.wpcf7fadeout = function() { return this.each(function() { $(this).animate({ opacity: 0 }, 'fast', function() { $(this).css({'z-index': -100}); }); }); }; $.fn.wpcf7onloadrefill = function() { return this.each(function() { var url = $(this).attr('action'); if (0 < url.indexof('#')) url = url.substr(0, url.indexof('#')); var id = $(this).find('input[name="_wpcf7"]').val(); var unittag = $(this).find('input[name="_wpcf7_unit_tag"]').val(); $.getjson(url, { _wpcf7_is_ajax_call: 1, _wpcf7: id, _wpcf7_request_ver: $.now() }, function(data) { if (data && data.captcha) $('#' + unittag).wpcf7refillcaptcha(data.captcha); if (data && data.quiz) $('#' + unittag).wpcf7refillquiz(data.quiz); } ); }); }; $.fn.wpcf7refillcaptcha = function(captcha) { return this.each(function() { var form = $(this); $.each(captcha, function(i, n) { form.find(':input[name="' + i + '"]').clearfields(); form.find('img.wpcf7-captcha-' + i).attr('src', n); var match = /([0-9]+)\.(png|gif|jpeg)$/.exec(n); form.find('input:hidden[name="_wpcf7_captcha_challenge_' + i + '"]').attr('value', match[1]); }); }); }; $.fn.wpcf7refillquiz = function(quiz) { return this.each(function() { var form = $(this); $.each(quiz, function(i, n) { form.find(':input[name="' + i + '"]').clearfields(); form.find(':input[name="' + i + '"]').siblings('span.wpcf7-quiz-label').text(n[0]); form.find('input:hidden[name="_wpcf7_quiz_answer_' + i + '"]').attr('value', n[1]); }); }); }; $.fn.wpcf7clearresponseoutput = function() { return this.each(function() { $(this).find('div.wpcf7-response-output').hide().empty().removeclass('wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked').removeattr('role'); $(this).find('span.wpcf7-not-valid-tip').remove(); $(this).find('img.ajax-loader').css({ visibility: 'hidden' }); }); }; $.wpcf7updatescreenreaderresponse = function($form, data) { $('.wpcf7 .screen-reader-response').html('').attr('role', ''); if (data.message) { var $response = $form.siblings('.screen-reader-response').first(); $response.append(data.message); if (data.invalids) { var $invalids = $('