( 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 ); wpcf7.initform( $form ); if ( wpcf7.cached ) { wpcf7.refill( $form ); } } ); } ); wpcf7.getid = function( form ) { return parseint( $( 'input[name="_wpcf7"]', form ).val(), 10 ); }; wpcf7.initform = function( form ) { var $form = $( form ); $form.submit( function( event ) { if ( ! wpcf7.supporthtml5.placeholder ) { $( '[placeholder].placeheld', $form ).each( function( i, n ) { $( n ).val( '' ).removeclass( 'placeheld' ); } ); } if ( typeof window.formdata === 'function' ) { 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 ); } ); } ); } ); // url input correction $form.on( 'change', '.wpcf7-validates-as-url', function() { var val = $.trim( $( this ).val() ); if ( val && ! val.match( /^[a-z][a-z0-9.+-]*:/i ) && -1 !== val.indexof( '.' ) ) { val = val.replace( /^\/+/, '' ); val = 'http://' + val; } $( this ).val( val ); } ); }; wpcf7.submit = function( form ) { if ( typeof window.formdata !== 'function' ) { return; } var $form = $( form ); $( '.ajax-loader', $form ).addclass( 'is-active' ); wpcf7.clearresponse( $form ); var formdata = new formdata( $form.get( 0 ) ); var detail = { id: $form.closest( 'div.wpcf7' ).attr( 'id' ), status: 'init', inputs: [], formdata: formdata }; $.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( /^_wpcf7_\w+_free_text_/ ) ) { var owner = field.name.replace( /^_wpcf7_\w+_free_text_/, '' ); detail.inputs.push( { name: owner + '-free-text', value: field.value } ); } else if ( field.name.match( /^_/ ) ) { // do nothing } else { detail.inputs.push( field ); } } ); wpcf7.triggerevent( $form.closest( 'div.wpcf7' ), 'beforesubmit', detail ); var ajaxsuccess = function( data, status, xhr, $form ) { detail.id = $( data.into ).attr( 'id' ); detail.status = data.status; detail.apiresponse = data; 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 'acceptance_missing': $message.addclass( 'wpcf7-acceptance-missing' ); $form.addclass( 'unaccepted' ); wpcf7.triggerevent( data.into, 'unaccepted', 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 'aborted': $message.addclass( 'wpcf7-aborted' ); $form.addclass( 'aborted' ); wpcf7.triggerevent( data.into, 'aborted', detail ); break; case 'mail_sent': $message.addclass( 'wpcf7-mail-sent-ok' ); $form.addclass( 'sent' ); wpcf7.triggerevent( data.into, 'mailsent', detail ); break; case 'mail_failed': $message.addclass( 'wpcf7-mail-sent-ng' ); $form.addclass( 'failed' ); wpcf7.triggerevent( data.into, 'mailfailed', detail ); break; default: var customstatusclass = 'custom-' + data.status.replace( /[^0-9a-z]+/i, '-' ); $message.addclass( 'wpcf7-' + customstatusclass ); $form.addclass( customstatusclass ); } wpcf7.refill( $form, data ); wpcf7.triggerevent( data.into, 'submit', detail ); if ( 'mail_sent' == data.status ) { $form.each( function() { this.reset(); } ); wpcf7.togglesubmit( $form ); } if ( ! wpcf7.supporthtml5.placeholder ) { $form.find( '[placeholder].placeheld' ).each( function( i, n ) { $( n ).val( $( n ).attr( 'placeholder' ) ); } ); } $message.html( '' ).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 = $( '