1( function( $ ) { 2 3 'use strict'; 4 5 if ( typeof wpcf7 === 'undefined' || wpcf7 === null ) { 6 return; 7 } 8 9 wpcf7 = $.extend( { 10 cached: 0, 11 inputs: [] 12 }, wpcf7 ); 13 14 $( function() { 15 wpcf7.supportHtml5 = ( function() { 16 var features = {}; 17 var input = document.createElement( 'input' ); 18 19 features.placeholder = 'placeholder' in input; 20 21 var inputTypes = [ 'email', 'url', 'tel', 'number', 'range', 'date' ]; 22 23 $.each( inputTypes, function( index, value ) { 24 input.setAttribute( 'type', value ); 25 features[ value ] = input.type !== 'text'; 26 } ); 27 28 return features; 29 } )(); 30 31 $( 'div.wpcf7 > form' ).each( function() { 32 var $form = $( this ); 33 wpcf7.initForm( $form ); 34 35 if ( wpcf7.cached ) { 36 wpcf7.refill( $form ); 37 } 38 } ); 39 } ); 40 41 wpcf7.getId = function( form ) { 42 return parseInt( $( 'input[name="_wpcf7"]', form ).val(), 10 ); 43 }; 44 45 wpcf7.initForm = function( form ) { 46 var $form = $( form ); 47 48 $form.submit( function( event ) { 49 if ( ! wpcf7.supportHtml5.placeholder ) { 50 $( '[placeholder].placeheld', $form ).each( function( i, n ) { 51 $( n ).val( '' ).removeClass( 'placeheld' ); 52 } ); 53 } 54 55 if ( typeof window.FormData === 'function' ) { 56 wpcf7.submit( $form ); 57 event.preventDefault(); 58 } 59 } ); 60 61 $( '.wpcf7-submit', $form ).after( '<span class="ajax-loader"></span>' ); 62 63 wpcf7.toggleSubmit( $form ); 64 65 $form.on( 'click', '.wpcf7-acceptance', function() { 66 wpcf7.toggleSubmit( $form ); 67 } ); 68 69 // Exclusive Checkbox 70 $( '.wpcf7-exclusive-checkbox', $form ).on( 'click', 'input:checkbox', function() { 71 var name = $( this ).attr( 'name' );
72 $form.find( 'input:checkbox[name="' + name + '"]' ).not( this ).prop( 'checked', false ); 73 } ); 74 75 // Free Text Option for Checkboxes and Radio Buttons 76 $( '.wpcf7-list-item.has-free-text', $form ).each( function() { 77 var $freetext = $( ':input.wpcf7-free-text', this ); 78 var $wrap = $( this ).closest( '.wpcf7-form-control' ); 79 80 if ( $( ':checkbox, :radio', this ).is( ':checked' ) ) { 81 $freetext.prop( 'disabled', false ); 82 } else { 83 $freetext.prop( 'disabled', true ); 84 } 85 86 $wrap.on( 'change', ':checkbox, :radio', function() { 87 var $cb = $( '.has-free-text', $wrap ).find( ':checkbox, :radio' ); 88 89 if ( $cb.is( ':checked' ) ) { 90 $freetext.prop( 'disabled', false ).focus(); 91 } else { 92 $freetext.prop( 'disabled', true ); 93 } 94 } ); 95 } ); 96 97 // Placeholder Fallback 98 if ( ! wpcf7.supportHtml5.placeholder ) { 99 $( '[placeholder]', $form ).each( function() { 100 $( this ).val( $( this ).attr( 'placeholder' ) ); 101 $( this ).addClass( 'placeheld' ); 102 103 $( this ).focus( function() { 104 if ( $( this ).hasClass( 'placeheld' ) ) { 105 $( this ).val( '' ).removeClass( 'placeheld' ); 106 } 107 } ); 108 109 $( this ).blur( function() { 110 if ( '' === $( this ).val() ) { 111 $( this ).val( $( this ).attr( 'placeholder' ) ); 112 $( this ).addClass( 'placeheld' ); 113 } 114 } ); 115 } ); 116 } 117 118 if ( wpcf7.jqueryUi && ! wpcf7.supportHtml5.date ) {
119 $form.find( 'input.wpcf7-date[type="date"]' ).each( function() { 120 $( this ).datepicker( { 121 dateFormat: 'yy-mm-dd', 122 minDate: new Date( $( this ).attr( 'min' ) ), 123 maxDate: new Date( $( this ).attr( 'max' ) ) 124 } ); 125 } ); 126 } 127 128 if ( wpcf7.jqueryUi && ! wpcf7.supportHtml5.number ) { 129 $form.find( 'input.wpcf7-number[type="number"]' ).each( function() { 130 $( this ).spinner( { 131 min: $( this ).attr( 'min' ), 132 max: $( this ).attr( 'max' ), 133 step: $( this ).attr( 'step' ) 134 } ); 135 } ); 136 } 137 138 // Character Count 139 $( '.wpcf7-character-count', $form ).each( function() { 140 var $count = $( this ); 141 var name = $count.attr( 'data-target-name' ); 142 var down = $count.hasClass( 'down' ); 143 var starting = parseInt( $count.attr( 'data-starting-value' ), 10 ); 144 var maximum = parseInt( $count.attr( 'data-maximum-value' ), 10 ); 145 var minimum = parseInt( $count.attr( 'data-minimum-value' ), 10 ); 146 147 var updateCount = function( target ) { 148 var $target = $( target ); 149 var length = $target.val().length; 150 var count = down ? starting - length : length; 151 $count.attr( 'data-current-value', count ); 152 $count.text( count ); 153 154 if ( maximum && maximum < length ) { 155 $count.addClass( 'too-long' ); 156 } else { 157 $count.removeClass( 'too-long' ); 158 } 159 160 if ( minimum && length < minimum ) { 161 $count.addClass( 'too-short' ); 162 } else { 163 $count.removeClass( 'too-short' ); 164 } 165 }; 166 167 $( ':input[name="' + name + '"]', $form ).each( function() { 168 updateCount( this ); 169 170 $( this ).keyup( function() { 171 updateCount( this ); 172 } ); 173 } ); 174 } ); 175 176 // URL Input Correction 177 $form.on( 'change', '.wpcf7-validates-as-url', function() { 178 var val = $.trim( $( this ).val() ); 179 180 if ( val 181 && ! val.match( /^[a-z][a-z0-9.+-]*:/i ) 182 && -1 !== val.indexOf( '.' ) ) { 183 val = val.replace( /^\/+/, '' ); 184 val = 'http://' + val; 185 } 186 187 $( this ).val( val ); 188 } ); 189 }; 190 191 wpcf7.submit = function( form ) { 192 if ( typeof window.FormData !== 'function' ) { 193 return; 194 } 195 196 var $form = $( form ); 197 198 $( '.ajax-loader', $form ).addClass( 'is-active' ); 199 200 wpcf7.clearResponse( $form ); 201 202 var formData = new FormData( $form.get( 0 ) ); 203 204 var detail = { 205 id: $form.closest( 'div.wpcf7' ).attr( 'id' ), 206 status: 'init', 207 inputs: [], 208 formData: formData 209 }; 210 211 $.each( $form.serializeArray(), function( i, field ) { 212 if ( '_wpcf7' == field.name ) { 213 detail.contactFormId = field.value; 214 } else if ( '_wpcf7_version' == field.name ) { 215 detail.pluginVersion = field.value; 216 } else if ( '_wpcf7_locale' == field.name ) { 217 detail.contactFormLocale = field.value; 218 } else if ( '_wpcf7_unit_tag' == field.name ) { 219 detail.unitTag = field.value; 220 } else if ( '_wpcf7_container_post' == field.name ) { 221 detail.containerPostId = field.value; 222 } else if ( field.name.match( /^_wpcf7_\w+_free_text_/ ) ) { 223 var owner = field.name.replace( /^_wpcf7_\w+_free_text_/, '' ); 224 detail.inputs.push( { 225 name: owner + '-free-text', 226 value: field.value 227 } ); 228 } else if ( field.name.match( /^_/ ) ) { 229 // do nothing 230 } else { 231 detail.inputs.push( field ); 232 } 233 } ); 234 235 wpcf7.triggerEvent( $form.closest( 'div.wpcf7' ), 'beforesubmit', detail ); 236 237 var ajaxSuccess = function( data, status, xhr, $form ) { 238 detail.id = $( data.into ).attr( 'id' ); 239 detail.status = data.status; 240 detail.apiResponse = data; 241 242 var $message = $( '.wpcf7-response-output', $form ); 243 244 switch ( data.status ) { 245 case 'validation_failed': 246 $.each( data.invalidFields, function( i, n ) { 247 $( n.into, $form ).each( function() { 248 wpcf7.notValidTip( this, n.message ); 249 $( '.wpcf7-form-control', this ).addClass( 'wpcf7-not-valid' ); 250 $( '[aria-invalid]', this ).attr( 'aria-invalid', 'true' ); 251 } ); 252 } ); 253 254 $message.addClass( 'wpcf7-validation-errors' ); 255 $form.addClass( 'invalid' ); 256 257 wpcf7.triggerEvent( data.into, 'invalid', detail ); 258 break; 259 case 'acceptance_missing': 260 $message.addClass( 'wpcf7-acceptance-missing' ); 261 $form.addClass( 'unaccepted' ); 262 263 wpcf7.triggerEvent( data.into, 'unaccepted', detail ); 264 break; 265 case 'spam': 266 $message.addClass( 'wpcf7-spam-blocked' ); 267 $form.addClass( 'spam' ); 268 269 $( '[name="g-recaptcha-response"]', $form ).each( function() { 270 if ( '' === $( this ).val() ) { 271 var $recaptcha = $( this ).closest( '.wpcf7-form-control-wrap' ); 272 wpcf7.notValidTip( $recaptcha, wpcf7.recaptcha.messages.empty ); 273 } 274 } ); 275 276 wpcf7.triggerEvent( data.into, 'spam', detail ); 277 break; 278 case 'aborted': 279 $message.addClass( 'wpcf7-aborted' ); 280 $form.addClass( 'aborted' ); 281 282 wpcf7.triggerEvent( data.into, 'aborted', detail ); 283 break; 284 case 'mail_sent': 285 $message.addClass( 'wpcf7-mail-sent-ok' ); 286 $form.addClass( 'sent' ); 287 288 wpcf7.triggerEvent( data.into, 'mailsent', detail ); 289 break; 290 case 'mail_failed': 291 $message.addClass( 'wpcf7-mail-sent-ng' ); 292 $form.addClass( 'failed' ); 293 294 wpcf7.triggerEvent( data.into, 'mailfailed', detail ); 295 break; 296 default: 297 var customStatusClass = 'custom-' 298 + data.status.replace( /[^0-9a-z]+/i, '-' ); 299 $message.addClass( 'wpcf7-' + customStatusClass ); 300 $form.addClass( customStatusClass ); 301 } 302 303 wpcf7.refill( $form, data ); 304 305 wpcf7.triggerEvent( data.into, 'submit', detail ); 306 307 if ( 'mail_sent' == data.status ) { 308 $form.each( function() { 309 this.reset(); 310 } ); 311 312 wpcf7.toggleSubmit( $form ); 313 } 314 315 if ( ! wpcf7.supportHtml5.placeholder ) { 316 $form.find( '[placeholder].placeheld' ).each( function( i, n ) { 317 $( n ).val( $( n ).attr( 'placeholder' ) ); 318 } ); 319 } 320 321 $message.html( '' ).append( data.message ).slideDown( 'fast' ); 322 $message.attr( 'role', 'alert' ); 323 324 $( '.screen-reader-response', $form.closest( '.wpcf7' ) ).each( function() { 325 var $response = $( this ); 326 $response.html( '' ).attr( 'role', '' ).append( data.message ); 327 328 if ( data.invalidFields ) { 329 var $invalids = $( '<ul></ul>' ); 330 331 $.each( data.invalidFields, function( i, n ) { 332 if ( n.idref ) { 333 var $li = $( '<li></li>' ).append( $( '<a></a>' ).attr( 'href', '#' + n.idref ).append( n.message ) ); 334 } else { 335 var $li = $( '<li></li>' ).append( n.message ); 336 } 337 338 $invalids.append( $li ); 339 } ); 340
341 $response.append( $invalids ); 342 } 343 344 $response.attr( 'role', 'alert' ).focus(); 345 } ); 346 }; 347 348 $.ajax( { 349 type: 'POST', 350 url: wpcf7.apiSettings.getRoute( 351 '/contact-forms/' + wpcf7.getId( $form ) + '/feedback' ), 352 data: formData, 353 dataType: 'json', 354 processData: false, 355 contentType: false 356 } ).done( function( data, status, xhr ) { 357 ajaxSuccess( data, status, xhr, $form ); 358 $( '.ajax-loader', $form ).removeClass( 'is-active' ); 359 } ).fail( function( xhr, status, error ) { 360 var $e = $( '<div class="ajax-error"></div>' ).text( error.message ); 361 $form.after( $e ); 362 } ); 363 }; 364 365 wpcf7.triggerEvent = function( target, name, detail ) { 366 var $target = $( target ); 367 368 /* DOM event */ 369 var event = new CustomEvent( 'wpcf7' + name, { 370 bubbles: true, 371 detail: detail 372 } ); 373 374 $target.get( 0 ).dispatchEvent( event ); 375 376 /* jQuery event */ 377 $target.trigger( 'wpcf7:' + name, detail ); 378 $target.trigger( name + '.wpcf7', detail ); // deprecated 379 }; 380 381 wpcf7.toggleSubmit = function( form, state ) { 382 var $form = $( form ); 383 var $submit = $( 'input:submit', $form ); 384 385 if ( typeof state !== 'undefined' ) { 386 $submit.prop( 'disabled', ! state ); 387 return; 388 } 389 390 if ( $form.hasClass( 'wpcf7-acceptance-as-validation' ) ) { 391 return; 392 } 393 394 $submit.prop( 'disabled', false ); 395 396 $( '.wpcf7-acceptance', $form ).each( function() { 397 var $span = $( this ); 398 var $input = $( 'input:checkbox', $span ); 399 400 if ( ! $span.hasClass( 'optional' ) ) { 401 if ( $span.hasClass( 'invert' ) && $input.is( ':checked' ) 402 || ! $span.hasClass( 'invert' ) && ! $input.is( ':checked' ) ) { 403 $submit.prop( 'disabled', true ); 404 return false; 405 } 406 } 407 } ); 408 }; 409 410 wpcf7.notValidTip = function( target, message ) { 411 var $target = $( target ); 412 $( '.wpcf7-not-valid-tip', $target ).remove(); 413 $( '<span role="alert" class="wpcf7-not-valid-tip"></span>' ) 414 .text( message ).appendTo( $target ); 415 416 if ( $target.is( '.use-floating-validation-tip *' ) ) { 417 var fadeOut = function( target ) { 418 $( target ).not( ':hidden' ).animate( { 419 opacity: 0 420 }, 'fast', function() { 421 $( this ).css( { 'z-index': -100 } ); 422 } ); 423 }; 424 425 $target.on( 'mouseover', '.wpcf7-not-valid-tip', function() { 426 fadeOut( this ); 427 } ); 428 429 $target.on( 'focus', ':input', function() { 430 fadeOut( $( '.wpcf7-not-valid-tip', $target ) ); 431 } ); 432 } 433 }; 434 435 wpcf7.refill = function( form, data ) { 436 var $form = $( form ); 437 438 var refillCaptcha = function( $form, items ) { 439 $.each( items, function( i, n ) { 440 $form.find( ':input[name="' + i + '"]' ).val( '' );
441 $form.find( 'img.wpcf7-captcha-' + i ).attr( 'src', n ); 442 var match = /([0-9]+)\.(png|gif|jpeg)$/.exec( n ); 443 $form.find( 'input:hidden[name="_wpcf7_captcha_challenge_' + i + '"]' ).attr( 'value', match[ 1 ] ); 444 } ); 445 }; 446 447 var refillQuiz = function( $form, items ) { 448 $.each( items, function( i, n ) { 449 $form.find( ':input[name="' + i + '"]' ).val( '' ); 450 $form.find( ':input[name="' + i + '"]' ).siblings( 'span.wpcf7-quiz-label' ).text( n[ 0 ] ); 451 $form.find( 'input:hidden[name="_wpcf7_quiz_answer_' + i + '"]' ).attr( 'value', n[ 1 ] ); 452 } ); 453 }; 454 455 if ( typeof data === 'undefined' ) { 456 $.ajax( { 457 type: 'GET', 458 url: wpcf7.apiSettings.getRoute( 459 '/contact-forms/' + wpcf7.getId( $form ) + '/refill' ), 460 beforeSend: function( xhr ) { 461 var nonce = $form.find( ':input[name="_wpnonce"]' ).val(); 462 463 if ( nonce ) { 464 xhr.setRequestHeader( 'X-WP-Nonce', nonce ); 465 } 466 }, 467 dataType: 'json' 468 } ).done( function( data, status, xhr ) { 469 if ( data.captcha ) { 470 refillCaptcha( $form, data.captcha ); 471 } 472 473 if ( data.quiz ) { 474 refillQuiz( $form, data.quiz ); 475 } 476 } ); 477 478 } else { 479 if ( data.captcha ) { 480 refillCaptcha( $form, data.captcha ); 481 } 482 483 if ( data.quiz ) { 484 refillQuiz( $form, data.quiz ); 485 } 486 } 487 }; 488 489 wpcf7.clearResponse = function( form ) { 490 var $form = $( form ); 491 $form.removeClass( 'invalid spam sent failed' ); 492 $form.siblings( '.screen-reader-response' ).html( '' ).attr( 'role', '' ); 493 494 $( '.wpcf7-not-valid-tip', $form ).remove(); 495 $( '[aria-invalid]', $form ).attr( 'aria-invalid', 'false' ); 496 $( '.wpcf7-form-control', $form ).removeClass( 'wpcf7-not-valid' ); 497 498 $( '.wpcf7-response-output', $form ) 499 .hide().empty().removeAttr( 'role' ) 500 .removeClass( 'wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked' ); 501 }; 502 503 wpcf7.apiSettings.getRoute = function( path ) { 504 var url = wpcf7.apiSettings.root; 505 506 url = url.replace( 507 wpcf7.apiSettings.namespace, 508 wpcf7.apiSettings.namespace + path ); 509 510 return url; 511 }; 512 513} )( jQuery ); 514 515/* 516 * Polyfill for Internet Explorer 517 * See https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent 518 */ 519( function () { 520 if ( typeof window.CustomEvent === "function" ) return false; 521 522 function CustomEvent ( event, params ) { 523 params = params || { bubbles: false, cancelable: false, detail: undefined }; 524 var evt = document.createEvent( 'CustomEvent' ); 525 evt.initCustomEvent( event, 526 params.bubbles, params.cancelable, params.detail ); 527 return evt; 528 } 529 530 CustomEvent.prototype = window.Event.prototype; 531 532 window.CustomEvent = CustomEvent; 533} )();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.