PageSourceSearch

https://oabeilles.net/wp-content/plugins/contact-form-7/includes/js/scripts.js?ver=4.9.2

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

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.