PageSourceSearch

https://www.bolognafc.it/wp-content/plugins/easy-social-share-butt…/assets/modules/subscribe-forms.js?ver=11.6

js bolognafc.it collected 2026-10-01 11:45:47 UTC 19,357 bytes, 562 lines download raw bytes

1/**
2 * Subscribe forms
3 * @package EasySocialShareButtons
4 * @author appscreo
5 * @since 8.0
6 */
7( function( $ ) {
8	"use strict";
9	
10	function essb_ajax_subscribe(key, event) {
11
12		event.preventDefault();
13
14		var formContainer = $('.essb-subscribe-form-' + key + ' #essb-subscribe-from-content-form-mailchimp'),
15			positionContainer = $('.essb-subscribe-form-' + key + ' .essb-subscribe-form-content');
16
17		var usedPosition = $(positionContainer).attr('data-position') || '',
18			usedDesign = $(positionContainer).attr('data-design') || '';
19
20		if (formContainer.length) {
21			// Additional check for require agree to terms check
22			if ($(formContainer).find('.essb-subscribe-confirm').length) {
23				var state = $(formContainer).find('.essb-subscribe-confirm').is(":checked");
24				if (!state) {
25					event.preventDefault();
26					if (essb_settings.subscribe_terms_error)
27						alert(essb_settings.subscribe_terms_error);
28					else
29						alert('You need to confirm that you agree with our terms');
30					return;
31				}
32			}
33
34			if ($(formContainer).find('.essb-subscribe-form-content-name-field').length && essb_settings.subscribe_validate_name) {
35				if ($(formContainer).find('.essb-subscribe-form-content-name-field').val() == '') {
36					if (essb_settings.subscribe_validate_name_error)
37						alert(essb_settings.subscribe_validate_name_error);
38					else
39						alert('You need to fill name field too');
40					return;
41				}
42			}
43
44			var user_mail = $(formContainer).find('.essb-subscribe-form-content-email-field').val();
45			var user_name = $(formContainer).find('.essb-subscribe-form-content-name-field').length ? $(formContainer).find('.essb-subscribe-form-content-name-field').val() : '';
46			$(formContainer).find('.submit').prop('disabled', true);
47			$(formContainer).hide();
48			$('.essb-subscribe-form-' + key).find('.essb-subscribe-loader').show();
49			var submitapi_call = formContainer.attr('action') + '&mailchimp_email='+user_mail+'&mailchimp_name='+user_name+'&position='+usedPosition+'&design='+usedDesign+'&title='+encodeURIComponent(document.title);
50			
51			/**
52			 * @since 8.6 custom fields support for Mailchimp
53			 */
54			var elCustomFields = document.querySelectorAll('.essb-subscribe-form-' + key + ' #essb-subscribe-from-content-form-mailchimp .essb-subscribe-custom'),
55				isCustomError = false;
56			for (var i = 0; i < elCustomFields.length; i++) {
57				if (elCustomFields[i].value == '' && elCustomFields[i].classList.contains('essb-subscribe-required')) {
58					isCustomError = true;
59					var place = elCustomFields[i].getAttribute('placeholder') || '';
60					alert('You need to fill ' + place);
61					break;
62				}
63				
64				var param = elCustomFields[i].getAttribute('data-field') || '';
65				if (param != '') submitapi_call += '&mailchimp_' + param + '=' + elCustomFields[i].value;
66			}
67			
68			if (isCustomError) return;
69			
70			/**
71			 * @since 7.7 Additional check to prevent mixed content 
72			 */
73			var current_page_url = window.location.href;
74			if (current_page_url.indexOf('https://') > -1 && submitapi_call.indexOf('https://') == -1) submitapi_call = submitapi_call.replace('http://', 'https://');
75			
76			// validate reCaptcha too
77			if ($('.essb-subscribe-captcha').length) {
78				var recaptcha  = $( '#g-recaptcha-response' ).val();
79				
80				if ($('input[name="cf-turnstile-response"]').length) recaptcha  = $( 'input[name="cf-turnstile-response"]' ).val();
81				submitapi_call += '&validate_recaptcha=true&recaptcha=' + recaptcha;
82			}
83			
84			
85			$.post(submitapi_call, { mailchimp_email1: user_mail, mailchimp_name1: user_name},
86					function (data) {
87
88						if (data) {
89
90						console.log(data);
91
92						if (data['code'] == '1') {
93							$('.essb-subscribe-form-' + key).find('.essb-subscribe-form-content-success').show();
94							$('.essb-subscribe-form-' + key).find('.essb-subscribe-form-content-error').hide();
95							$(formContainer).hide();
96
97							// subscribe conversions tracking
98							//usedPosition
99							if (typeof(essb_subscribe_tracking) != 'undefined') {
100								essb_subscribe_tracking(usedPosition);
101							}
102							
103							// integration with Conversions Pro
104							if (typeof (essbSubscribeProLog) != 'undefined') {								
105								essbSubscribeProLog('subscribe_conversion_success', usedPosition, usedDesign);
106							}
107
108							// redirecting users if successful redirect URL is set
109							if (data['redirect']) {
110								setTimeout(function() {
111
112									if (data['redirect_new']) {
113										var win = window.open(data['redirect'], '_blank');
114										win.focus();
115									}
116									else
117										window.location.href = data['redirect'];
118								}, 200);
119							}
120							
121							if (window.pendingUnlockOnSubscribe) essb_optin_locker_unlock();
122
123							essb.trigger('subscribe_success', {'design': usedDesign, 'position': usedPosition, 'email': user_mail, 'name': user_name});
124						}
125						else {
126							// integration with Conversions Pro
127							if (typeof (essbSubscribeProLog) != 'undefined') {								
128								essbSubscribeProLog('subscribe_conversion_fail', usedPosition, usedDesign);
129							}
130							
131							var storedMessage = $('.essb-subscribe-form-' + key).find('.essb-subscribe-form-content-error').attr('data-message') || '';
132							if (storedMessage == '') {
133								 $('.essb-subscribe-form-' + key).find('.essb-subscribe-form-content-error').attr('data-message', $('.essb-subscribe-form-' + key).find('.essb-subscribe-form-content-error').text());
134							}
135
136							if (data['code'] == 90)
137								$('.essb-subscribe-form-' + key).find('.essb-subscribe-form-content-error').text(data['message']);
138							else
139								$('.essb-subscribe-form-' + key).find('.essb-subscribe-form-content-error').text(storedMessage);
140							$('.essb-subscribe-form-' + key).find('.essb-subscribe-form-content-error').show();
141							$('.essb-subscribe-form-' + key).find('.essb-subscribe-from-content-form').show();
142							$(formContainer).find('.submit').prop('disabled', false);
143						}
144						$('.essb-subscribe-form-' + key).find('.essb-subscribe-loader').hide();
145					}},
146			'json');
147		}
148
149	};
150
151	window.essb_ajax_subscribe = essb_ajax_subscribe;
152	
153	
154	
155	$(document).ready(function(){
156		/**
157		 * Booster Pop-up forms
158		 */
159		var booster_optin_triggered = false,
160			booster_optin_percent = 0,
161			booster_optin_time = 0;
162	
163		var essb_manualform_show = window.essb_manualform_show = function() {
164			essb_optin_booster_show('manual');
165			booster_optin_triggered = false;
166		}
167	
168		var essb_optin_booster_show = function(event) {
169	
170			if (booster_optin_triggered) return;
171	
172			var base_element = '.essb-optinbooster-'+event;
173			var base_overlay_element = '.essb-optinbooster-overlay-'+event;
174	
175			if (!$(base_element).length) return;
176	
177			var singleDisplay = $(base_element).attr('data-single') || '',
178				singleDisplayDelay = $(base_element).attr('data-single-days') || '';
179	
180			if (singleDisplay == '1') {
181				var cookie_name = "essbOptinBooster";
182				var cookieSet = essbGetCookie(cookie_name);
183				if (cookieSet == "yes") { return; }
184	
185				singleDisplayDelay = (singleDisplayDelay == '' || !Number(singleDisplayDelay)) ? 14 : Number(singleDisplayDelay);
186	
187				essbSetCookie(cookie_name, "yes", singleDisplayDelay);
188			}
189	
190			jQuery.fn.extend({
191		        center: function () {
192		            return this.each(function() {
193		                var top = (jQuery(window).height() - jQuery(this).outerHeight()) / 2;
194		                var left = (jQuery(window).width() - jQuery(this).outerWidth()) / 2;
195		                jQuery(this).css({position:'fixed', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
196		            });
197		        }
198		    });
199	
200			var win_width = jQuery( window ).width();
201			var doc_height = jQuery('document').height();
202	
203			var base_width = 700;
204			if (win_width < base_width) { base_width = win_width - 60; }
205	
206			$(base_element).css( { width: base_width+'px'});
207			$(base_element).center();
208	
209			$(base_element).fadeIn(400);
210			$(base_overlay_element).fadeIn(200);
211	
212			$(base_element).addClass('active-booster');
213			$(base_overlay_element).addClass('active-booster-overlay');
214	
215			booster_optin_triggered = true;
216			
217			// integration with Conversions Pro
218			if (typeof (essbSubscribeProLog) != 'undefined') {
219				var position = $(base_element + ' .essb-subscribe-form-content').data('position') || '',
220					design = $(base_element + ' .essb-subscribe-form-content').data('design') || '';
221				essbSubscribeProLog('subscribe_conversion_loaded', position, design);
222			}
223		}
224	
225		var essb_optinbooster_close = function() {
226	
227	
228			$(".active-booster").fadeOut(200);
229			$('.active-booster').removeClass('active-booster');
230	
231			$(".active-booster-overlay").fadeOut(400);
232			$('.active-booster-overlay').removeClass('active-booster-overlay');
233		}
234	
235		if ($('.essb-optinbooster-exit')) {
236	
237			jQuery(document).on('mouseleave', function(e) {
238	
239					if(e.clientY < 0) { // Check if the cursor went above the top of the browser window
240						essb_optin_booster_show('exit');
241					}
242				});
243		}
244	
245		var essb_booster_scroll = function() {
246			if (booster_optin_triggered) { return; }
247	
248			var current_pos = jQuery(window).scrollTop();
249			var height = jQuery(document).height()-jQuery(window).height();
250			var percentage = current_pos/height*100;
251	
252			if (percentage > booster_optin_percent && booster_optin_percent > 0) {
253				essb_optin_booster_show('scroll');
254			}
255		}
256	
257		if ($('.essb-optinbooster-scroll')) {
258			booster_optin_percent = $('.essb-optinbooster-scroll').attr("data-scroll") || "";
259			booster_optin_percent = parseFloat(booster_optin_percent);
260			$(window).on('scroll', essb_booster_scroll);
261		}
262	
263		if ($('.essb-optinbooster-time')) {
264			booster_optin_time = $('.essb-optinbooster-time').attr("data-delay") || "";
265			booster_optin_time = parseFloat(booster_optin_time);
266			booster_optin_time = booster_optin_time * 1000;
267			setTimeout(function(){ essb_optin_booster_show('time'); }, booster_optin_time);
268		}
269		
270		if ($('.essb-optinbooster-manual').length) {
271			var selector = $('.essb-optinbooster-manual').data('manual-selector') || '';
272			if (selector != '' && $(selector).length) $(selector).on('click', function(e) {
273				e.preventDefault();
274				essb_manualform_show();
275			});
276		}
277	
278	
279		$('.essb-optinbooster-overlay').each(function() {
280	
281			$(this).on('click', function(e) {
282				e.preventDefault();
283	
284				essb_optinbooster_close();
285			});
286		});
287	
288		$('.essb-optinbooster-close').each(function() {
289	
290			$(this).on('click', function(e) {
291				e.preventDefault();
292	
293				essb_optinbooster_close();
294			});
295		});
296	
297		function essbSetCookie(cname, cvalue, exdays) {
298		    var d = new Date();
299		    d.setTime(d.getTime() + (exdays*24*60*60*1000));
300		    var expires = "expires="+d.toGMTString();
301		    document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
302		}
303	
304		function essbGetCookie(cname) {
305		    var name = cname + "=";
306		    var ca = document.cookie.split(';');
307		    for(var i=0; i<ca.length; i++) {
308		        var c = ca[i].trim();
309		        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
310		    }
311		    return "";
312		}
313
314		/**
315		 * Flyout subscribe forms
316		 */
317		var optin_triggered = false,
318			optin_percent = 0,
319			optin_time = 0;
320	
321		var essb_optin_flyout_show = function(event) {
322			
323			if (optin_triggered) return;
324			
325			var base_element = '.essb-optinflyout-'+event;
326			var base_overlay_element = '.essb-optinflyout-overlay-'+event;
327			
328			if (!$(base_element).length) return;
329			
330			var singleDisplay = $(base_element).attr('data-single') || '';
331			if (singleDisplay == '1') {
332				var cookie_name = "essbOptinFlyout";
333				var cookieSet = essbGetCookie(cookie_name);
334				if (cookieSet == "yes") { return; }
335				essbSetCookie(cookie_name, "yes", 14);
336			}
337			
338			jQuery.fn.extend({
339		        center: function () {
340		            return this.each(function() {
341		                var top = (jQuery(window).height() - jQuery(this).outerHeight()) / 2;
342		                var left = (jQuery(window).width() - jQuery(this).outerWidth()) / 2;
343		                jQuery(this).css({position:'fixed', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
344		            });
345		        }
346		    }); 
347			
348			var win_width = jQuery( window ).width();
349			var doc_height = jQuery('document').height();
350			
351			var base_width = 500;
352			if (win_width < base_width) { base_width = win_width - 60; }
353			
354			$(base_element).css( { width: base_width+'px'});
355			
356			$(base_element).slideDown(400);
357			
358			$(base_element).addClass('active-flyout');
359			
360			optin_triggered = true;
361			// integration with Conversions Pro
362			if (typeof (essbSubscribeProLog) != 'undefined') {
363				var position = $(base_element + ' .essb-subscribe-form-content').data('position') || '',
364					design = $(base_element + ' .essb-subscribe-form-content').data('design') || '';
365				essbSubscribeProLog('subscribe_conversion_loaded', position, design);
366			}
367		}
368		
369		var essb_optinflyout_close = function() {
370			
371	
372			$(".active-flyout").fadeOut(200);
373			$('.active-flyout').removeClass('active-flyout');
374		}
375	
376		var essb_booster_exit = function() {
377			var e = window.event;
378			
379			if (!e) return;
380			
381			var from = e.relatedTarget || e.toElement;
382	
383			// Reliable, works on mouse exiting window and user switching active program
384			if(!from || from.nodeName === "HTML") {
385				essb_optin_flyout_show('exit');
386			}
387		}
388		
389		if ($('.essb-optinflyout-exit'))
390			$(document).mouseout(essb_booster_exit);
391		
392		var essb_flyout_scroll = function() {
393			if (optin_triggered) { return; }
394			
395			var current_pos = jQuery(window).scrollTop();
396			var height = jQuery(document).height()-jQuery(window).height();
397			var percentage = current_pos/height*100;	
398			
399			if (percentage > optin_percent && optin_percent > 0) {
400				essb_optin_flyout_show('scroll');
401			}
402		}
403		
404		if ($('.essb-optinflyout-scroll')) {
405			optin_percent = $('.essb-optinflyout-scroll').attr("data-scroll") || "";
406			optin_percent = parseFloat(optin_percent);
407			$(window).on('scroll', essb_flyout_scroll);
408		}
409		
410		if ($('.essb-optinflyout-time')) {
411			optin_time = $('.essb-optinflyout-time').attr("data-delay") || "";
412			optin_time = parseFloat(optin_time);
413			optin_time = optin_time * 1000;
414			setTimeout(function(){ essb_optin_flyout_show('time'); }, optin_time);
415		}
416		
417		
418		$('.essb-optinflyout-overlay').each(function() {
419			
420			$(this).on('click', function(e) {
421				e.preventDefault();
422				
423				essb_optinflyout_close();
424			});
425		});
426		
427		$('.essb-optinflyout-close').each(function() {
428			
429			$(this).on('click', function(e) {
430				e.preventDefault();
431				
432				essb_optinflyout_close();
433			});
434		});
435		
436		/**
437		 * Locker form
438		 */
439		var locker_optin_triggered = false,
440			locker_optin_percent = 0,
441			locker_optin_time = 0,
442			locker_cookie_name = 'essb_optin_locker_unlocked',
443			pendingUnlockOnSubscribe = window.pendingUnlockOnSubscribe = false;
444		
445		var essb_optin_locker_unlock = window.essb_optin_locker_unlock = function() {
446			essb_optinlocker_close();
447			
448			var unlockLen = $('.essb-optinlocker').data('unlock') || '';			
449			if (!Number(unlockLen)) unlockLen = 90;
450			essbSetCookie(locker_cookie_name, "yes", unlockLen);
451		};
452		
453		var essb_optin_locker_show = function(event) {
454	
455			if (locker_optin_triggered) return;
456	
457			var base_element = '.essb-optinlocker-'+event;
458			var base_overlay_element = '.essb-optinlocker-overlay-'+event;
459	
460			if (!$(base_element).length) return;
461	
462			// check if it is unlocked
463			if (essbGetCookie(locker_cookie_name) == 'yes') return;
464				
465			jQuery.fn.extend({
466		        center: function () {
467		            return this.each(function() {
468		                var top = (jQuery(window).height() - jQuery(this).outerHeight()) / 2;
469		                var left = (jQuery(window).width() - jQuery(this).outerWidth()) / 2;
470		                jQuery(this).css({position:'fixed', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
471		            });
472		        }
473		    });
474	
475			var win_width = jQuery( window ).width();
476			var doc_height = jQuery('document').height();
477	
478			var base_width = 700;
479			if (win_width < base_width) { base_width = win_width - 60; }
480	
481			$(base_element).css( { width: base_width+'px'});
482			$(base_element).center();
483	
484			$(base_element).fadeIn(400);
485			$(base_overlay_element).fadeIn(200);
486	
487			$(base_element).addClass('active-locker');
488			$(base_overlay_element).addClass('active-locker-overlay');
489			$('body').addClass('removeScroll');
490	
491			locker_optin_triggered = true;
492			window.pendingUnlockOnSubscribe = true;
493			
494			// integration with Conversions Pro
495			if (typeof (essbSubscribeProLog) != 'undefined') {
496				var position = $(base_element + ' .essb-subscribe-form-content').data('position') || '',
497					design = $(base_element + ' .essb-subscribe-form-content').data('design') || '';
498				essbSubscribeProLog('subscribe_conversion_loaded', position, design);
499			}
500		}
501	
502		var essb_optinlocker_close = function() {
503			$(".active-locker").fadeOut(200);
504			$('.active-locker').removeClass('active-locker');
505	
506			$(".active-locker-overlay").fadeOut(400);
507			$('.active-locker-overlay').removeClass('active-locker-overlay');
508			$('body').removeClass('removeScroll');
509		}
510	
511	
512		var essb_optinlocker_scroll = function() {
513			if (locker_optin_triggered) { return; }	
514			var current_pos = jQuery(window).scrollTop();
515			var height = jQuery(document).height()-jQuery(window).height();
516			var percentage = current_pos/height*100;
517	
518			if (percentage > locker_optin_percent && locker_optin_percent > 0) {
519				essb_optin_locker_show('scroll');
520			}
521		}
522	
523		if ($('.essb-optinlocker-scroll')) {
524			locker_optin_percent = $('.essb-optinlocker-scroll').attr("data-scroll") || "";
525			locker_optin_percent = parseFloat(locker_optin_percent);
526			$(window).on('scroll', essb_optinlocker_scroll);
527		}
528	
529		if ($('.essb-optinlocker-time')) {
530			locker_optin_time = $('.essb-optinlocker-time').attr("data-delay") || "";
531			locker_optin_time = parseFloat(locker_optin_time);
532			locker_optin_time = booster_optin_time * 1000;
533			setTimeout(function(){ essb_optin_locker_show('time'); }, locker_optin_time);
534		}
535			
536		$('.essb-optinlocker-close').each(function() {
537			$(this).on('click', function(e) {
538				e.preventDefault();
539				essb_optinlocker_close();
540			});
541		});
542		
543		/**
544		 * Subscribe reCaptcha		
545		 */
546		if ($('.essb-subscribe-captcha').length) {
547			$('.essb-subscribe-captcha').each(function() {
548				var id = $(this).attr('id') || '';
549				if (id == '') return;				
550				
551				// Maybe load reCAPTCHA.
552				if ( typeof(essb_subscribe_recaptcha) != 'undefined' && essb_subscribe_recaptcha && essb_subscribe_recaptcha.recaptchaSitekey ) {
553					setTimeout(function() {
554						grecaptcha.render(essb_subscribe_recaptcha.turnstile ? '#' + id : id, {
555							sitekey:  essb_subscribe_recaptcha.recaptchaSitekey
556						} );
557					}, 500);
558				}
559			});
560		}				
561	});
562} )( 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.