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 wpcf7.triggerEvent( data.into, 'spam', detail ); 270 break; 271 case 'aborted': 272 $message.addClass( 'wpcf7-aborted' ); 273 $form.addClass( 'aborted' ); 274 275 wpcf7.triggerEvent( data.into, 'aborted', detail ); 276 break; 277 case 'mail_sent': 278 $message.addClass( 'wpcf7-mail-sent-ok' ); 279 $form.addClass( 'sent' ); 280 281 wpcf7.triggerEvent( data.into, 'mailsent', detail ); 282 break; 283 case 'mail_failed': 284 $message.addClass( 'wpcf7-mail-sent-ng' ); 285 $form.addClass( 'failed' ); 286 287 wpcf7.triggerEvent( data.into, 'mailfailed', detail ); 288 break; 289 default: 290 var customStatusClass = 'custom-' 291 + data.status.replace( /[^0-9a-z]+/i, '-' ); 292 $message.addClass( 'wpcf7-' + customStatusClass ); 293 $form.addClass( customStatusClass ); 294 } 295 296 wpcf7.refill( $form, data ); 297 298 wpcf7.triggerEvent( data.into, 'submit', detail ); 299 300 if ( 'mail_sent' == data.status ) { 301 $form.each( function() { 302 this.reset(); 303 } ); 304 305 wpcf7.toggleSubmit( $form ); 306 } 307 308 if ( ! wpcf7.supportHtml5.placeholder ) { 309 $form.find( '[placeholder].placeheld' ).each( function( i, n ) { 310 $( n ).val( $( n ).attr( 'placeholder' ) ); 311 } ); 312 } 313 314 $message.html( '' ).append( data.message ).slideDown( 'fast' ); 315 $message.attr( 'role', 'alert' ); 316 317 $( '.screen-reader-response', $form.closest( '.wpcf7' ) ).each( function() { 318 var $response = $( this ); 319 $response.html( '' ).attr( 'role', '' ).append( data.message ); 320 321 if ( data.invalidFields ) { 322 var $invalids = $( '<ul></ul>' ); 323 324 $.each( data.invalidFields, function( i, n ) { 325 if ( n.idref ) { 326 var $li = $( '<li></li>' ).append( $( '<a></a>' ).attr( 'href', '#' + n.idref ).append( n.message ) ); 327 } else { 328 var $li = $( '<li></li>' ).append( n.message ); 329 } 330 331 $invalids.append( $li ); 332 } ); 333
334 $response.append( $invalids ); 335 } 336 337 $response.attr( 'role', 'alert' ).focus(); 338 } ); 339 }; 340 341 $.ajax( { 342 type: 'POST', 343 url: wpcf7.apiSettings.getRoute( 344 '/contact-forms/' + wpcf7.getId( $form ) + '/feedback' ), 345 data: formData, 346 dataType: 'json', 347 processData: false, 348 contentType: false 349 } ).done( function( data, status, xhr ) { 350 ajaxSuccess( data, status, xhr, $form ); 351 $( '.ajax-loader', $form ).removeClass( 'is-active' ); 352 } ).fail( function( xhr, status, error ) { 353 var $e = $( '<div class="ajax-error"></div>' ).text( error.message ); 354 $form.after( $e ); 355 } ); 356 }; 357 358 wpcf7.triggerEvent = function( target, name, detail ) { 359 var $target = $( target ); 360 361 /* DOM event */ 362 var event = new CustomEvent( 'wpcf7' + name, { 363 bubbles: true, 364 detail: detail 365 } ); 366 367 $target.get( 0 ).dispatchEvent( event ); 368 369 /* jQuery event */ 370 $target.trigger( 'wpcf7:' + name, detail ); 371 $target.trigger( name + '.wpcf7', detail ); // deprecated 372 }; 373 374 wpcf7.toggleSubmit = function( form, state ) { 375 var $form = $( form ); 376 var $submit = $( 'input:submit', $form ); 377 378 if ( typeof state !== 'undefined' ) { 379 $submit.prop( 'disabled', ! state ); 380 return; 381 } 382 383 if ( $form.hasClass( 'wpcf7-acceptance-as-validation' ) ) { 384 return; 385 } 386 387 $submit.prop( 'disabled', false ); 388 389 $( '.wpcf7-acceptance', $form ).each( function() { 390 var $span = $( this ); 391 var $input = $( 'input:checkbox', $span ); 392 393 if ( ! $span.hasClass( 'optional' ) ) { 394 if ( $span.hasClass( 'invert' ) && $input.is( ':checked' ) 395 || ! $span.hasClass( 'invert' ) && ! $input.is( ':checked' ) ) { 396 $submit.prop( 'disabled', true ); 397 return false; 398 } 399 } 400 } ); 401 }; 402 403 wpcf7.notValidTip = function( target, message ) { 404 var $target = $( target ); 405 $( '.wpcf7-not-valid-tip', $target ).remove(); 406 $( '<span role="alert" class="wpcf7-not-valid-tip"></span>' ) 407 .text( message ).appendTo( $target ); 408 409 if ( $target.is( '.use-floating-validation-tip *' ) ) { 410 var fadeOut = function( target ) { 411 $( target ).not( ':hidden' ).animate( { 412 opacity: 0 413 }, 'fast', function() { 414 $( this ).css( { 'z-index': -100 } ); 415 } ); 416 }; 417 418 $target.on( 'mouseover', '.wpcf7-not-valid-tip', function() { 419 fadeOut( this ); 420 } ); 421 422 $target.on( 'focus', ':input', function() { 423 fadeOut( $( '.wpcf7-not-valid-tip', $target ) ); 424 } ); 425 } 426 }; 427 428 wpcf7.refill = function( form, data ) { 429 var $form = $( form ); 430 431 var refillCaptcha = function( $form, items ) { 432 $.each( items, function( i, n ) { 433 $form.find( ':input[name="' + i + '"]' ).val( '' );
434 $form.find( 'img.wpcf7-captcha-' + i ).attr( 'src', n ); 435 var match = /([0-9]+)\.(png|gif|jpeg)$/.exec( n ); 436 $form.find( 'input:hidden[name="_wpcf7_captcha_challenge_' + i + '"]' ).attr( 'value', match[ 1 ] ); 437 } ); 438 }; 439 440 var refillQuiz = function( $form, items ) { 441 $.each( items, function( i, n ) { 442 $form.find( ':input[name="' + i + '"]' ).val( '' ); 443 $form.find( ':input[name="' + i + '"]' ).siblings( 'span.wpcf7-quiz-label' ).text( n[ 0 ] ); 444 $form.find( 'input:hidden[name="_wpcf7_quiz_answer_' + i + '"]' ).attr( 'value', n[ 1 ] ); 445 } ); 446 }; 447 448 if ( typeof data === 'undefined' ) { 449 $.ajax( { 450 type: 'GET', 451 url: wpcf7.apiSettings.getRoute( 452 '/contact-forms/' + wpcf7.getId( $form ) + '/refill' ), 453 beforeSend: function( xhr ) { 454 var nonce = $form.find( ':input[name="_wpnonce"]' ).val(); 455 456 if ( nonce ) { 457 xhr.setRequestHeader( 'X-WP-Nonce', nonce ); 458 } 459 }, 460 dataType: 'json' 461 } ).done( function( data, status, xhr ) { 462 if ( data.captcha ) { 463 refillCaptcha( $form, data.captcha ); 464 } 465 466 if ( data.quiz ) { 467 refillQuiz( $form, data.quiz ); 468 } 469 } ); 470 471 } else { 472 if ( data.captcha ) { 473 refillCaptcha( $form, data.captcha ); 474 } 475 476 if ( data.quiz ) { 477 refillQuiz( $form, data.quiz ); 478 } 479 } 480 }; 481 482 wpcf7.clearResponse = function( form ) { 483 var $form = $( form ); 484 $form.removeClass( 'invalid spam sent failed' ); 485 $form.siblings( '.screen-reader-response' ).html( '' ).attr( 'role', '' ); 486 487 $( '.wpcf7-not-valid-tip', $form ).remove(); 488 $( '[aria-invalid]', $form ).attr( 'aria-invalid', 'false' ); 489 $( '.wpcf7-form-control', $form ).removeClass( 'wpcf7-not-valid' ); 490 491 $( '.wpcf7-response-output', $form ) 492 .hide().empty().removeAttr( 'role' ) 493 .removeClass( 'wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked' ); 494 }; 495 496 wpcf7.apiSettings.getRoute = function( path ) { 497 var url = wpcf7.apiSettings.root; 498 499 url = url.replace( 500 wpcf7.apiSettings.namespace, 501 wpcf7.apiSettings.namespace + path ); 502 503 return url; 504 }; 505 506} )( jQuery ); 507 508/* 509 * Polyfill for Internet Explorer 510 * See https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent 511 */ 512( function () { 513 if ( typeof window.CustomEvent === "function" ) return false; 514 515 function CustomEvent ( event, params ) { 516 params = params || { bubbles: false, cancelable: false, detail: undefined }; 517 var evt = document.createEvent( 'CustomEvent' ); 518 evt.initCustomEvent( event, 519 params.bubbles, params.cancelable, params.detail ); 520 return evt; 521 } 522 523 CustomEvent.prototype = window.Event.prototype; 524 525 window.CustomEvent = CustomEvent; 526} )();
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.