( 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 ); wpcf7.setstatus( $form, 'init' ); $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.resetcounter( $form ); // 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( /^_/ ) ) { // 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; switch ( data.status ) { case 'init': wpcf7.setstatus( $form, 'init' ); break; case 'validation_failed': $.each( data.invalid_fields, function( i, n ) { $( n.into, $form ).each( function() { wpcf7.notvalidtip( this, n.message ); $( '.wpcf7-form-control', this ).addclass( 'wpcf7-not-valid' ); $( '.wpcf7-form-control', this ).attr( 'aria-describedby', n.error_id ); $( '[aria-invalid]', this ).attr( 'aria-invalid', 'true' ); } ); } ); wpcf7.setstatus( $form, 'invalid' ); wpcf7.triggerevent( data.into, 'invalid', detail ); break; case 'acceptance_missing': wpcf7.setstatus( $form, 'unaccepted' ); wpcf7.triggerevent( data.into, 'unaccepted', detail ); break; case 'spam': wpcf7.setstatus( $form, 'spam' ); wpcf7.triggerevent( data.into, 'spam', detail ); break; case 'aborted': wpcf7.setstatus( $form, 'aborted' ); wpcf7.triggerevent( data.into, 'aborted', detail ); break; case 'mail_sent': wpcf7.setstatus( $form, 'sent' ); wpcf7.triggerevent( data.into, 'mailsent', detail ); break; case 'mail_failed': wpcf7.setstatus( $form, 'failed' ); wpcf7.triggerevent( data.into, 'mailfailed', detail ); break; default: wpcf7.setstatus( $form, 'custom-' + data.status.replace( /[^0-9a-z]+/i, '-' ) ); } wpcf7.refill( $form, data ); wpcf7.triggerevent( data.into, 'submit', detail ); if ( 'mail_sent' == data.status ) { $form.each( function() { this.reset(); } ); wpcf7.togglesubmit( $form ); wpcf7.resetcounter( $form ); } if ( ! wpcf7.supporthtml5.placeholder ) { $form.find( '[placeholder].placeheld' ).each( function( i, n ) { $( n ).val( $( n ).attr( 'placeholder' ) ); } ); } $( '.wpcf7-response-output', $form ) .html( '' ).append( data.message ).slidedown( 'fast' ); $( '.screen-reader-response', $form.closest( '.wpcf7' ) ).each( function() { var $response = $( this ); $( '[role="status"]', $response ).html( data.message ); if ( data.invalid_fields ) { $.each( data.invalid_fields, function( i, n ) { if ( n.idref ) { var $li = $( '
' ).append( $( '' ).attr( 'href', '#' + n.idref ).append( n.message ) ); } else { var $li = $( '' ).append( n.message ); } $li.attr( 'id', n.error_id ); $( 'ul', $response ).append( $li ); } ); } } ); if ( data.posted_data_hash ) { $form.find( 'input[name="_wpcf7_posted_data_hash"]' ).first() .val( data.posted_data_hash ); } }; $.ajax( { type: 'post', url: wpcf7.apisettings.getroute( '/contact-forms/' + wpcf7.getid( $form ) + '/feedback' ), data: formdata, datatype: 'json', processdata: false, contenttype: false } ).done( function( data, status, xhr ) { ajaxsuccess( data, status, xhr, $form ); $( '.ajax-loader', $form ).removeclass( 'is-active' ); } ).fail( function( xhr, status, error ) { var $e = $( '' ).text( error.message ); $form.after( $e ); } ); }; wpcf7.triggerevent = function( target, name, detail ) { var event = new customevent( 'wpcf7' + name, { bubbles: true, detail: detail } ); $( target ).get( 0 ).dispatchevent( event ); }; wpcf7.setstatus = function( form, status ) { var $form = $( form ); var prevstatus = $form.attr( 'data-status' ); $form.data( 'status', status ); $form.addclass( status ); $form.attr( 'data-status', status ); if ( prevstatus && prevstatus !== status ) { $form.removeclass( prevstatus ); } } wpcf7.togglesubmit = function( form, state ) { var $form = $( form ); var $submit = $( 'input:submit', $form ); if ( typeof state !== 'undefined' ) { $submit.prop( 'disabled', ! state ); return; } if ( $form.hasclass( 'wpcf7-acceptance-as-validation' ) ) { return; } $submit.prop( 'disabled', false ); $( '.wpcf7-acceptance', $form ).each( function() { var $span = $( this ); var $input = $( 'input:checkbox', $span ); if ( ! $span.hasclass( 'optional' ) ) { if ( $span.hasclass( 'invert' ) && $input.is( ':checked' ) || ! $span.hasclass( 'invert' ) && ! $input.is( ':checked' ) ) { $submit.prop( 'disabled', true ); return false; } } } ); }; wpcf7.resetcounter = function( form ) { var $form = $( form ); $( '.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 ); } ); } ); } ); }; wpcf7.notvalidtip = function( target, message ) { var $target = $( target ); $( '.wpcf7-not-valid-tip', $target ).remove(); $( '' ).attr( { 'class': 'wpcf7-not-valid-tip', 'aria-hidden': 'true', } ).text( message ).appendto( $target ); if ( $target.is( '.use-floating-validation-tip *' ) ) { var fadeout = function( target ) { $( target ).not( ':hidden' ).animate( { opacity: 0 }, 'fast', function() { $( this ).css( { 'z-index': -100 } ); } ); }; $target.on( 'mouseover', '.wpcf7-not-valid-tip', function() { fadeout( this ); } ); $target.on( 'focus', ':input', function() { fadeout( $( '.wpcf7-not-valid-tip', $target ) ); } ); } }; wpcf7.refill = function( form, data ) { var $form = $( form ); var refillcaptcha = function( $form, items ) { $.each( items, function( i, n ) { $form.find( ':input[name="' + i + '"]' ).val( '' ); $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 ] ); } ); }; var refillquiz = function( $form, items ) { $.each( items, function( i, n ) { $form.find( ':input[name="' + i + '"]' ).val( '' ); $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 ] ); } ); }; if ( typeof data === 'undefined' ) { $.ajax( { type: 'get', url: wpcf7.apisettings.getroute( '/contact-forms/' + wpcf7.getid( $form ) + '/refill' ), beforesend: function( xhr ) { var nonce = $form.find( ':input[name="_wpnonce"]' ).val(); if ( nonce ) { xhr.setrequestheader( 'x-wp-nonce', nonce ); } }, datatype: 'json' } ).done( function( data, status, xhr ) { if ( data.captcha ) { refillcaptcha( $form, data.captcha ); } if ( data.quiz ) { refillquiz( $form, data.quiz ); } } ); } else { if ( data.captcha ) { refillcaptcha( $form, data.captcha ); } if ( data.quiz ) { refillquiz( $form, data.quiz ); } } }; wpcf7.clearresponse = function( form ) { var $form = $( form ); $form.siblings( '.screen-reader-response' ).each( function() { $( '[role="status"]', this ).html( '' ); $( 'ul', this ).html( '' ); } ); $( '.wpcf7-not-valid-tip', $form ).remove(); $( '[aria-invalid]', $form ).attr( 'aria-invalid', 'false' ); $( '.wpcf7-form-control', $form ).removeclass( 'wpcf7-not-valid' ); $( '.wpcf7-response-output', $form ).hide().empty(); }; wpcf7.apisettings.getroute = function( path ) { var url = wpcf7.apisettings.root; url = url.replace( wpcf7.apisettings.namespace, wpcf7.apisettings.namespace + path ); return url; }; } )( jquery ); /* * polyfill for internet explorer * see https://developer.mozilla.org/en-us/docs/web/api/customevent/customevent */ ( function () { if ( typeof window.customevent === "function" ) return false; function customevent ( event, params ) { params = params || { bubbles: false, cancelable: false, detail: undefined }; var evt = document.createevent( 'customevent' ); evt.initcustomevent( event, params.bubbles, params.cancelable, params.detail ); return evt; } customevent.prototype = window.event.prototype; window.customevent = customevent; } )();