PageSourceSearch

https://accessibility.day/wp-content/plugins/contact-form-7/includes/js/scripts.js?ver=5.3.2

js accessibility.day collected 2026-09-24 08:28:52 UTC 14,280 bytes, 531 lines download raw bytes

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

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.