PageSourceSearch

https://www.afnil.org/wp-content/plugins/contact-form-7/includes/js/scripts.js?ver=5.0.7

js afnil.org collected 2026-10-02 04:02:52 UTC 17,692 bytes, 607 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 ( ! 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		$(".wpcf7-form").addClass("disable-btn");
200
201		wpcf7.clearResponse( $form );
202
203		var formData = new FormData( $form.get( 0 ) );
204
205		var detail = {
206			id: $form.closest( 'div.wpcf7' ).attr( 'id' ),
207			status: 'init',
208			inputs: [],
209			formData: formData
210		};
211
212		$.each( $form.serializeArray(), function( i, field ) {
213			if ( '_wpcf7' == field.name ) {
214				detail.contactFormId = field.value;
215			} else if ( '_wpcf7_version' == field.name ) {
216				detail.pluginVersion = field.value;
217			} else if ( '_wpcf7_locale' == field.name ) {
218				detail.contactFormLocale = field.value;
219			} else if ( '_wpcf7_unit_tag' == field.name ) {
220				detail.unitTag = field.value;
221			} else if ( '_wpcf7_container_post' == field.name ) {
222				detail.containerPostId = field.value;
223			} else if ( field.name.match( /^_wpcf7_\w+_free_text_/ ) ) {
224				var owner = field.name.replace( /^_wpcf7_\w+_free_text_/, '' );
225				detail.inputs.push( {
226					name: owner + '-free-text',
227					value: field.value
228				} );
229			} else if ( field.name.match( /^_/ ) ) {
230				// do nothing
231			} else {
232				detail.inputs.push( field );
233			}
234		} );
235
236		wpcf7.triggerEvent( $form.closest( 'div.wpcf7' ), 'beforesubmit', detail );
237
238		var ajaxSuccess = function( data, status, xhr, $form ) {
239			detail.id = $( data.into ).attr( 'id' );
240			detail.status = data.status;
241			detail.apiResponse = data;
242
243			var $message = $( '.wpcf7-response-output', $form );
244
245			switch ( data.status ) {
246				case 'validation_failed':
247					$.each( data.invalidFields, function( i, n ) {
248						$( n.into, $form ).each( function() {
249							wpcf7.notValidTip( this, n.message );
250							$( '.wpcf7-form-control', this ).addClass( 'wpcf7-not-valid' );
251							if($( '.wpcf7-form-control', this ).parent().hasClass('custom-select-container')) {
252                                $( '.wpcf7-form-control', this ).parent().addClass( 'wpcf7-not-valid' );
253							}
254							$( '[aria-invalid]', this ).attr( 'aria-invalid', 'true' );
255						} );
256					} );
257
258					$message.addClass( 'wpcf7-validation-errors' );
259					$form.addClass( 'invalid' );
260
261					wpcf7.triggerEvent( data.into, 'invalid', detail );
262					break;
263				case 'acceptance_missing':
264					$message.addClass( 'wpcf7-acceptance-missing' );
265					$form.addClass( 'unaccepted' );
266
267					wpcf7.triggerEvent( data.into, 'unaccepted', detail );
268					break;
269				case 'spam':
270					$message.addClass( 'wpcf7-spam-blocked' );
271					$form.addClass( 'spam' );
272
273					$( '[name="g-recaptcha-response"]', $form ).each( function() {
274						if ( '' === $( this ).val() ) {
275							var $recaptcha = $( this ).closest( '.wpcf7-form-control-wrap' );
276							wpcf7.notValidTip( $recaptcha, wpcf7.recaptcha.messages.empty );
277						}
278					} );
279
280					wpcf7.triggerEvent( data.into, 'spam', detail );
281					break;
282				case 'aborted':
283					$message.addClass( 'wpcf7-aborted' );
284					$form.addClass( 'aborted' );
285
286					wpcf7.triggerEvent( data.into, 'aborted', detail );
287					break;
288				case 'mail_sent':
289					$message.addClass( 'wpcf7-mail-sent-ok' );
290					$form.addClass( 'sent' );
291
292					//add form content filled
293					var $form = $('.wpcf7-form');
294
295					$('.wpcf7-form').after('<div class="form_content hidden" id="form_submission_content">' + $form.html() + '</div>');
296
297					$('#form_submission_content').find('.article-info').closest('div[class*="col-md"] ').remove();
298					$('#form_submission_content').find('.wpcf7-recaptcha').remove();
299					$('#form_submission_content').find('.codedropz-upload-handler').remove();
300					$('#form_submission_content').find('input[type="button"]').remove();
301					$('#form_submission_content').find('input[type="submit"]').remove();
302
303
304					$.each($(".wpcf7-form input[type='text'],.wpcf7-form input[type='tel'],.wpcf7-form input[type='number'],.wpcf7-form input[type='url'],.wpcf7-form input[type='email']"), function () {
305						var name = $(this).attr('name');
306						var value = $(this).val();
307						var $element = $('#form_submission_content').find('input[name="' + name + '"]');
308
309						var $parent = $element.parent();
310						if (value !== '') {
311							$parent.append('<div class="value_field">' + value + '</div>');
312						} else {
313							$parent.append('<div class="value_field">&nbsp;</div>');
314						}
315						$element.remove();
316					});
317
318					$.each($(".wpcf7-form input[type='radio'], .wpcf7-form input[type='checkbox']"), function () {
319						var name = $(this).attr('name');
320						var value = $(this).val();
321						var $element = $('#form_submission_content').find('input[name="' + name + '"][value="' + value + '"]');
322
323						var $parent = $element.closest('.wpcf7-list-item');
324						if ($(this).is(':checked')) {
325							$parent.empty();
326							$parent.append('<div class="value_field">' + value + '</div>');
327						} else {
328							$parent.remove();
329						}
330					});
331
332					$.each($(".wpcf7-form select"), function () {
333						var name = $(this).attr('name');
334						var value = $(this).children("option:selected").val();
335						var $element = $('#form_submission_content').find('select[name="' + name + '"]');
336
337						var $parent = $element.parent();
338						$parent.empty();
339						$parent.append('<div class="value_field">' + value + '</div>');
340
341					});
342
343					$.each($(".wpcf7-form textarea"), function () {
344						var name = $(this).attr('name');
345						var value = $(this).val();
346						var $element = $('#form_submission_content').find('textarea[name="' + name + '"]');
347
348						var $parent = $element.parent();
349						$parent.empty();
350						$parent.append('<div class="value_field">' + value + '</div>');
351					});
352
353					$.each($("#form_submission_content input[type='file']"), function () {
354						$(this).remove();
355					});
356
357					var data_form = $('#form_submission_content').html();
358
359					formData.append('content_form', data_form);
360
361					wpcf7.triggerEvent( data.into, 'mailsent', detail );
362					break;
363				case 'mail_failed':
364					$message.addClass( 'wpcf7-mail-sent-ng' );
365					$form.addClass( 'failed' );
366
367					wpcf7.triggerEvent( data.into, 'mailfailed', detail );
368					break;
369				default:
370					var customStatusClass = 'custom-'
371						+ data.status.replace( /[^0-9a-z]+/i, '-' );
372					$message.addClass( 'wpcf7-' + customStatusClass );
373					$form.addClass( customStatusClass );
374			}
375
376			wpcf7.refill( $form, data );
377
378			wpcf7.triggerEvent( data.into, 'submit', detail );
379
380			if ( 'mail_sent' == data.status ) {
381				$form.each( function() {
382					this.reset();
383				} );
384
385				wpcf7.toggleSubmit( $form );
386			}
387
388			if ( ! wpcf7.supportHtml5.placeholder ) {
389				$form.find( '[placeholder].placeheld' ).each( function( i, n ) {
390					$( n ).val( $( n ).attr( 'placeholder' ) );
391				} );
392			}
393
394			$message.html( '' ).append( data.message ).slideDown( 'fast' );
395			$message.attr( 'role', 'alert' );
396
397			$( '.screen-reader-response', $form.closest( '.wpcf7' ) ).each( function() {
398				var $response = $( this );
399				$response.html( '' ).attr( 'role', '' ).append( data.message );
400
401				if ( data.invalidFields ) {
402					var $invalids = $( '<ul></ul>' );
403
404					$.each( data.invalidFields, function( i, n ) {
405						if ( n.idref ) {
406							var $li = $( '<li></li>' ).append( $( '<a></a>' ).attr( 'href', '#' + n.idref ).append( n.message ) );
407						} else {
408							var $li = $( '<li></li>' ).append( n.message );
409						}
410
411						$invalids.append( $li );
412					} );
413
414					$response.append( $invalids );
415				}
416
417				$response.attr( 'role', 'alert' ).focus();
418			} );
419		};
420
421		$.ajax( {
422			type: 'POST',
423			url: wpcf7.apiSettings.getRoute(
424				'/contact-forms/' + wpcf7.getId( $form ) + '/feedback' ),
425			data: formData,
426			dataType: 'json',
427			processData: false,
428			contentType: false
429		} ).done( function( data, status, xhr ) {
430			ajaxSuccess( data, status, xhr, $form );
431			$( '.ajax-loader', $form ).removeClass( 'is-active' );
432			$(".wpcf7-form").removeClass("disable-btn");
433		} ).fail( function( xhr, status, error ) {
434			var $e = $( '<div class="ajax-error"></div>' ).text( error.message );
435			$form.after( $e );
436		} );
437	};
438
439	wpcf7.triggerEvent = function( target, name, detail ) {
440		var $target = $( target );
441
442		/* DOM event */
443		var event = new CustomEvent( 'wpcf7' + name, {
444			bubbles: true,
445			detail: detail
446		} );
447
448		$target.get( 0 ).dispatchEvent( event );
449
450		/* jQuery event */
451		$target.trigger( 'wpcf7:' + name, detail );
452		$target.trigger( name + '.wpcf7', detail ); // deprecated
453	};
454
455	wpcf7.toggleSubmit = function( form, state ) {
456		var $form = $( form );
457		var $submit = $( 'input:submit', $form );
458
459		if ( typeof state !== 'undefined' ) {
460			$submit.prop( 'disabled', ! state );
461			return;
462		}
463
464		if ( $form.hasClass( 'wpcf7-acceptance-as-validation' ) ) {
465			return;
466		}
467
468		$submit.prop( 'disabled', false );
469
470		$( '.wpcf7-acceptance', $form ).each( function() {
471			var $span = $( this );
472			var $input = $( 'input:checkbox', $span );
473
474			if ( ! $span.hasClass( 'optional' ) ) {
475				if ( $span.hasClass( 'invert' ) && $input.is( ':checked' )
476				|| ! $span.hasClass( 'invert' ) && ! $input.is( ':checked' ) ) {
477					$submit.prop( 'disabled', true );
478					return false;
479				}
480			}
481		} );
482	};
483
484	wpcf7.notValidTip = function( target, message ) {
485		var $target = $( target );
486		$( '.wpcf7-not-valid-tip', $target ).remove();
487		$( '<span role="alert" class="wpcf7-not-valid-tip"></span>' )
488			.text( message ).appendTo( $target );
489
490		if ( $target.is( '.use-floating-validation-tip *' ) ) {
491			var fadeOut = function( target ) {
492				$( target ).not( ':hidden' ).animate( {
493					opacity: 0
494				}, 'fast', function() {
495					$( this ).css( { 'z-index': -100 } );
496				} );
497			};
498
499			$target.on( 'mouseover', '.wpcf7-not-valid-tip', function() {
500				fadeOut( this );
501			} );
502
503			$target.on( 'focus', ':input', function() {
504				fadeOut( $( '.wpcf7-not-valid-tip', $target ) );
505			} );
506		}
507	};
508
509	wpcf7.refill = function( form, data ) {
510		var $form = $( form );
511
512		var refillCaptcha = function( $form, items ) {
513			$.each( items, function( i, n ) {
514				$form.find( ':input[name="' + i + '"]' ).val( '' );
515				$form.find( 'img.wpcf7-captcha-' + i ).attr( 'src', n );
516				var match = /([0-9]+)\.(png|gif|jpeg)$/.exec( n );
517				$form.find( 'input:hidden[name="_wpcf7_captcha_challenge_' + i + '"]' ).attr( 'value', match[ 1 ] );
518			} );
519		};
520
521		var refillQuiz = function( $form, items ) {
522			$.each( items, function( i, n ) {
523				$form.find( ':input[name="' + i + '"]' ).val( '' );
524				$form.find( ':input[name="' + i + '"]' ).siblings( 'span.wpcf7-quiz-label' ).text( n[ 0 ] );
525				$form.find( 'input:hidden[name="_wpcf7_quiz_answer_' + i + '"]' ).attr( 'value', n[ 1 ] );
526			} );
527		};
528
529		if ( typeof data === 'undefined' ) {
530			$.ajax( {
531				type: 'GET',
532				url: wpcf7.apiSettings.getRoute(
533					'/contact-forms/' + wpcf7.getId( $form ) + '/refill' ),
534				beforeSend: function( xhr ) {
535					var nonce = $form.find( ':input[name="_wpnonce"]' ).val();
536
537					if ( nonce ) {
538						xhr.setRequestHeader( 'X-WP-Nonce', nonce );
539					}
540				},
541				dataType: 'json'
542			} ).done( function( data, status, xhr ) {
543				if ( data.captcha ) {
544					refillCaptcha( $form, data.captcha );
545				}
546
547				if ( data.quiz ) {
548					refillQuiz( $form, data.quiz );
549				}
550			} );
551
552		} else {
553			if ( data.captcha ) {
554				refillCaptcha( $form, data.captcha );
555			}
556
557			if ( data.quiz ) {
558				refillQuiz( $form, data.quiz );
559			}
560		}
561	};
562
563	wpcf7.clearResponse = function( form ) {
564		var $form = $( form );
565		$form.removeClass( 'invalid spam sent failed' );
566		$form.siblings( '.screen-reader-response' ).html( '' ).attr( 'role', '' );
567
568		$( '.wpcf7-not-valid-tip', $form ).remove();
569		$( '[aria-invalid]', $form ).attr( 'aria-invalid', 'false' );
570		$( '.wpcf7-form-control', $form ).removeClass( 'wpcf7-not-valid' );
571
572		$( '.wpcf7-response-output', $form )
573			.hide().empty().removeAttr( 'role' )
574			.removeClass( 'wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked' );
575	};
576
577	wpcf7.apiSettings.getRoute = function( path ) {
578		var url = wpcf7.apiSettings.root;
579
580		url = url.replace(
581			wpcf7.apiSettings.namespace,
582			wpcf7.apiSettings.namespace + path );
583
584		return url;
585	};
586
587} )( jQuery );
588
589/*
590 * Polyfill for Internet Explorer
591 * See https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
592 */
593( function () {
594	if ( typeof window.CustomEvent === "function" ) return false;
595
596	function CustomEvent ( event, params ) {
597		params = params || { bubbles: false, cancelable: false, detail: undefined };
598		var evt = document.createEvent( 'CustomEvent' );
599		evt.initCustomEvent( event,
600			params.bubbles, params.cancelable, params.detail );
601		return evt;
602	}
603
604	CustomEvent.prototype = window.Event.prototype;
605
606	window.CustomEvent = CustomEvent;
607} )();

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.