PageSourceSearch

https://www.totb.ro/wp-content/plugins/contact-form-7/includes/js/scripts.js?ver=5.0.3

js totb.ro collected 2026-09-24 21:23:21 UTC 14,585 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		$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				wpcf7.toggleSubmit( $form );
313			}
314
315			$form.find( '[placeholder].placeheld' ).each( function( i, n ) {
316				$( n ).val( $( n ).attr( 'placeholder' ) );
317			} );
318
319			$message.html( '' ).append( data.message ).slideDown( 'fast' );
320			$message.attr( 'role', 'alert' );
321
322			$( '.screen-reader-response', $form.closest( '.wpcf7' ) ).each( function() {
323				var $response = $( this );
324				$response.html( '' ).attr( 'role', '' ).append( data.message );
325
326				if ( data.invalidFields ) {
327					var $invalids = $( '<ul></ul>' );
328
329					$.each( data.invalidFields, function( i, n ) {
330						if ( n.idref ) {
331							var $li = $( '<li></li>' ).append( $( '<a></a>' ).attr( 'href', '#' + n.idref ).append( n.message ) );
332						} else {
333							var $li = $( '<li></li>' ).append( n.message );
334						}
335
336						$invalids.append( $li );
337					} );
338
339					$response.append( $invalids );
340				}
341
342				$response.attr( 'role', 'alert' ).focus();
343			} );
344		};
345
346		$.ajax( {
347			type: 'POST',
348			url: wpcf7.apiSettings.getRoute(
349				'/contact-forms/' + wpcf7.getId( $form ) + '/feedback' ),
350			data: formData,
351			dataType: 'json',
352			processData: false,
353			contentType: false
354		} ).done( function( data, status, xhr ) {
355			ajaxSuccess( data, status, xhr, $form );
356			$( '.ajax-loader', $form ).removeClass( 'is-active' );
357		} ).fail( function( xhr, status, error ) {
358			var $e = $( '<div class="ajax-error"></div>' ).text( error.message );
359			$form.after( $e );
360		} );
361	};
362
363	wpcf7.triggerEvent = function( target, name, detail ) {
364		var $target = $( target );
365
366		/* DOM event */
367		var event = new CustomEvent( 'wpcf7' + name, {
368			bubbles: true,
369			detail: detail
370		} );
371
372		$target.get( 0 ).dispatchEvent( event );
373
374		/* jQuery event */
375		$target.trigger( 'wpcf7:' + name, detail );
376		$target.trigger( name + '.wpcf7', detail ); // deprecated
377	};
378
379	wpcf7.toggleSubmit = function( form, state ) {
380		var $form = $( form );
381		var $submit = $( 'input:submit', $form );
382
383		if ( typeof state !== 'undefined' ) {
384			$submit.prop( 'disabled', ! state );
385			return;
386		}
387
388		if ( $form.hasClass( 'wpcf7-acceptance-as-validation' ) ) {
389			return;
390		}
391
392		$submit.prop( 'disabled', false );
393
394		$( '.wpcf7-acceptance', $form ).each( function() {
395			var $span = $( this );
396			var $input = $( 'input:checkbox', $span );
397
398			if ( ! $span.hasClass( 'optional' ) ) {
399				if ( $span.hasClass( 'invert' ) && $input.is( ':checked' )
400				|| ! $span.hasClass( 'invert' ) && ! $input.is( ':checked' ) ) {
401					$submit.prop( 'disabled', true );
402					return false;
403				}
404			}
405		} );
406	};
407
408	wpcf7.notValidTip = function( target, message ) {
409		var $target = $( target );
410		$( '.wpcf7-not-valid-tip', $target ).remove();
411		$( '<span role="alert" class="wpcf7-not-valid-tip"></span>' )
412			.text( message ).appendTo( $target );
413
414		if ( $target.is( '.use-floating-validation-tip *' ) ) {
415			var fadeOut = function( target ) {
416				$( target ).not( ':hidden' ).animate( {
417					opacity: 0
418				}, 'fast', function() {
419					$( this ).css( { 'z-index': -100 } );
420				} );
421			};
422
423			$target.on( 'mouseover', '.wpcf7-not-valid-tip', function() {
424				fadeOut( this );
425			} );
426
427			$target.on( 'focus', ':input', function() {
428				fadeOut( $( '.wpcf7-not-valid-tip', $target ) );
429			} );
430		}
431	};
432
433	wpcf7.refill = function( form, data ) {
434		var $form = $( form );
435
436		var refillCaptcha = function( $form, items ) {
437			$.each( items, function( i, n ) {
438				$form.find( ':input[name="' + i + '"]' ).val( '' );
439				$form.find( 'img.wpcf7-captcha-' + i ).attr( 'src', n );
440				var match = /([0-9]+)\.(png|gif|jpeg)$/.exec( n );
441				$form.find( 'input:hidden[name="_wpcf7_captcha_challenge_' + i + '"]' ).attr( 'value', match[ 1 ] );
442			} );
443		};
444
445		var refillQuiz = function( $form, items ) {
446			$.each( items, function( i, n ) {
447				$form.find( ':input[name="' + i + '"]' ).val( '' );
448				$form.find( ':input[name="' + i + '"]' ).siblings( 'span.wpcf7-quiz-label' ).text( n[ 0 ] );
449				$form.find( 'input:hidden[name="_wpcf7_quiz_answer_' + i + '"]' ).attr( 'value', n[ 1 ] );
450			} );
451		};
452
453		if ( typeof data === 'undefined' ) {
454			$.ajax( {
455				type: 'GET',
456				url: wpcf7.apiSettings.getRoute(
457					'/contact-forms/' + wpcf7.getId( $form ) + '/refill' ),
458				beforeSend: function( xhr ) {
459					var nonce = $form.find( ':input[name="_wpnonce"]' ).val();
460
461					if ( nonce ) {
462						xhr.setRequestHeader( 'X-WP-Nonce', nonce );
463					}
464				},
465				dataType: 'json'
466			} ).done( function( data, status, xhr ) {
467				if ( data.captcha ) {
468					refillCaptcha( $form, data.captcha );
469				}
470
471				if ( data.quiz ) {
472					refillQuiz( $form, data.quiz );
473				}
474			} );
475
476		} else {
477			if ( data.captcha ) {
478				refillCaptcha( $form, data.captcha );
479			}
480
481			if ( data.quiz ) {
482				refillQuiz( $form, data.quiz );
483			}
484		}
485	};
486
487	wpcf7.clearResponse = function( form ) {
488		var $form = $( form );
489		$form.removeClass( 'invalid spam sent failed' );
490		$form.siblings( '.screen-reader-response' ).html( '' ).attr( 'role', '' );
491
492		$( '.wpcf7-not-valid-tip', $form ).remove();
493		$( '[aria-invalid]', $form ).attr( 'aria-invalid', 'false' );
494		$( '.wpcf7-form-control', $form ).removeClass( 'wpcf7-not-valid' );
495
496		$( '.wpcf7-response-output', $form )
497			.hide().empty().removeAttr( 'role' )
498			.removeClass( 'wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked' );
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.