( function( $ ) { 'use strict'; if ( typeof wpcf7 === 'undefined' || wpcf7 === null ) { return; } wpcf7 = $.extend( { cached: 0, inputs: [] }, wpcf7 ); $( function() { wpcf7.supporthtml5 = ( function() { var features = {}; var input = document.createelement( 'input' ); features.placeholder = 'placeholder' in input; var inputtypes = [ 'email', 'url', 'tel', 'number', 'range', 'date' ]; $.each( inputtypes, function( index, value ) { input.setattribute( 'type', value ); features[ value ] = input.type !== 'text'; } ); return features; } )(); $( 'div.wpcf7 > form' ).each( function() { var $form = $( this ); $form.submit( function( event ) { if ( typeof window.formdata !== 'function' ) { return; } wpcf7.submit( $form ); event.preventdefault(); } ); $( '.wpcf7-submit', $form ).after( '' ); wpcf7.togglesubmit( $form ); $form.on( 'click', '.wpcf7-acceptance', function() { wpcf7.togglesubmit( $form ); } ); // exclusive checkbox $( '.wpcf7-exclusive-checkbox', $form ).on( 'click', 'input:checkbox', function() { var name = $( this ).attr( 'name' ); $form.find( 'input:checkbox[name="' + name + '"]' ).not( this ).prop( 'checked', false ); } ); // free text option for checkboxes and radio buttons $( '.wpcf7-list-item.has-free-text', $form ).each( function() { var $freetext = $( ':input.wpcf7-free-text', this ); var $wrap = $( this ).closest( '.wpcf7-form-control' ); if ( $( ':checkbox, :radio', this ).is( ':checked' ) ) { $freetext.prop( 'disabled', false ); } else { $freetext.prop( 'disabled', true ); } $wrap.on( 'change', ':checkbox, :radio', function() { var $cb = $( '.has-free-text', $wrap ).find( ':checkbox, :radio' ); if ( $cb.is( ':checked' ) ) { $freetext.prop( 'disabled', false ).focus(); } else { $freetext.prop( 'disabled', true ); } } ); } ); // placeholder fallback if ( ! wpcf7.supporthtml5.placeholder ) { $( '[placeholder]', $form ).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' ); } } ); } ); } if ( wpcf7.jqueryui && ! wpcf7.supporthtml5.date ) { $form.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 ) { $form.find( 'input.wpcf7-number[type="number"]' ).each( function() { $( this ).spinner( { min: $( this ).attr( 'min' ), max: $( this ).attr( 'max' ), step: $( this ).attr( 'step' ) } ); } ); } // character count $( '.wpcf7-character-count', $form ).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 $target = $( 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' ); } }; $( ':input[name="' + name + '"]', $form ).each( function() { updatecount( this ); $( this ).keyup( function() { updatecount( this ); } ); } ); } ); $form.on( 'change', '.wpcf7-validates-as-url', function() { var val = $.trim( $( this ).val() ); // check the scheme part if ( val && ! val.match( /^[a-z][a-z0-9.+-]*:/i ) ) { val = val.replace( /^\/+/, '' ); val = 'http://' + val; } $( this ).val( val ); } ); if ( wpcf7.cached ) { wpcf7.refill( $form ); } } ); } ); wpcf7.getid = function( form ) { return parseint( $( 'input[name="_wpcf7"]', form ).val(), 10 ); }; wpcf7.submit = function( form ) { var $form = $( form ); $( '[placeholder].placeheld', $form ).each( function( i, n ) { $( n ).val( '' ); } ); wpcf7.clearresponse( $form ); $( '.ajax-loader', $form ).addclass( 'is-active' ); if ( typeof window.formdata !== 'function' ) { return; } var formdata = new formdata( $form.get( 0 ) ); var ajaxsuccess = function( data, status, xhr, $form ) { var detail = { id: $( data.into ).attr( 'id' ), status: data.status, inputs: [] }; $.each( $form.serializearray(), function( i, field ) { if ( '_wpcf7' == field.name ) { detail.contactformid = field.value; } else if ( '_wpcf7_version' == field.name ) { detail.pluginversion = field.value; } else if ( '_wpcf7_locale' == field.name ) { detail.contactformlocale = field.value; } else if ( '_wpcf7_unit_tag' == field.name ) { detail.unittag = field.value; } else if ( '_wpcf7_container_post' == field.name ) { detail.containerpostid = field.value; } else if ( field.name.match( /^_/ ) ) { // do nothing } else { detail.inputs.push( field ); } } ); var $message = $( '.wpcf7-response-output', $form ); switch ( data.status ) { case 'validation_failed': $.each( data.invalidfields, function( i, n ) { $( n.into, $form ).each( function() { wpcf7.notvalidtip( this, n.message ); $( '.wpcf7-form-control', this ).addclass( 'wpcf7-not-valid' ); $( '[aria-invalid]', this ).attr( 'aria-invalid', 'true' ); } ); } ); $message.addclass( 'wpcf7-validation-errors' ); $form.addclass( 'invalid' ); wpcf7.triggerevent( data.into, 'invalid', detail ); break; case 'spam': $message.addclass( 'wpcf7-spam-blocked' ); $form.addclass( 'spam' ); $( '[name="g-recaptcha-response"]', $form ).each( function() { if ( '' === $( this ).val() ) { var $recaptcha = $( this ).closest( '.wpcf7-form-control-wrap' ); wpcf7.notvalidtip( $recaptcha, wpcf7.recaptcha.messages.empty ); } } ); wpcf7.triggerevent( data.into, 'spam', detail ); break; case 'mail_sent': $message.addclass( 'wpcf7-mail-sent-ok' ); $form.addclass( 'sent' ); if ( data.onsentok ) { $.each( data.onsentok, function( i, n ) { eval( n ) } ); } wpcf7.triggerevent( data.into, 'mailsent', detail ); break; case 'mail_failed': case 'acceptance_missing': default: $message.addclass( 'wpcf7-mail-sent-ng' ); $form.addclass( 'failed' ); wpcf7.triggerevent( data.into, 'mailfailed', detail ); } wpcf7.refill( $form, data ); if ( data.onsubmit ) { $.each( data.onsubmit, function( i, n ) { eval( n ) } ); } wpcf7.triggerevent( data.into, 'submit', detail ); if ( 'mail_sent' == data.status ) { $form.each( function() { this.reset(); } ); } $form.find( '[placeholder].placeheld' ).each( function( i, n ) { $( n ).val( $( n ).attr( 'placeholder' ) ); } ); $message.append( data.message ).slidedown( 'fast' ); $message.attr( 'role', 'alert' ); $( '.screen-reader-response', $form.closest( '.wpcf7' ) ).each( function() { var $response = $( this ); $response.html( '' ).attr( 'role', '' ).append( data.message ); if ( data.invalidfields ) { var $invalids = $( '