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 ( typeof window.FormData !== 'function' ) { 50 return; 51 } 52 53 wpcf7.submit( $form ); 54 event.preventDefault(); 55 } ); 56 57 $( '.wpcf7-submit', $form ).after( '<span class="ajax-loader"></span>' ); 58 59 wpcf7.toggleSubmit( $form ); 60 61 $form.on( 'click', '.wpcf7-acceptance', function() { 62 wpcf7.toggleSubmit( $form ); 63 } ); 64 65 // Exclusive Checkbox 66 $( '.wpcf7-exclusive-checkbox', $form ).on( 'click', 'input:checkbox', function() { 67 var name = $( this ).attr( 'name' );
68 $form.find( 'input:checkbox[name="' + name + '"]' ).not( this ).prop( 'checked', false ); 69 } ); 70 71 // Free Text Option for Checkboxes and Radio Buttons 72 $( '.wpcf7-list-item.has-free-text', $form ).each( function() { 73 var $freetext = $( ':input.wpcf7-free-text', this ); 74 var $wrap = $( this ).closest( '.wpcf7-form-control' ); 75 76 if ( $( ':checkbox, :radio', this ).is( ':checked' ) ) { 77 $freetext.prop( 'disabled', false ); 78 } else { 79 $freetext.prop( 'disabled', true ); 80 } 81 82 $wrap.on( 'change', ':checkbox, :radio', function() { 83 var $cb = $( '.has-free-text', $wrap ).find( ':checkbox, :radio' ); 84 85 if ( $cb.is( ':checked' ) ) { 86 $freetext.prop( 'disabled', false ).focus(); 87 } else { 88 $freetext.prop( 'disabled', true ); 89 } 90 } ); 91 } ); 92 93 // Placeholder Fallback 94 if ( ! wpcf7.supportHtml5.placeholder ) { 95 $( '[placeholder]', $form ).each( function() { 96 $( this ).val( $( this ).attr( 'placeholder' ) ); 97 $( this ).addClass( 'placeheld' ); 98 99 $( this ).focus( function() { 100 if ( $( this ).hasClass( 'placeheld' ) ) { 101 $( this ).val( '' ).removeClass( 'placeheld' ); 102 } 103 } ); 104 105 $( this ).blur( function() { 106 if ( '' === $( this ).val() ) { 107 $( this ).val( $( this ).attr( 'placeholder' ) ); 108 $( this ).addClass( 'placeheld' ); 109 } 110 } ); 111 } ); 112 } 113 114 if ( wpcf7.jqueryUi && ! wpcf7.supportHtml5.date ) {
115 $form.find( 'input.wpcf7-date[type="date"]' ).each( function() { 116 $( this ).datepicker( { 117 dateFormat: 'yy-mm-dd', 118 minDate: new Date( $( this ).attr( 'min' ) ), 119 maxDate: new Date( $( this ).attr( 'max' ) ) 120 } ); 121 } ); 122 } 123 124 if ( wpcf7.jqueryUi && ! wpcf7.supportHtml5.number ) { 125 $form.find( 'input.wpcf7-number[type="number"]' ).each( function() { 126 $( this ).spinner( { 127 min: $( this ).attr( 'min' ), 128 max: $( this ).attr( 'max' ), 129 step: $( this ).attr( 'step' ) 130 } ); 131 } ); 132 } 133 134 // Character Count 135 $( '.wpcf7-character-count', $form ).each( function() { 136 var $count = $( this ); 137 var name = $count.attr( 'data-target-name' ); 138 var down = $count.hasClass( 'down' ); 139 var starting = parseInt( $count.attr( 'data-starting-value' ), 10 ); 140 var maximum = parseInt( $count.attr( 'data-maximum-value' ), 10 ); 141 var minimum = parseInt( $count.attr( 'data-minimum-value' ), 10 ); 142 143 var updateCount = function( target ) { 144 var $target = $( target ); 145 var length = $target.val().length; 146 var count = down ? starting - length : length; 147 $count.attr( 'data-current-value', count ); 148 $count.text( count ); 149 150 if ( maximum && maximum < length ) { 151 $count.addClass( 'too-long' ); 152 } else { 153 $count.removeClass( 'too-long' ); 154 } 155 156 if ( minimum && length < minimum ) { 157 $count.addClass( 'too-short' ); 158 } else { 159 $count.removeClass( 'too-short' ); 160 } 161 }; 162 163 $( ':input[name="' + name + '"]', $form ).each( function() { 164 updateCount( this ); 165 166 $( this ).keyup( function() { 167 updateCount( this ); 168 } ); 169 } ); 170 } ); 171 172 // URL Input Correction 173 $form.on( 'change', '.wpcf7-validates-as-url', function() { 174 var val = $.trim( $( this ).val() ); 175 176 if ( val 177 && ! val.match( /^[a-z][a-z0-9.+-]*:/i ) 178 && -1 !== val.indexOf( '.' ) ) { 179 val = val.replace( /^\/+/, '' ); 180 val = 'http://' + val; 181 } 182 183 $( this ).val( val ); 184 } ); 185 }; 186 187 wpcf7.submit = function( form ) { 188 if ( typeof window.FormData !== 'function' ) { 189 return; 190 } 191 192 var $form = $( form ); 193 194 $( '.ajax-loader', $form ).addClass( 'is-active' ); 195 196 $( '[placeholder].placeheld', $form ).each( function( i, n ) { 197 $( n ).val( '' ); 198 } ); 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 313 $form.find( '[placeholder].placeheld' ).each( function( i, n ) { 314 $( n ).val( $( n ).attr( 'placeholder' ) ); 315 } ); 316 317 $message.html( '' ).append( data.message ).slideDown( 'fast' ); 318 $message.attr( 'role', 'alert' ); 319 320 $( '.screen-reader-response', $form.closest( '.wpcf7' ) ).each( function() { 321 var $response = $( this ); 322 $response.html( '' ).attr( 'role', '' ).append( data.message ); 323 324 if ( data.invalidFields ) { 325 var $invalids = $( '<ul></ul>' ); 326 327 $.each( data.invalidFields, function( i, n ) { 328 if ( n.idref ) { 329 var $li = $( '<li></li>' ).append( $( '<a></a>' ).attr( 'href', '#' + n.idref ).append( n.message ) ); 330 } else { 331 var $li = $( '<li></li>' ).append( n.message ); 332 } 333 334 $invalids.append( $li ); 335 } ); 336
337 $response.append( $invalids ); 338 } 339 340 $response.attr( 'role', 'alert' ).focus(); 341 } ); 342 }; 343 344 $.ajax( { 345 type: 'POST', 346 url: wpcf7.apiSettings.getRoute( 347 '/contact-forms/' + wpcf7.getId( $form ) + '/feedback' ), 348 data: formData, 349 dataType: 'json', 350 processData: false, 351 contentType: false 352 } ).done( function( data, status, xhr ) { 353 ajaxSuccess( data, status, xhr, $form ); 354 $( '.ajax-loader', $form ).removeClass( 'is-active' ); 355 } ).fail( function( xhr, status, error ) { 356 var $e = $( '<div class="ajax-error"></div>' ).text( error.message ); 357 $form.after( $e ); 358 } ); 359 }; 360 361 wpcf7.triggerEvent = function( target, name, detail ) { 362 var $target = $( target ); 363 364 /* DOM event */ 365 var event = new CustomEvent( 'wpcf7' + name, { 366 bubbles: true, 367 detail: detail 368 } ); 369 370 $target.get( 0 ).dispatchEvent( event ); 371 372 /* jQuery event */ 373 $target.trigger( 'wpcf7:' + name, detail ); 374 $target.trigger( name + '.wpcf7', detail ); // deprecated 375 }; 376 377 wpcf7.toggleSubmit = function( form, state ) { 378 var $form = $( form ); 379 var $submit = $( 'input:submit', $form ); 380 381 if ( typeof state !== 'undefined' ) { 382 $submit.prop( 'disabled', ! state ); 383 return; 384 } 385 386 if ( $form.hasClass( 'wpcf7-acceptance-as-validation' ) ) { 387 return; 388 } 389 390 $submit.prop( 'disabled', false ); 391 392 $( '.wpcf7-acceptance', $form ).each( function() { 393 var $span = $( this ); 394 var $input = $( 'input:checkbox', $span ); 395 396 if ( ! $span.hasClass( 'optional' ) ) { 397 if ( $span.hasClass( 'invert' ) && $input.is( ':checked' ) 398 || ! $span.hasClass( 'invert' ) && ! $input.is( ':checked' ) ) { 399 $submit.prop( 'disabled', true ); 400 return false; 401 } 402 } 403 } ); 404 }; 405 406 wpcf7.notValidTip = function( target, message ) { 407 var $target = $( target ); 408 $( '.wpcf7-not-valid-tip', $target ).remove(); 409 $( '<span role="alert" class="wpcf7-not-valid-tip"></span>' ) 410 .text( message ).appendTo( $target ); 411 412 if ( $target.is( '.use-floating-validation-tip *' ) ) { 413 var fadeOut = function( target ) { 414 $( target ).not( ':hidden' ).animate( { 415 opacity: 0 416 }, 'fast', function() { 417 $( this ).css( { 'z-index': -100 } ); 418 } ); 419 }; 420 421 $target.on( 'mouseover', '.wpcf7-not-valid-tip', function() { 422 fadeOut( this ); 423 } ); 424 425 $target.on( 'focus', ':input', function() { 426 fadeOut( $( '.wpcf7-not-valid-tip', $target ) ); 427 } ); 428 } 429 }; 430 431 wpcf7.refill = function( form, data ) { 432 var $form = $( form ); 433 434 var refillCaptcha = function( $form, items ) { 435 $.each( items, function( i, n ) { 436 $form.find( ':input[name="' + i + '"]' ).val( '' );
437 $form.find( 'img.wpcf7-captcha-' + i ).attr( 'src', n ); 438 var match = /([0-9]+)\.(png|gif|jpeg)$/.exec( n ); 439 $form.find( 'input:hidden[name="_wpcf7_captcha_challenge_' + i + '"]' ).attr( 'value', match[ 1 ] ); 440 } ); 441 }; 442 443 var refillQuiz = function( $form, items ) { 444 $.each( items, function( i, n ) { 445 $form.find( ':input[name="' + i + '"]' ).val( '' ); 446 $form.find( ':input[name="' + i + '"]' ).siblings( 'span.wpcf7-quiz-label' ).text( n[ 0 ] ); 447 $form.find( 'input:hidden[name="_wpcf7_quiz_answer_' + i + '"]' ).attr( 'value', n[ 1 ] ); 448 } ); 449 }; 450 451 if ( typeof data === 'undefined' ) { 452 $.ajax( { 453 type: 'GET', 454 url: wpcf7.apiSettings.getRoute( 455 '/contact-forms/' + wpcf7.getId( $form ) + '/refill' ), 456 beforeSend: function( xhr ) { 457 var nonce = $form.find( ':input[name="_wpnonce"]' ).val(); 458 459 if ( nonce ) { 460 xhr.setRequestHeader( 'X-WP-Nonce', nonce ); 461 } 462 }, 463 dataType: 'json' 464 } ).done( function( data, status, xhr ) { 465 if ( data.captcha ) { 466 refillCaptcha( $form, data.captcha ); 467 } 468 469 if ( data.quiz ) { 470 refillQuiz( $form, data.quiz ); 471 } 472 } ); 473 474 } else { 475 if ( data.captcha ) { 476 refillCaptcha( $form, data.captcha ); 477 } 478 479 if ( data.quiz ) { 480 refillQuiz( $form, data.quiz ); 481 } 482 } 483 }; 484 485 wpcf7.clearResponse = function( form ) { 486 var $form = $( form ); 487 $form.removeClass( 'invalid spam sent failed' ); 488 $form.siblings( '.screen-reader-response' ).html( '' ).attr( 'role', '' ); 489 490 $( '.wpcf7-not-valid-tip', $form ).remove(); 491 $( '[aria-invalid]', $form ).attr( 'aria-invalid', 'false' ); 492 $( '.wpcf7-form-control', $form ).removeClass( 'wpcf7-not-valid' ); 493 494 $( '.wpcf7-response-output', $form ) 495 .hide().empty().removeAttr( 'role' ) 496 .removeClass( 'wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked' ); 497 }; 498 499 wpcf7.apiSettings.getRoute = function( path ) { 500 var url = wpcf7.apiSettings.root; 501 502 url = url.replace( 503 wpcf7.apiSettings.namespace, 504 wpcf7.apiSettings.namespace + path ); 505 506 return url; 507 }; 508 509} )( jQuery ); 510 511/* 512 * Polyfill for Internet Explorer 513 * See https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent 514 */ 515( function () { 516 if ( typeof window.CustomEvent === "function" ) return false; 517 518 function CustomEvent ( event, params ) { 519 params = params || { bubbles: false, cancelable: false, detail: undefined }; 520 var evt = document.createEvent( 'CustomEvent' ); 521 evt.initCustomEvent( event, 522 params.bubbles, params.cancelable, params.detail ); 523 return evt; 524 } 525 526 CustomEvent.prototype = window.Event.prototype; 527 528 window.CustomEvent = CustomEvent; 529} )();
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.