PageSourceSearch

https://spotlight.vegas/wp-content/plugins/yith-easy-login-registe…/assets/js/popup-handler.js?ver=1.12.0

js spotlight.vegas collected 2026-09-24 13:07:54 UTC 17,214 bytes, 560 lines download raw bytes

1/**
2 * Frontend
3 *
4 * @author YITH
5 * @package YITH Easy Login Register Popup for WooCommerce
6 * @version 1.0.0
7 */
8
9;(function( $, window, document ) {
10	"use strict";
11
12	if ( typeof yith_welrp == 'undefined' ) {
13		return;
14	}
15
16	var perfEntries = performance.getEntriesByType( "navigation" ),
17		entry = perfEntries[0],
18		json = typeof entry != 'undefined' ? entry.toJSON() : false,
19		logged_in = false;
20
21	function cachedScript( url, options ) {
22		options = $.extend( options || {}, {
23			dataType: "script",
24			cache: true,
25			url: url
26		} );
27		return jQuery.ajax( options );
28	}
29
30	function doRequest( action, data ) {
31		return $.ajax( {
32			url: yith_welrp.ajaxUrl.toString().replace( '%%endpoint%%', action ),
33			data: data,
34			dataType: 'json',
35			type: 'POST'
36		} );
37	}
38
39	function animateInElem( elem, animation, callback ) {
40		elem.show().addClass( 'animated ' + animation );
41		elem.one( 'animationend', function() {
42			elem.removeClass( 'animated ' + animation );
43			if ( typeof callback != 'undefined' ) {
44				callback();
45			}
46		} );
47	}
48
49	function animateOutElem( elem, animation, callback ) {
50		elem.addClass( 'animated ' + animation );
51		elem.one( 'animationend', function() {
52			elem.hide().removeClass( 'animated ' + animation );
53			if ( typeof callback != 'undefined' ) {
54				callback();
55			}
56		} );
57	}
58
59	if ( json && json.type == 'back_forward' ) {
60		// check user logged in on back_forward navigation type to avoid cache issues
61		doRequest( yith_welrp.checkLogin, {context: "frontend"} )
62			.done( function( response ) {
63				logged_in = response.logged;
64			} );
65	}
66
67	/**
68	 * @param $popup
69	 * @param attr
70	 * @constructor
71	 */
72	var YITHLoginRegisterPopup = function( item ) {
73		if ( ! item.length ) {
74			return;
75		}
76
77		this.self = item;
78		this.wrap = item.find( '.yith-welrp-popup-wrapper' );
79		this.popup = item.find( '.yith-welrp-popup' );
80		this.content = item.find( '.yith-welrp-popup-content-wrapper' );
81		this.overlay = item.find( '.yith-welrp-overlay' );
82		this.blocked = false;
83		this.opened = false;
84		this.animated = false;
85		this.additional = item.hasClass( 'fixed' );
86		this.currentSection = null;
87		this.previousSection = null;
88		this.animationIn = this.popup.attr( 'data-animation-in' );
89		this.animationOut = this.popup.attr( 'data-animation-out' );
90
91		// position first
92		this.position( null );
93		// handle social if needed
94		this.handleFacebook();
95		this.handleGoogle();
96		this.handleGoogleReCaptcha();
97
98		// attach event
99		$( window ).on( 'resize', {obj: this}, this.position );
100		// open
101		if ( yith_welrp.mainSelector ) {
102			$( document ).on( 'click', yith_welrp.mainSelector, {obj: this, additional: false}, this.open );
103		}
104		if ( yith_welrp.additionalSelector ) {
105			$( document ).on( 'click', yith_welrp.additionalSelector, {obj: this, additional: true}, this.open );
106		}
107		// close
108		if ( this.wrap.hasClass( 'close-on-click' ) ) {
109			this.overlay.on( 'click', {obj: this}, this.close );
110		}
111		this.popup.on( 'click', '.yith-welrp-popup-close', {obj: this}, this.close );
112		this.popup.on( 'click', 'a.yith-welrp-go-back', {obj: this}, this.goBack );
113		this.popup.on( 'click', 'a.yith-welrp-lost-password', {obj: this}, this.goLostPassword );
114		this.popup.on( 'click', 'a.yith-welrp-send-auth, a.yith-welrp-send-email', {obj: this}, this.sendResetEmail );
115		this.popup.on( 'click', '.yith-welrp-password-eye', {obj: this}, this.passwordEye );
116		this.popup.on( 'submit', 'form.yith-welrp-form', {obj: this}, this.formSubmit );
117		this.popup.on( 'keyup', '#user_login, #reg_email', {obj: this}, this.emailSuggestions );
118		this.popup.on( 'click', '.yith-welrp-email-suggestion-item', {obj: this}, this.useEmailSuggestion );
119		this.popup.on( 'click', '*', this.closeEmailSuggestion );
120	};
121
122	/** UTILS **/
123	YITHLoginRegisterPopup.prototype.position = function( event ) {
124		var popup = event == null ? this.popup : event.data.obj.popup,
125			window_w = $( window ).width(),
126			window_h = $( window ).height(),
127			margin = ((window_w - 40) > yith_welrp.popupWidth) ? window_h / 10 + 'px' : '0',
128			width = ((window_w - 40) > yith_welrp.popupWidth) ? yith_welrp.popupWidth + 'px' : 'auto';
129
130		popup.css( {
131			'margin-top': margin,
132			'margin-bottom': margin,
133			'width': width,
134		} );
135	};
136	YITHLoginRegisterPopup.prototype.block = function() {
137		if ( ! this.blocked ) {
138			this.popup.block( {
139				message: null,
140				overlayCSS: {
141					background: '#fff url(' + yith_welrp.loader + ') no-repeat center',
142					opacity: 0.5,
143					cursor: 'none'
144				}
145			} );
146			this.blocked = true;
147		}
148	};
149	YITHLoginRegisterPopup.prototype.unblock = function() {
150		if ( this.blocked ) {
151			this.popup.unblock();
152			this.blocked = false;
153		}
154	};
155	YITHLoginRegisterPopup.prototype.reset = function( message ) {
156		this.loadTemplate( 'email-section', {
157			title: this.additional ? yith_welrp.fsAdditionalTitle : yith_welrp.fsTitle
158		} );
159		this.previousSection = null;
160		if ( message ) {
161			this.addMessage( message, 'error' );
162		}
163		this.unblock();
164	};
165	YITHLoginRegisterPopup.prototype.loadTemplate = function( id, data ) {
166		var template = wp.template( id );
167		// save section and show new template
168		this.content.find( '.yith-welrp-message' ).remove();
169		this.previousSection = this.content.html();
170		this.showTemplate( template( data ) );
171	};
172	YITHLoginRegisterPopup.prototype.showTemplate = function( section ) {
173		this.content.hide().html( section ).fadeIn();
174		$( document ).trigger( 'yith_welrp_popup_template_loaded', [this.popup, this] );
175	};
176	YITHLoginRegisterPopup.prototype.addMessage = function( message, type ) {
177		if ( message ) {
178			if ( typeof type == 'undefined' ) {
179				type = 'success';
180			}
181
182			var elem = $( '<div/>', {
183				'class': 'yith-welrp-message ' + type,
184			} ).html( message );
185
186			if ( $( '.yith-welrp-message' ).length ) {
187				$( '.yith-welrp-message' ).replaceWith( elem );
188			} else {
189				this.content.find( '.yith-welrp-submit-button' ).before( elem );
190			}
191		}
192	};
193	YITHLoginRegisterPopup.prototype.passwordEye = function( event ) {
194		var input = $( this ).closest( '.yith-welrp-password-container' ).find( 'input' ),
195			type = input.attr( 'type' );
196
197		$( this ).toggleClass( 'opened' );
198		input.attr( 'type', type == 'password' ? 'text' : 'password' );
199	};
200
201	/** EVENT **/
202	YITHLoginRegisterPopup.prototype.open = function( event ) {
203		if ( logged_in ) {
204			return;
205		}
206		event.preventDefault();
207
208		var object = event.data.obj;
209		// if already opened or animated, return
210		if ( object.opened || object.animated ) {
211			return;
212		}
213
214		object.opened = true;
215		// check if additional
216		if ( event.data.additional ) {
217			object.additional = true;
218			object.popup.addClass( 'additional' );
219		}
220		// add template
221        //@modifiedByRWB
222        var emaillogin = '';
223        if(jQuery('#billing_email').val()!== ''){
224            emaillogin = jQuery('#billing_email').val();
225        }
226		object.loadTemplate( 'email-section', {
227            title: object.additional ? yith_welrp.fsAdditionalTitle : yith_welrp.fsTitle,
228            emaillogin:emaillogin
229		} );
230
231		object.self.show();
232		// animate
233		if ( object.animationIn ) {
234			object.animated = true;
235			animateInElem( object.overlay, 'fadeIn' );
236			animateInElem( object.popup, object.animationIn, function() {
237				object.animated = false;
238			} );
239		} else {
240			object.overlay.show();
241			object.popup.show();
242		}
243
244		// add html and body class
245		$( 'html, body' ).addClass( 'yith_welrp_opened' );
246		// trigger event
247		$( document ).trigger( 'yith_welrp_popup_opened', [object.popup, object] );
248	};
249	YITHLoginRegisterPopup.prototype.close = function( event ) {
250		event.preventDefault();
251		var object = event.data.obj;
252		// if animated, block close
253		if ( object.animated ) {
254			return;
255		}
256
257		// animate. Remove body class after overlay close
258		if ( object.animationOut ) {
259			object.animated = true;
260			animateOutElem( object.popup, object.animationOut );
261			animateOutElem( object.overlay, 'fadeOut slow', function() {
262				object.opened = false;
263				object.additional = false;
264				object.animated = false;
265				object.popup.removeClass( 'additional' );
266				object.self.hide();
267			} );
268		} else {
269			object.opened = false;
270			object.additional = false;
271			object.popup.removeClass( 'additional' );
272			object.overlay.hide();
273			object.popup.hide();
274			object.self.hide();
275		}
276
277		// remove body class
278		$( 'html, body' ).removeClass( 'yith_welrp_opened' );
279		// trigger event
280		$( document ).trigger( 'yith_welrp_popup_closed', [object.popup, object] );
281	};
282	YITHLoginRegisterPopup.prototype.goBack = function( event ) {
283		event.preventDefault();
284		var object = event.data.obj;
285
286		if ( object.previousSection != null ) {
287			object.showTemplate( object.previousSection );
288			object.previousSection = null;
289		} else {
290			object.reset();
291		}
292	};
293	YITHLoginRegisterPopup.prototype.goLostPassword = function( event ) {
294		event.preventDefault();
295
296		var object = event.data.obj,
297			user = object.content.find( "input[name='user_email']" ),
298			data = {
299				title: yith_welrp.lostPasswordTitle,
300				message: yith_welrp.lostPasswordMessage,
301				button_label: yith_welrp.lostPasswordButton,
302				user_login: user.length ? user.val() : '',
303				action: 'lost-password'
304			};
305
306		object.loadTemplate( 'lost-password-section', data );
307	};
308	YITHLoginRegisterPopup.prototype.sendResetEmail = function( event ) {
309		event.preventDefault();
310		var object = event.data.obj,
311			user = $( this ).data( 'user-login' ),
312			data = [
313				{name: "action", value: 'lost-password'},
314				{name: "resend", value: true},
315				{name: "user_login", value: user}
316			];
317
318		object.formAction( data );
319	};
320	YITHLoginRegisterPopup.prototype.emailSuggestions = function( event ) {
321		var field = $( this ),
322			val = field.val().split( '@' ),
323			base = val[0],
324			domain = val.length > 1 ? val[1] : '',
325			suggestions = '';
326
327		// create suggestions
328		$.each( yith_welrp.emailSuggestions, function( x, j ) {
329			if ( domain && (j.indexOf( domain ) !== 0 || domain === j) ) {
330				return;
331			}
332			suggestions = suggestions + '<li class="yith-welrp-email-suggestion-item">' + base + '@' + j + '</li>';
333		} );
334
335		if ( base.length < 3 || ! suggestions ) {
336			field.closest( '.yith-welrp-email-suggestion' ).replaceWith( field ).end().focus();
337			return;
338		}
339
340		if ( ! field.closest( '.yith-welrp-email-suggestion' ).length ) {
341			field.wrap( '<div class="yith-welrp-email-suggestion"></div>' )
342				.after( '<ul class="yith-welrp-email-suggestion-list"></ul>' ).focus();
343		}
344
345		field.next( '.yith-welrp-email-suggestion-list' ).html( suggestions );
346	};
347	YITHLoginRegisterPopup.prototype.useEmailSuggestion = function( event ) {
348		event.stopPropagation();
349		$( this ).closest( '.yith-welrp-email-suggestion' ).find( 'input' ).val( $( this ).text() ).keyup();
350	};
351	YITHLoginRegisterPopup.prototype.closeEmailSuggestion = function( event ) {
352		if ( $( this ).closest( '.yith-welrp-email-suggestion' ).length || $( this ).hasClass( 'yith-welrp-email-suggestion' ) ) {
353			return;
354		}
355
356		var field = $( '.yith-welrp-email-suggestion' ).find( 'input' );
357		if ( field.length ) {
358			$( '.yith-welrp-email-suggestion' ).replaceWith( field );
359		}
360
361	};
362	YITHLoginRegisterPopup.prototype.formSubmit = function( event ) {
363		event.preventDefault();
364
365		var object = event.data.obj,
366			form = $( this ),
367			data = form.serializeArray();
368
369		object.formAction( data );
370	};
371	YITHLoginRegisterPopup.prototype.formAction = function( data ) {
372
373		var object = this;
374		var myloc = window.location.href;
375		if(myloc.indexOf('seat-selection-map') !== -1){
376			if(jQuery('.time_elem_active').length > 0){
377				myloc += '&def_date='+jQuery('.time_elem_active').attr('event_date')+'&def_ev='+jQuery('.time_elem_active').attr('event_id');
378			}
379		}
380		data.push(
381			{name: "origin", value: myloc },
382			{name: "additional", value: object.additional ? 1 : 0},
383			{name: "context", value: "frontend"}
384		);
385
386		object.block();
387
388		doRequest( yith_welrp.formAction, data )
389			.done( function( response ) {
390
391				if ( response.success ) {
392					if ( typeof response.data.action != 'undefined' ) { // handle action if any
393						if ( typeof response.data.action.redirectTo != 'undefined' ) {
394							window.location.href = response.data.action.redirectTo;
395							return;
396						}else if ( typeof response.data.action.show_message != 'undefined' ) {
397							jQuery('#pwait_message').show();
398							object.unblock();
399							return;
400						} else if ( typeof response.data.action.nextSection != 'undefined' ) {
401							object.loadTemplate( response.data.action.nextSection, response.data.popup );
402						}
403					}
404				}
405
406				object.addMessage( response.data.message, response.success ? 'success' : 'error' );
407
408				$( document ).trigger( 'yith_welrp_popup_form_action_handled', [response.success, response, this] );
409
410				object.unblock();
411			} )
412			.fail( function( response ) {
413				object.reset( yith_welrp.errorMsg );
414			} );
415	};
416
417	/** Google reCatpcha **/
418	YITHLoginRegisterPopup.prototype.handleGoogleReCaptcha = function() {
419		if ( typeof yith_welrp.googleReCaptcha == 'undefined' ) {
420			return;
421		}
422		// get script
423		cachedScript( 'https://www.google.com/recaptcha/api.js' )
424			.done( function( script, textStatus ) {
425
426				var reCaptcha = null;
427
428				$( document ).on( 'yith_welrp_popup_template_loaded', function() {
429					var captchaContainer = document.getElementById( 'g-recaptcha' );
430					if ( captchaContainer ) {
431						reCaptcha = grecaptcha.render( captchaContainer, {
432							'sitekey': yith_welrp.googleReCaptcha,
433							'theme': 'light'
434						} );
435					}
436				} );
437
438				$( document ).on( 'yith_welrp_popup_form_action_handled', function( event, response ) {
439					if ( ! response && reCaptcha !== null ) {
440						grecaptcha.reset( reCaptcha );
441					}
442				} );
443			} )
444			.fail( function( jqxhr, settings, exception ) {
445				console.log( 'Error retreiving Google reCaptcha' );
446			} );
447	};
448
449	/** SOCIALS **/
450	YITHLoginRegisterPopup.prototype.socialAction = function( token, social ) {
451
452		var object = this,
453			data = [
454				{name: "origin", value: window.location.pathname},
455				{name: "additional", value: object.additional ? 1 : 0},
456				{name: "context", value: "frontend"},
457				{name: "token", value: token},
458				{name: "social", value: social}
459			];
460
461		doRequest( yith_welrp.socialAction, data )
462			.done( function( response ) {
463				if ( response.success ) {
464					if ( typeof response.data.redirectTo != 'undefined' ) {
465						window.location.href = response.data.redirectTo;
466					}
467				} else {
468					object.reset( response.data.message, 'error' );
469				}
470
471				$( document ).trigger( 'yith_welrp_popup_form_social_handled', [response.success, response, social, this] );
472			} )
473			.fail( function( response ) {
474				object.reset( yith_welrp.message );
475			} );
476	};
477	YITHLoginRegisterPopup.prototype.handleFacebook = function() {
478		var object = this;
479
480		if ( typeof yith_welrp.facebookAppID == 'undefined' ) {
481			return;
482		}
483
484		// get script
485		cachedScript( 'https://connect.facebook.net/en_US/sdk.js' )
486			.done( function( script, textStatus ) {
487				FB.init( {
488					appId: yith_welrp.facebookAppID,
489					xfbml: true,     // Parse social plugins on this webpage.
490					version: 'v4.0',
491                    status     : true // set this status to true, this will fixed popup blocker issue
492				} );
493
494				object.popup.on( 'click', '#yith-welrp-facebook-button', ( event ) => {
495					object.block();
496
497					FB.getLoginStatus( function( response ) {
498						if ( response.status == 'connected' ) {
499							object.socialAction( response.authResponse.accessToken, 'facebook' );
500						} else {
501							FB.login( function( response ) {
502								if ( response.status === 'connected' ) {
503									object.socialAction( response.authResponse.accessToken, 'facebook' );
504								} else {
505									object.reset( yith_welrp.errorMsg );
506								}
507							}, {scope: 'public_profile,email'} );
508						}
509					}, true );
510				} );
511			} )
512			.fail( function( jqxhr, settings, exception ) {
513				console.log( 'Error get FB SDK' );
514			} );
515	};
516	YITHLoginRegisterPopup.prototype.handleGoogle = function() {
517		var object = this;
518
519		if ( typeof yith_welrp.googleAppID == 'undefined' ) {
520			return;
521		}
522
523		// get script
524		cachedScript( 'https://apis.google.com/js/api:client.js' )
525			.done( function( script, textStatus ) {
526				gapi.load( 'auth2', function() {
527					// Retrieve the singleton for the GoogleAuth library and set up the client.
528					var auth2 = gapi.auth2.init( {
529						client_id: yith_welrp.googleAppID,
530						cookiepolicy: 'single_host_origin'
531					} );
532
533					$( document ).on( 'yith_welrp_popup_opened', function() {
534						var button = document.getElementById( 'yith-welrp-google-button' );
535
536						$( button ).on( 'click', function() {
537							object.block();
538						} );
539						auth2.attachClickHandler( button, {},
540							function( googleUser ) {
541								object.socialAction( googleUser.getAuthResponse().id_token, 'google' );
542							},
543							function( error ) {
544								console.log( JSON.stringify( error, undefined, 2 ) );
545								object.reset( yith_welrp.errorMsg );
546							} );
547					} );
548				} );
549			} )
550			.fail( function( jqxhr, settings, exception ) {
551				console.log( 'Error get Google SDK' );
552			} );
553	};
554
555	// START
556	$( document ).ready( function() {
557		new YITHLoginRegisterPopup( $( document ).find( '#yith-welrp' ) );
558	} );
559
560})( jQuery, window, document );

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.