( 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 = $( '' ); $.each( data.invalidfields, function( i, n ) { if ( n.idref ) { var $li = $( '
  • ' ).append( $( '' ).attr( 'href', '#' + n.idref ).append( n.message ) ); } else { var $li = $( '
  • ' ).append( n.message ); } $invalids.append( $li ); } ); $response.append( $invalids ); } $response.attr( 'role', 'alert' ).focus(); } ); }; $.ajax( { type: 'post', url: wpcf7.apisettings.root + wpcf7.apisettings.namespace + '/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 $target = $( target ); /* dom event */ var event = new customevent( 'wpcf7' + name, { bubbles: true, detail: detail } ); $target.get( 0 ).dispatchevent( event ); /* jquery event */ $target.trigger( 'wpcf7:' + name, detail ); $target.trigger( name + '.wpcf7', detail ); // deprecated }; 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 ); $( 'input:checkbox.wpcf7-acceptance', $form ).each( function() { var $a = $( this ); if ( $a.hasclass( 'wpcf7-invert' ) && $a.is( ':checked' ) || ! $a.hasclass( 'wpcf7-invert' ) && ! $a.is( ':checked' ) ) { $submit.prop( 'disabled', true ); return false; } } ); }; wpcf7.notvalidtip = function( target, message ) { var $target = $( target ); $( '.wpcf7-not-valid-tip', $target ).remove(); $( '' ) .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.root + wpcf7.apisettings.namespace + '/contact-forms/' + wpcf7.getid( $form ) + '/refill', 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.removeclass( 'invalid spam sent failed' ); $form.siblings( '.screen-reader-response' ).html( '' ).attr( 'role', '' ); $( '.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().removeattr( 'role' ) .removeclass( 'wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked' ); }; } )( 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; } )();