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.resetCounter( $form ); 140 141 // URL Input Correction 142 $form.on( 'change', '.wpcf7-validates-as-url', function() { 143 var val = $.trim( $( this ).val() ); 144 145 if ( val 146 && ! val.match( /^[a-z][a-z0-9.+-]*:/i ) 147 && -1 !== val.indexOf( '.' ) ) { 148 val = val.replace( /^\/+/, '' ); 149 val = 'http://' + val; 150 } 151 152 $( this ).val( val ); 153 } ); 154 }; 155 156 wpcf7.submit = function( form ) { 157 if ( typeof window.FormData !== 'function' ) { 158 return; 159 } 160 161 var $form = $( form ); 162 163 $( '.ajax-loader', $form ).addClass( 'is-active' ); 164 165 wpcf7.clearResponse( $form ); 166 167 var formData = new FormData( $form.get( 0 ) ); 168 169 var detail = { 170 id: $form.closest( 'div.wpcf7' ).attr( 'id' ), 171 status: 'init', 172 inputs: [], 173 formData: formData 174 }; 175 176 $.each( $form.serializeArray(), function( i, field ) { 177 if ( '_wpcf7' == field.name ) { 178 detail.contactFormId = field.value; 179 } else if ( '_wpcf7_version' == field.name ) { 180 detail.pluginVersion = field.value; 181 } else if ( '_wpcf7_locale' == field.name ) { 182 detail.contactFormLocale = field.value; 183 } else if ( '_wpcf7_unit_tag' == field.name ) { 184 detail.unitTag = field.value; 185 } else if ( '_wpcf7_container_post' == field.name ) { 186 detail.containerPostId = field.value; 187 } else if ( field.name.match( /^_wpcf7_\w+_free_text_/ ) ) { 188 var owner = field.name.replace( /^_wpcf7_\w+_free_text_/, '' ); 189 detail.inputs.push( { 190 name: owner + '-free-text', 191 value: field.value 192 } ); 193 } else if ( field.name.match( /^_/ ) ) { 194 // do nothing 195 } else { 196 detail.inputs.push( field ); 197 } 198 } ); 199 200 wpcf7.triggerEvent( $form.closest( 'div.wpcf7' ), 'beforesubmit', detail ); 201 202 var ajaxSuccess = function( data, status, xhr, $form ) { 203 detail.id = $( data.into ).attr( 'id' ); 204 detail.status = data.status; 205 detail.apiResponse = data; 206 207 var $message = $( '.wpcf7-response-output', $form ); 208 209 switch ( data.status ) { 210 case 'validation_failed': 211 $.each( data.invalidFields, function( i, n ) { 212 $( n.into, $form ).each( function() { 213 wpcf7.notValidTip( this, n.message ); 214 $( '.wpcf7-form-control', this ).addClass( 'wpcf7-not-valid' ); 215 $( '[aria-invalid]', this ).attr( 'aria-invalid', 'true' ); 216 } ); 217 } ); 218 219 $message.addClass( 'wpcf7-validation-errors' ); 220 $form.addClass( 'invalid' ); 221 222 wpcf7.triggerEvent( data.into, 'invalid', detail ); 223 break; 224 case 'acceptance_missing': 225 $message.addClass( 'wpcf7-acceptance-missing' ); 226 $form.addClass( 'unaccepted' ); 227 228 wpcf7.triggerEvent( data.into, 'unaccepted', detail ); 229 break; 230 case 'spam': 231 $message.addClass( 'wpcf7-spam-blocked' ); 232 $form.addClass( 'spam' ); 233 234 wpcf7.triggerEvent( data.into, 'spam', detail ); 235 break; 236 case 'aborted': 237 $message.addClass( 'wpcf7-aborted' ); 238 $form.addClass( 'aborted' ); 239 240 wpcf7.triggerEvent( data.into, 'aborted', detail ); 241 break; 242 case 'mail_sent': 243 $message.addClass( 'wpcf7-mail-sent-ok' ); 244 $form.addClass( 'sent' ); 245 246 wpcf7.triggerEvent( data.into, 'mailsent', detail ); 247 break; 248 case 'mail_failed': 249 $message.addClass( 'wpcf7-mail-sent-ng' ); 250 $form.addClass( 'failed' ); 251 252 wpcf7.triggerEvent( data.into, 'mailfailed', detail ); 253 break; 254 default: 255 var customStatusClass = 'custom-' 256 + data.status.replace( /[^0-9a-z]+/i, '-' ); 257 $message.addClass( 'wpcf7-' + customStatusClass ); 258 $form.addClass( customStatusClass ); 259 } 260 261 wpcf7.refill( $form, data ); 262 263 wpcf7.triggerEvent( data.into, 'submit', detail ); 264 265 if ( 'mail_sent' == data.status ) { 266 $form.each( function() { 267 this.reset(); 268 } ); 269 270 wpcf7.toggleSubmit( $form ); 271 wpcf7.resetCounter( $form ); 272 } 273 274 if ( ! wpcf7.supportHtml5.placeholder ) { 275 $form.find( '[placeholder].placeheld' ).each( function( i, n ) { 276 $( n ).val( $( n ).attr( 'placeholder' ) ); 277 } ); 278 } 279 280 $message.html( '' ).append( data.message ).slideDown( 'fast' ); 281 $message.attr( 'role', 'alert' ); 282 283 $( '.screen-reader-response', $form.closest( '.wpcf7' ) ).each( function() { 284 var $response = $( this ); 285 $response.html( '' ).attr( 'role', '' ).append( data.message ); 286 287 if ( data.invalidFields ) { 288 var $invalids = $( '<ul></ul>' ); 289 290 $.each( data.invalidFields, function( i, n ) { 291 if ( n.idref ) { 292 var $li = $( '<li></li>' ).append( $( '<a></a>' ).attr( 'href', '#' + n.idref ).append( n.message ) ); 293 } else { 294 var $li = $( '<li></li>' ).append( n.message ); 295 } 296 297 $invalids.append( $li ); 298 } ); 299
300 $response.append( $invalids ); 301 } 302 303 $response.attr( 'role', 'alert' ).focus(); 304 } ); 305 }; 306 307 $.ajax( { 308 type: 'POST', 309 url: wpcf7.apiSettings.getRoute( 310 '/contact-forms/' + wpcf7.getId( $form ) + '/feedback' ), 311 data: formData, 312 dataType: 'json', 313 processData: false, 314 contentType: false 315 } ).done( function( data, status, xhr ) { 316 ajaxSuccess( data, status, xhr, $form ); 317 $( '.ajax-loader', $form ).removeClass( 'is-active' ); 318 } ).fail( function( xhr, status, error ) { 319 var $e = $( '<div class="ajax-error"></div>' ).text( error.message ); 320 $form.after( $e ); 321 } ); 322 }; 323 324 wpcf7.triggerEvent = function( target, name, detail ) { 325 var $target = $( target ); 326 327 /* DOM event */ 328 var event = new CustomEvent( 'wpcf7' + name, { 329 bubbles: true, 330 detail: detail 331 } ); 332 333 $target.get( 0 ).dispatchEvent( event ); 334 335 /* jQuery event */ 336 $target.trigger( 'wpcf7:' + name, detail ); 337 $target.trigger( name + '.wpcf7', detail ); // deprecated 338 }; 339 340 wpcf7.toggleSubmit = function( form, state ) { 341 var $form = $( form ); 342 var $submit = $( 'input:submit', $form ); 343 344 if ( typeof state !== 'undefined' ) { 345 $submit.prop( 'disabled', ! state ); 346 return; 347 } 348 349 if ( $form.hasClass( 'wpcf7-acceptance-as-validation' ) ) { 350 return; 351 } 352 353 $submit.prop( 'disabled', false ); 354 355 $( '.wpcf7-acceptance', $form ).each( function() { 356 var $span = $( this ); 357 var $input = $( 'input:checkbox', $span ); 358 359 if ( ! $span.hasClass( 'optional' ) ) { 360 if ( $span.hasClass( 'invert' ) && $input.is( ':checked' ) 361 || ! $span.hasClass( 'invert' ) && ! $input.is( ':checked' ) ) { 362 $submit.prop( 'disabled', true ); 363 return false; 364 } 365 } 366 } ); 367 }; 368 369 wpcf7.resetCounter = function( form ) { 370 var $form = $( form ); 371 372 $( '.wpcf7-character-count', $form ).each( function() { 373 var $count = $( this ); 374 var name = $count.attr( 'data-target-name' ); 375 var down = $count.hasClass( 'down' ); 376 var starting = parseInt( $count.attr( 'data-starting-value' ), 10 ); 377 var maximum = parseInt( $count.attr( 'data-maximum-value' ), 10 ); 378 var minimum = parseInt( $count.attr( 'data-minimum-value' ), 10 ); 379 380 var updateCount = function( target ) { 381 var $target = $( target ); 382 var length = $target.val().length; 383 var count = down ? starting - length : length; 384 $count.attr( 'data-current-value', count ); 385 $count.text( count ); 386 387 if ( maximum && maximum < length ) { 388 $count.addClass( 'too-long' ); 389 } else { 390 $count.removeClass( 'too-long' ); 391 } 392 393 if ( minimum && length < minimum ) { 394 $count.addClass( 'too-short' ); 395 } else { 396 $count.removeClass( 'too-short' ); 397 } 398 }; 399 400 $( ':input[name="' + name + '"]', $form ).each( function() { 401 updateCount( this ); 402 403 $( this ).keyup( function() { 404 updateCount( this ); 405 } ); 406 } ); 407 } ); 408 }; 409 410 wpcf7.notValidTip = function( target, message ) { 411 var $target = $( target ); 412 $( '.wpcf7-not-valid-tip', $target ).remove(); 413 414 $( '<span></span>' ).attr( { 415 'class': 'wpcf7-not-valid-tip', 416 'role': 'alert', 417 'aria-hidden': 'true', 418 } ).text( message ).appendTo( $target ); 419 420 if ( $target.is( '.use-floating-validation-tip *' ) ) { 421 var fadeOut = function( target ) { 422 $( target ).not( ':hidden' ).animate( { 423 opacity: 0 424 }, 'fast', function() { 425 $( this ).css( { 'z-index': -100 } ); 426 } ); 427 }; 428 429 $target.on( 'mouseover', '.wpcf7-not-valid-tip', function() { 430 fadeOut( this ); 431 } ); 432 433 $target.on( 'focus', ':input', function() { 434 fadeOut( $( '.wpcf7-not-valid-tip', $target ) ); 435 } ); 436 } 437 }; 438 439 wpcf7.refill = function( form, data ) { 440 var $form = $( form ); 441 442 var refillCaptcha = function( $form, items ) { 443 $.each( items, function( i, n ) { 444 $form.find( ':input[name="' + i + '"]' ).val( '' );
445 $form.find( 'img.wpcf7-captcha-' + i ).attr( 'src', n ); 446 var match = /([0-9]+)\.(png|gif|jpeg)$/.exec( n ); 447 $form.find( 'input:hidden[name="_wpcf7_captcha_challenge_' + i + '"]' ).attr( 'value', match[ 1 ] ); 448 } ); 449 }; 450 451 var refillQuiz = function( $form, items ) { 452 $.each( items, function( i, n ) { 453 $form.find( ':input[name="' + i + '"]' ).val( '' ); 454 $form.find( ':input[name="' + i + '"]' ).siblings( 'span.wpcf7-quiz-label' ).text( n[ 0 ] ); 455 $form.find( 'input:hidden[name="_wpcf7_quiz_answer_' + i + '"]' ).attr( 'value', n[ 1 ] ); 456 } ); 457 }; 458 459 if ( typeof data === 'undefined' ) { 460 $.ajax( { 461 type: 'GET', 462 url: wpcf7.apiSettings.getRoute( 463 '/contact-forms/' + wpcf7.getId( $form ) + '/refill' ), 464 beforeSend: function( xhr ) { 465 var nonce = $form.find( ':input[name="_wpnonce"]' ).val(); 466 467 if ( nonce ) { 468 xhr.setRequestHeader( 'X-WP-Nonce', nonce ); 469 } 470 }, 471 dataType: 'json' 472 } ).done( function( data, status, xhr ) { 473 if ( data.captcha ) { 474 refillCaptcha( $form, data.captcha ); 475 } 476 477 if ( data.quiz ) { 478 refillQuiz( $form, data.quiz ); 479 } 480 } ); 481 482 } else { 483 if ( data.captcha ) { 484 refillCaptcha( $form, data.captcha ); 485 } 486 487 if ( data.quiz ) { 488 refillQuiz( $form, data.quiz ); 489 } 490 } 491 }; 492 493 wpcf7.clearResponse = function( form ) { 494 var $form = $( form ); 495 $form.removeClass( 'invalid spam sent failed' ); 496 $form.siblings( '.screen-reader-response' ).html( '' ).attr( 'role', '' ); 497 498 $( '.wpcf7-not-valid-tip', $form ).remove(); 499 $( '[aria-invalid]', $form ).attr( 'aria-invalid', 'false' ); 500 $( '.wpcf7-form-control', $form ).removeClass( 'wpcf7-not-valid' ); 501 502 $( '.wpcf7-response-output', $form ) 503 .hide().empty().removeAttr( 'role' ) 504 .removeClass( 'wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked' ); 505 }; 506 507 wpcf7.apiSettings.getRoute = function( path ) { 508 var url = wpcf7.apiSettings.root; 509 510 url = url.replace( 511 wpcf7.apiSettings.namespace, 512 wpcf7.apiSettings.namespace + path ); 513 514 return url; 515 }; 516 517} )( jQuery ); 518 519/* 520 * Polyfill for Internet Explorer 521 * See https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent 522 */ 523( function () { 524 if ( typeof window.CustomEvent === "function" ) return false; 525 526 function CustomEvent ( event, params ) { 527 params = params || { bubbles: false, cancelable: false, detail: undefined }; 528 var evt = document.createEvent( 'CustomEvent' ); 529 evt.initCustomEvent( event, 530 params.bubbles, params.cancelable, params.detail ); 531 return evt; 532 } 533 534 CustomEvent.prototype = window.Event.prototype; 535 536 window.CustomEvent = CustomEvent; 537} )();
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.