PageSourceSearch

https://primariacampulung.ro/js/views/view.contact.js

js primariacampulung.ro collected 2026-10-02 13:12:17 UTC 7,650 bytes, 280 lines download raw bytes

1/*
2Name: 			View - Contact
3Written by: 	Okler Themes - (http://www.okler.net)
4Theme Version:	9.2.0
5*/
6
7(function($) {
8
9	'use strict';
10
11	/*
12	Custom Rules
13	*/
14	
15	// No White Space
16	$.validator.addMethod("noSpace", function(value, element) {
17		if( $(element).attr('required') ) {
18			return value.search(/^(?! *$)[^]+$/) == 0;
19		}
20
21		return true;
22	}, 'Please fill this empty field.');
23
24	/*
25	Assign Custom Rules on Fields
26	*/
27	$.validator.addClassRules({
28	    'form-control': {
29	        noSpace: true
30	    }
31	});
32
33	/*
34	Contact Form: Basic
35	*/
36	$('.contact-form').each(function(){
37		$(this).validate({
38			errorPlacement: function(error, element) {
39				if(element.attr('type') == 'radio' || element.attr('type') == 'checkbox') {
40					error.appendTo(element.closest('.form-group'));
41				} else if( element.is('select') && element.closest('.custom-select-1') ) {
42					error.appendTo(element.closest('.form-group'));
43				} else {
44					if( element.closest('.form-group').length ) {
45						error.appendTo(element.closest('.form-group'));
46					} else {
47						error.insertAfter(element);
48					}
49				}
50			},
51			submitHandler: function(form) {
52
53				var $form = $(form),
54					$messageSuccess = $form.find('.contact-form-success'),
55					$messageError = $form.find('.contact-form-error'),
56					$submitButton = $(this.submitButton),
57					$errorMessage = $form.find('.mail-error-message'),
58					submitButtonText = $submitButton.val();
59
60				$submitButton.val( $submitButton.data('loading-text') ? $submitButton.data('loading-text') : 'Loading...' ).attr('disabled', true);
61
62				// Fields Data
63				var formData = $form.serializeArray(),
64					data = {};
65
66				$(formData).each(function(index, obj){
67					if( data[obj.name] ) {
68						data[obj.name] = data[obj.name] + ', ' + obj.value;						
69					} else {
70						data[obj.name] = obj.value;
71					}
72				});
73
74				// Google Recaptcha v2
75				if( data["g-recaptcha-response"] != undefined ) {
76					data["g-recaptcha-response"] = $form.find('#g-recaptcha-response').val();
77				}
78
79				// Ajax Submit
80				$.ajax({
81					type: 'POST',
82					url: $form.attr('action'),
83					data: data
84				}).always(function(data, textStatus, jqXHR) {
85
86					$errorMessage.empty().hide();
87
88					if (data.response == 'success') {
89
90						// Uncomment the code below to redirect for a thank you page
91						// self.location = 'thank-you.html';
92
93						$messageSuccess.removeClass('d-none');
94						$messageError.addClass('d-none');
95
96						// Reset Form
97						$form.find('.form-control')
98							.val('')
99							.blur()
100							.parent()
101							.removeClass('has-success')
102							.removeClass('has-danger')
103							.find('label.error')
104							.remove();
105
106						if (($messageSuccess.offset().top - 80) < $(window).scrollTop()) {
107							$('html, body').animate({
108								scrollTop: $messageSuccess.offset().top - 80
109							}, 300);
110						}
111
112						$form.find('.form-control').removeClass('error');
113
114						$submitButton.val( submitButtonText ).attr('disabled', false);
115						
116						return;
117
118					} else if (data.response == 'error' && typeof data.errorMessage !== 'undefined') {
119						$errorMessage.html(data.errorMessage).show();
120					} else {
121						$errorMessage.html(data.responseText).show();
122					}
123
124					$messageError.removeClass('d-none');
125					$messageSuccess.addClass('d-none');
126
127					if (($messageError.offset().top - 80) < $(window).scrollTop()) {
128						$('html, body').animate({
129							scrollTop: $messageError.offset().top - 80
130						}, 300);
131					}
132
133					$form.find('.has-success')
134						.removeClass('has-success');
135						
136					$submitButton.val( submitButtonText ).attr('disabled', false);
137
138				});
139			}
140		});
141	});
142
143	/*
144	Contact Form: Advanced
145	*/
146	$('#contactFormAdvanced').validate({
147		onkeyup: false,
148		onclick: false,
149		onfocusout: false,
150		rules: {
151			'captcha': {
152				captcha: true
153			},
154			'checkboxes[]': {
155				required: true
156			},
157			'radios': {
158				required: true
159			}
160		},
161		errorPlacement: function(error, element) {
162			if(element.attr('type') == 'radio' || element.attr('type') == 'checkbox') {
163				error.appendTo(element.closest('.form-group'));
164			} else if( element.is('select') && element.closest('.custom-select-1') ) {
165				error.appendTo(element.closest('.form-group'));
166			} else {
167				error.insertAfter(element);
168			}
169		}
170	});
171
172	/*
173	Contact Form: reCaptcha v3
174	*/
175	$('.contact-form-recaptcha-v3').each(function(){
176		$(this).validate({
177			errorPlacement: function(error, element) {
178				if(element.attr('type') == 'radio' || element.attr('type') == 'checkbox') {
179					error.appendTo(element.closest('.form-group'));
180				} else if( element.is('select') && element.closest('.custom-select-1') ) {
181					error.appendTo(element.closest('.form-group'));
182				} else {
183					error.insertAfter(element);
184				}
185			},
186			submitHandler: function(form) {
187
188				var $form = $(form),
189					$messageSuccess = $form.find('.contact-form-success'),
190					$messageError = $form.find('.contact-form-error'),
191					$submitButton = $(this.submitButton),
192					$errorMessage = $form.find('.mail-error-message'),
193					submitButtonText = $submitButton.val();
194
195				$submitButton.val( $submitButton.data('loading-text') ? $submitButton.data('loading-text') : 'Loading...' ).attr('disabled', true);
196
197				var recaptchaSrcURL = $('#google-recaptcha-v3').attr('src'),
198					newURL          = new URL(recaptchaSrcURL),
199					site_key        = newURL.searchParams.get("render");
200
201				grecaptcha.execute(site_key, {action: 'contact_us'}).then(function(token) {
202
203					// Fields Data
204					var formData = $form.serializeArray(),
205						data = {};
206
207					$(formData).each(function(index, obj){
208					    data[obj.name] = obj.value;
209					});
210
211					// Recaptcha v3 Token
212					data["g-recaptcha-response"] = token;
213
214					// Ajax Submit
215					$.ajax({
216						type: 'POST',
217						url: $form.attr('action'),
218						data: data
219					}).always(function(data, textStatus, jqXHR) {
220
221						$errorMessage.empty().hide();
222
223						if (data.response == 'success') {
224
225							// Uncomment the code below to redirect for a thank you page
226							// self.location = 'thank-you.html';
227
228							$messageSuccess.removeClass('d-none');
229							$messageError.addClass('d-none');
230
231							// Reset Form
232							$form.find('.form-control')
233								.val('')
234								.blur()
235								.parent()
236								.removeClass('has-success')
237								.removeClass('has-danger')
238								.find('label.error')
239								.remove();
240
241							if (($messageSuccess.offset().top - 80) < $(window).scrollTop()) {
242								$('html, body').animate({
243									scrollTop: $messageSuccess.offset().top - 80
244								}, 300);
245							}
246
247							$form.find('.form-control').removeClass('error');
248
249							$submitButton.val( submitButtonText ).attr('disabled', false);
250							
251							return;
252
253						} else if (data.response == 'error' && typeof data.errorMessage !== 'undefined') {
254							$errorMessage.html(data.errorMessage).show();
255						} else {
256							$errorMessage.html(data.responseText).show();
257						}
258
259						$messageError.removeClass('d-none');
260						$messageSuccess.addClass('d-none');
261
262						if (($messageError.offset().top - 80) < $(window).scrollTop()) {
263							$('html, body').animate({
264								scrollTop: $messageError.offset().top - 80
265							}, 300);
266						}
267
268						$form.find('.has-success')
269							.removeClass('has-success');
270							
271						$submitButton.val( submitButtonText ).attr('disabled', false);
272
273					});
274
275				});
276			}
277		});
278	});
279
280}).apply(this, [jQuery]);

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.