PageSourceSearch

https://www.askcoffeeroastery.com/wp-content/plugins/jet-popup/assets/js/jet-popup-frontend.js?ver=2.2.3.2

js askcoffeeroastery.com collected 2026-10-08 16:33:33 UTC 53,293 bytes, 2,046 lines download raw bytes

1( function( $ ) {
2
3	'use strict';
4
5	// Keep JetPopup bound to its isolated anime.js instance.
6	var anime = window.JetPopupAnime;
7
8	window.JetPopupFrontend = {
9
10		addedScripts: {},
11
12		addedStyles: {},
13
14		addedAssetsPromises: [],
15
16		getTooltipReference: function( $trigger ) {
17			const popper = $trigger && $trigger.closest( '[data-tippy-root]' )[0],
18				instance = popper && popper._tippy;
19
20			if ( instance && $( instance.reference ).closest( '.jet-tooltip-widget' ).length ) {
21				return $( instance.reference );
22			}
23
24			return $();
25		},
26
27		getTooltipPopupData: function( popupData, $trigger ) {
28			const $reference = JetPopupFrontend.getTooltipReference( $trigger ),
29				settings = $trigger && $trigger.closest( '[data-jet-popup]' ).data( 'jet-popup' );
30
31			if ( ! $reference.length ) {
32				return popupData;
33			}
34
35			if ( settings && ! settings['is-jet-engine'] && ! popupData.isJetEngine && ! popupData.loopDynamicPopup ) {
36				return popupData;
37			}
38
39			// Tippy can render outside the listing. Resolve context from its owner,
40			// using JetEngine's existing resolver to preserve query/source metadata.
41			if ( window.JetEngine && window.JetEngine.prepareJetPopup
42				&& $reference.closest( '.jet-listing-grid__item, .jet-calendar-week__day-event, [data-item-object]' ).length ) {
43				popupData = window.JetEngine.prepareJetPopup(
44					$.extend( {}, popupData ), { 'is-jet-engine': true }, $reference
45				);
46			} else if ( popupData.loopDynamicPopup ) {
47				popupData = $.extend( {}, popupData, JetPopupFrontend.getLoopItemData( $reference ) );
48			}
49
50			if ( popupData.postId && ( popupData.isJetEngine || popupData.loopDynamicPopup ) ) {
51				popupData.forceLoad = true;
52			}
53
54			return popupData;
55		},
56
57		getLoopItemData: function( $trigger ) {
58
59			let $loopItem = $();
60
61			if ( ! $trigger || ! $trigger.length ) {
62				return {};
63			}
64
65			$loopItem = $trigger.closest( '[data-elementor-type="loop-item"], .e-loop-item' );
66
67			if ( ! $loopItem.length ) {
68				$loopItem = $trigger.find( '[data-elementor-type="loop-item"], .e-loop-item' ).first();
69			}
70
71			if ( ! $loopItem.length ) {
72				return {};
73			}
74
75			let postId    = $loopItem.data( 'post-id' ) || false,
76				className = $loopItem.attr( 'class' ) || '',
77				matches   = [
78					className.match( /\be-loop-item-(\d+)\b/ ),
79					className.match( /\bpost-(\d+)\b/ ),
80					className.match( /\bpage-id-(\d+)\b/ ),
81					className.match( /\battachment-(\d+)\b/ ),
82				];
83
84			if ( ! postId ) {
85				for ( let match of matches ) {
86					if ( match && match[1] ) {
87						postId = match[1];
88						break;
89					}
90				}
91			}
92
93			if ( ! postId ) {
94				return {};
95			}
96
97			return {
98				postId: +postId,
99			};
100		},
101
102		maybeExtendPopupData: function( popupData, $trigger ) {
103			let loopItemData = {};
104
105			popupData = popupData || {};
106
107			// Attached JetEngine listing popups can reach this method with only
108			// popupId. Resolve the clicked item before falling back to the page ID.
109			if ( $trigger && $trigger.length && ( popupData.isJetEngine || $trigger.data( 'popupIsJetEngine' ) ) ) {
110				const $item = $trigger.closest( '.jet-listing-grid__item, .jet-calendar-week__day-event, [data-item-object]' );
111
112				if ( $item.length ) {
113					const itemData = {
114						isJetEngine: true,
115						postId: $item.data( 'item-object' ) || $item.data( 'post-id' ),
116					};
117					const $items = $item.closest( '.jet-listing-grid__items' );
118
119					if ( $items.length ) {
120						itemData.listingSource = $items.data( 'listing-source' );
121						itemData.listingId = $items.data( 'listing-id' );
122						itemData.queryId = $items.data( 'query-id' );
123						itemData.cctSlug = $items.data( 'cct-slug' ) || $items.data( 'cctSlug' ) || $item.data( 'cct-slug' ) || $item.data( 'cctSlug' );
124					}
125
126					return jQuery.extend( {}, popupData, itemData, { forceLoad: true } );
127				}
128			}
129
130			if ( popupData.postId ) {
131				return popupData;
132			}
133
134			if ( popupData.loopDynamicPopup && $trigger && $trigger.length ) {
135				loopItemData = JetPopupFrontend.getLoopItemData( $trigger );
136			}
137
138			if ( loopItemData.postId ) {
139				return jQuery.extend( {}, popupData, loopItemData );
140			}
141
142			if ( window.jetPopupData && window.jetPopupData.currentPostId ) {
143				return jQuery.extend( {}, popupData, {
144					postId: +window.jetPopupData.currentPostId,
145				} );
146			}
147
148			return popupData;
149		},
150
151		init: function() {
152			let $popup_list = $( '.jet-popup.jet-popup--front-mode' );
153
154			$popup_list.each( function( index ) {
155				let $target  = $( this ),
156					instance = null,
157					settings = $target.data( 'settings' );
158
159				instance = new window.jetPopup( $target, settings );
160				instance.init();
161			} );
162
163			JetPopupFrontend.initAttachedPopups();
164
165			JetPopupFrontend.initBlocks();
166
167			$( window ).on( 'jet-popup/ajax/frontend-init', ( event, payload ) => {
168
169				switch ( payload.contentType ) {
170					case 'elementor':
171						JetPopupFrontend.maybeElementorFrontendInit( payload.$container );
172						break;
173					case 'default':
174						JetPopupFrontend.maybeDefaultFrontendInit( payload );
175						break
176				}
177			} );
178		},
179
180		initAttachedPopups: function ( $scope ) {
181			$scope = $scope || $( 'body' );
182
183			$scope.find( '[data-popup-instance]' ).each( ( index, el ) => {
184				let $this = $( el ),
185					popupId = $this.data( 'popup-instance' ) || 'none',
186					triggerType = $this.data( 'popup-trigger-type' ) || 'none',
187					clickedCustomClass = $this.data( 'popup-custom-selector' ) || '',
188				popupData = {
189					popupId: `jet-popup-${ popupId }`,
190				};
191
192				// Listing overlays are initialized before JetEngine's popup filter in
193				// some setups. Resolve the item context at click time as a fallback.
194				const getListingPopupData = ( $trigger ) => {
195					const $item = $trigger.closest( '.jet-listing-grid__item, .jet-calendar-week__day-event, [data-item-object]' );
196
197					if ( ! $item.length ) {
198						return popupData;
199					}
200
201					const data = $.extend( {}, popupData, {
202						isJetEngine: true,
203						postId: $item.data( 'item-object' ) || $item.data( 'post-id' ),
204					} );
205					const $items = $item.closest( '.jet-listing-grid__items' );
206
207					if ( $items.length ) {
208						data.listingSource = $items.data( 'listing-source' );
209						data.listingId = $items.data( 'listing-id' );
210						data.queryId = $items.data( 'query-id' );
211						data.cctSlug = $items.data( 'cct-slug' ) || $items.data( 'cctSlug' ) || $item.data( 'cct-slug' ) || $item.data( 'cctSlug' );
212					}
213
214					return data;
215				};
216
217				if ( $this.hasClass( 'jet-popup-attach-event-inited' ) ) {
218					return;
219				}
220
221				$this.addClass( 'jet-popup-attach-event-inited' );
222
223				switch( triggerType ) {
224					case 'click-self':
225						$this.addClass( 'jet-popup-cursor-pointer' );
226						JetPopupFrontend.makeTriggerAccessible( $this, popupData.popupId );
227
228						$this.on( 'click.JetPopup', function( event ) {
229							event.preventDefault();
230							const eventPopupData = getListingPopupData( $( event.currentTarget ) );
231
232							$( window ).trigger( {
233								type: 'jet-popup-open-trigger',
234								popupData: eventPopupData,
235								triggeredBy: $( event.currentTarget ),
236							} );
237
238							return false;
239						} );
240						break;
241					case 'click-selector':
242
243						if ( '' !== clickedCustomClass ) {
244							$this.find( clickedCustomClass ).addClass( 'jet-popup-cursor-pointer' );
245							JetPopupFrontend.makeTriggerAccessible( $this.find( clickedCustomClass ), popupData.popupId );
246
247							$this.on( 'click.JetPopup', clickedCustomClass, function( event ) {
248								event.preventDefault();
249
250								$( window ).trigger( {
251									type: 'jet-popup-open-trigger',
252									popupData: popupData,
253									triggeredBy: $( event.currentTarget ),
254								} );
255
256								return false;
257							} );
258						}
259						break;
260					case 'hover':
261						$this.on( 'mouseenter.JetPopup', function( event ) {
262
263							$( window ).trigger( {
264								type: 'jet-popup-open-trigger',
265								popupData: popupData,
266								triggeredBy: $this,
267							} );
268						} );
269						break;
270					case 'scroll-to':
271						const observer = new IntersectionObserver(( entries ) => {
272							entries.forEach(( entry ) => {
273
274								if ( entry.isIntersecting ) {
275
276									$( window ).trigger( {
277										type: 'jet-popup-open-trigger',
278										popupData: popupData,
279										triggeredBy: $this,
280									} );
281								}			
282							})
283						},
284						{ 
285							threshold: 0.5
286						});
287
288						for ( let i = 0; i < $( $this ).length; i++ ) {
289							const elements = $( $this )[i];
290							observer.observe( elements );
291						} 
292
293						break;
294				}
295			} );
296		},
297
298		initBlocks: function( $scope ) {
299			$scope = $scope || $( 'body' );
300
301			window.JetPlugins.init( $scope, [
302				{
303					block: 'jet-popup/action-button',
304					callback: ( $scope ) => {
305						let $button    = $( '.jet-popup-action-button__instance', $scope ),
306							actionType = $scope.data( 'action-type' );
307
308						JetPopupFrontend.actionButtonHandle( $button, actionType );
309					}
310				}
311			] );
312		},
313
314		actionButtonBlock: function( $scope ) {
315			var $button    = $( '.jet-popup-action-button__instance', $scope ),
316				actionType = $scope.data( 'action-type' );
317
318			JetPopupFrontend.actionButtonHandle( $button, actionType );
319		},
320
321		getPopupActionButtonCloseState: function( $popup, constantly ) {
322			var popupSettings = $popup.data( 'settings' ) || {};
323
324			if ( undefined !== constantly ) {
325				return constantly;
326			}
327
328			return popupSettings['show-once'] || false;
329		},
330
331		redirectPopupActionButton: function( $button ) {
332			var link   = $button.attr( 'href' ),
333				target = $button.attr( 'target' );
334
335			if ( ! link || '#' === link ) {
336				return;
337			}
338
339			if ( '_blank' === target  ) {
340				window.open( link, '_blank' );
341			} else {
342				window.open( link, '_self' );
343			}
344		},
345
346		actionButtonHandle: function ( $button, actionType = 'link' ) {
347
348			switch ( actionType ) {
349
350				case 'link':
351
352					$button.on( 'click.JetPopup', function( event ) {
353						event.preventDefault();
354
355						var $currentPopup = $button.closest( '.jet-popup' ),
356							popupId       = $currentPopup.attr( 'id' );
357
358						$( window ).trigger( {
359							type: 'jet-popup-close-trigger',
360							popupData: {
361								popupId: popupId,
362								constantly: JetPopupFrontend.getPopupActionButtonCloseState( $currentPopup )
363							}
364						} );
365
366						JetPopupFrontend.redirectPopupActionButton( $( this ) );
367
368						return false;
369					} );
370					break;
371
372				case 'leave':
373					$button.on( 'click.JetPopup', function( event ) {
374						event.preventDefault();
375
376						window.history.back();
377					} );
378					break;
379
380				case 'close-popup':
381					$button.on( 'click.JetPopup', function( event ) {
382						event.preventDefault();
383
384						var $currentPopup = $button.closest( '.jet-popup' ),
385							popupId = $currentPopup.attr( 'id' );
386
387						$( window ).trigger( {
388							type: 'jet-popup-close-trigger',
389							popupData: {
390								popupId: popupId,
391								constantly: false
392							}
393						} );
394
395						JetPopupFrontend.redirectPopupActionButton( $( this ) );
396					} );
397					break;
398
399				case 'close-all-popups':
400					$button.on( 'click.JetPopup', function( event ) {
401						event.preventDefault();
402
403						var $popups = $( '.jet-popup' );
404
405						if ( $popups[0] ) {
406							$popups.each( function( index ) {
407								var $popup  = $( this ),
408									popupId = $popup.attr( 'id' );
409
410								$( window ).trigger( {
411									type: 'jet-popup-close-trigger',
412									popupData: {
413										popupId: popupId,
414										constantly: false
415									}
416								} );
417							} );
418						}
419
420						JetPopupFrontend.redirectPopupActionButton( $( this ) );
421					} );
422					break;
423
424				case 'close-constantly':
425					$button.on( 'click.JetPopup', function( event ) {
426						event.preventDefault();
427
428						var $currentPopup = $button.closest( '.jet-popup' ),
429							popupId = $currentPopup.attr( 'id' );
430
431						$( window ).trigger( {
432							type: 'jet-popup-close-trigger',
433							popupData: {
434								popupId: popupId,
435								constantly: true
436							}
437						} );
438
439						JetPopupFrontend.redirectPopupActionButton( $( this ) );
440					} );
441					break;
442
443				case 'close-all-constantly':
444					$button.on( 'click.JetPopup', function( event ) {
445						event.preventDefault();
446
447						var $popups = $( '.jet-popup' );
448
449						if ( $popups[0] ) {
450							$popups.each( function( index ) {
451								var $popup  = $( this ),
452									popupId = $popup.attr( 'id' );
453
454								$( window ).trigger( {
455									type: 'jet-popup-close-trigger',
456									popupData: {
457										popupId: popupId,
458										constantly: true
459									}
460								} );
461							} );
462						}
463
464						JetPopupFrontend.redirectPopupActionButton( $( this ) );
465					} );
466					break;
467			}
468		},
469
470		isNativeInteractiveElement: function( element ) {
471			if ( ! element || ! element.tagName ) {
472				return false;
473			}
474
475			const tagName = element.tagName.toLowerCase();
476
477			return -1 !== [ 'a', 'button', 'input', 'select', 'textarea', 'option', 'summary' ].indexOf( tagName );
478		},
479
480		makeTriggerAccessible: function( $elements, popupId ) {
481			if ( ! $elements || ! $elements.length ) {
482				return;
483			}
484
485			$elements.each( function() {
486				const $element = $( this );
487
488				if ( popupId ) {
489					$element.attr( {
490						'aria-haspopup': 'dialog',
491						'aria-controls': popupId,
492						'aria-expanded': 'false',
493					} );
494				}
495
496				if ( JetPopupFrontend.isNativeInteractiveElement( this ) ) {
497					return;
498				}
499
500				if ( ! $element.is( '[role]' ) ) {
501					$element.attr( 'role', 'button' );
502				}
503
504				if ( ! $element.is( '[tabindex]' ) ) {
505					$element.attr( 'tabindex', '0' );
506				}
507			} );
508
509			$elements.off( 'keydown.jetPopupA11yTrigger' ).on( 'keydown.jetPopupA11yTrigger', function( event ) {
510				const key = event.key || '';
511
512				if ( JetPopupFrontend.isNativeInteractiveElement( event.currentTarget ) ) {
513					return;
514				}
515
516				if ( 'Enter' === key || ' ' === key || 'Spacebar' === key || 13 === event.keyCode || 32 === event.keyCode ) {
517					event.preventDefault();
518					$( this ).trigger( 'click' );
519				}
520			} );
521		},
522
523		loadScriptAsync: function( script, uri ) {
524
525			if ( JetPopupFrontend.addedScripts.hasOwnProperty( script ) ) {
526				return script;
527			}
528
529			JetPopupFrontend.addedScripts[ script ] = uri;
530
531			const asset = document.getElementById( script + '-js' );
532
533			if ( asset ) {
534				return script;
535			}
536
537			return new Promise( function( resolve, reject ) {
538				var tag = document.createElement( 'script' );
539
540				tag.src    = uri;
541				tag.async  = false;
542				tag.onload = function() {
543					resolve( script );
544				};
545
546				document.head.appendChild( tag );
547			} );
548		},
549
550		loadStyle: function( style, uri ) {
551
552			if ( JetPopupFrontend.addedStyles.hasOwnProperty( style ) && JetPopupFrontend.addedStyles[ style ] ===  uri) {
553				return style;
554			}
555
556			JetPopupFrontend.addedStyles[ style ] = uri;
557
558			return new Promise( function( resolve, reject ) {
559				var tag = document.createElement( 'link' );
560
561				tag.id      = style;
562				tag.rel     = 'stylesheet';
563				tag.href    = uri;
564				tag.type    = 'text/css';
565				tag.media   = 'all';
566				tag.onload  = function() {
567					resolve( style );
568				};
569
570				document.head.appendChild( tag );
571			});
572		},
573
574		assetsLoaderPromise: function() {
575			return Promise.all( JetPopupFrontend.addedAssetsPromises );
576		},
577
578		maybeElementorFrontendInit: function( $popupContainer ) {
579			$popupContainer.find( 'div[data-element_type]' ).each( function() {
580				var $this       = $( this ),
581				    elementType = $this.data( 'element_type' );
582
583				if ( ! elementType ) {
584					return;
585				}
586
587				try {
588					if ( 'widget' === elementType ) {
589						elementType = $this.data( 'widget_type' );
590
591						if ( window.elementorFrontend && window.elementorFrontend.hooks ) {
592							window.elementorFrontend.hooks.doAction( 'frontend/element_ready/widget', $this, $ );
593						}
594					}
595
596					if ( window.elementorFrontend && window.elementorFrontend.hooks ) {
597						window.elementorFrontend.hooks.doAction( 'frontend/element_ready/global', $this, $ );
598						window.elementorFrontend.hooks.doAction( 'frontend/element_ready/' + elementType, $this, $ );
599					}
600
601				} catch ( err ) {
602					console.log(err);
603					$this.remove();
604
605					return false;
606				}
607			} );
608		},
609
610		maybeDefaultFrontendInit: function ( payload ) {
611			const contentElements = payload.contentElements || [],
612				$container = payload.$container;
613
614			$container.find( '[data-is-block*="/"]' ).each( ( index, el ) => {
615				window.JetPlugins.hooks.doAction( window.JetPlugins.hookNameFromBlock( el.dataset.isBlock ), jQuery( el ) );
616			} );
617		}
618	};
619
620	/**
621	 * [jetPopup description]
622	 * @param  {[type]} $popup   [description]
623	 * @param  {[type]} settings [description]
624	 * @return {[type]}          [description]
625	 */
626	window.jetPopup = function( $popup, settings ) {
627		var self                   = this,
628			$window                = $( window ),
629			$document              = $( document ),
630			popupSettings          = settings,
631			id                     = popupSettings['id'],
632			popupId                = popupSettings['jet-popup-id'],
633			popupsLocalStorageData = {},
634			//editMode               = Boolean( window.elementorFrontend.isEditMode() ),
635			isAnimation            = false,
636			isOpen                 = false,
637			ajaxGetContentHanler   = null,
638			ajaxContentLoaded      = false,
639			focusedBeforeOpen      = null,
640			$lastTrigger           = $();
641
642		self.getAccessibilityConfig = function() {
643			return window.jetPopupData && window.jetPopupData.accessibility ? window.jetPopupData.accessibility : {};
644		};
645
646		self.getPopupLabel = function() {
647			return self.getAccessibilityConfig().popupLabel || 'Popup dialog';
648		};
649
650		self.getCloseButtonLabel = function() {
651			return self.getAccessibilityConfig().closeButtonLabel || 'Close popup';
652		};
653
654		self.isFocusableElement = function( element ) {
655			let $element = $( element ),
656				tabIndex = $element.attr( 'tabindex' );
657
658			if ( ! element || ! $element.length ) {
659				return false;
660			}
661
662			if ( $element.is( '[disabled], [hidden], [aria-hidden="true"]' ) || $element.hasClass( 'elementor-hidden' ) ) {
663				return false;
664			}
665
666			if ( undefined !== tabIndex && 0 > parseInt( tabIndex, 10 ) ) {
667				return false;
668			}
669
670			return !! ( element.offsetWidth || element.offsetHeight || element.getClientRects().length );
671		};
672
673		self.getFocusableElements = function() {
674			return $popup.find( 'a[href], area[href], input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [contenteditable="true"], [tabindex], .elementor-swiper-button, .jet-listing-dynamic-link__link' ).filter( function() {
675				return self.isFocusableElement( this );
676			} );
677		};
678
679		self.ensureDialogLabel = function() {
680			let $heading = $popup.find( '.jet-popup__container-content :header:visible:first, .jet-popup__container-content [role="heading"]:visible:first' ).first(),
681				generatedId = popupId + '-title';
682
683			$popup.removeAttr( 'aria-labelledby' );
684
685			if ( $heading.length ) {
686				if ( ! $heading.attr( 'id' ) ) {
687					$heading.attr( 'id', generatedId );
688				}
689
690				$popup.attr( 'aria-labelledby', $heading.attr( 'id' ) );
691				$popup.removeAttr( 'aria-label' );
692			} else {
693				$popup.attr( 'aria-label', self.getPopupLabel() );
694			}
695		};
696
697		self.preparePopupAccessibility = function() {
698			let $closeButton = $( '.jet-popup__close-button', $popup ).first();
699
700			$popup.attr( {
701				'role': 'dialog',
702				'aria-modal': 'true',
703				'aria-hidden': isOpen ? 'false' : 'true',
704				'tabindex': '-1',
705			} );
706
707			$( '.jet-popup__overlay, .jet-popup__container-overlay', $popup ).attr( 'aria-hidden', 'true' );
708
709			if ( $closeButton.length ) {
710				$closeButton.attr( {
711					'aria-label': self.getCloseButtonLabel(),
712				} );
713
714				if ( ! JetPopupFrontend.isNativeInteractiveElement( $closeButton[0] ) && ! $closeButton.is( '[tabindex]' ) ) {
715					$closeButton.attr( 'tabindex', '0' );
716				}
717
718				$closeButton.find( 'svg, i' ).attr( {
719					'aria-hidden': 'true',
720					'focusable': 'false',
721				} );
722
723			}
724
725			$popup.find( '.elementor-swiper-button' ).each( function() {
726				let $button = $( this );
727
728				if ( ! $button.is( '[tabindex]' ) ) {
729					$button.attr( 'tabindex', '0' );
730				}
731
732				if ( ! $button.is( '[role]' ) ) {
733					$button.attr( 'role', 'button' );
734				}
735			} );
736
737			self.ensureDialogLabel();
738		};
739
740		self.storeFocusContext = function( $trigger ) {
741			let activeElement = document.activeElement;
742
743			if ( $trigger && $trigger.length ) {
744				$lastTrigger = $trigger.first();
745				focusedBeforeOpen = $lastTrigger[0];
746			} else {
747				$lastTrigger = $();
748				focusedBeforeOpen = activeElement && document.body !== activeElement ? activeElement : null;
749			}
750
751			if ( $lastTrigger.length ) {
752				$lastTrigger.attr( 'aria-expanded', 'true' );
753			}
754		};
755
756		self.focusDefaultElement = function() {
757			let $closeButton = $( '.jet-popup__close-button', $popup ).first(),
758				$focusable = self.getFocusableElements(),
759				$target = $closeButton.length ? $closeButton : $focusable.first();
760
761			if ( ! $target.length ) {
762				$target = $( '.jet-popup__container', $popup ).first();
763			}
764
765			if ( $target.length && $target[0].focus ) {
766				window.setTimeout( function() {
767					try {
768						$target[0].focus( { preventScroll: true } );
769					} catch ( error ) {
770						$target[0].focus();
771					}
772				}, 0 );
773			}
774		};
775
776		self.restoreFocus = function() {
777			if ( $lastTrigger.length ) {
778				$lastTrigger.attr( 'aria-expanded', 'false' );
779			}
780
781			if ( focusedBeforeOpen && document.contains( focusedBeforeOpen ) && focusedBeforeOpen.focus ) {
782				try {
783					focusedBeforeOpen.focus( { preventScroll: true } );
784				} catch ( error ) {
785					focusedBeforeOpen.focus();
786				}
787			}
788
789			focusedBeforeOpen = null;
790			$lastTrigger = $();
791		};
792
793		self.moveFocusByOffset = function( offset ) {
794			let $focusable = self.getFocusableElements(),
795				activeIndex = $focusable.index( document.activeElement );
796
797			if ( ! $focusable.length ) {
798				return;
799			}
800
801			if ( -1 === activeIndex ) {
802				activeIndex = 0;
803			} else {
804				activeIndex = ( activeIndex + offset + $focusable.length ) % $focusable.length;
805			}
806
807			if ( $focusable.eq( activeIndex )[0] && $focusable.eq( activeIndex )[0].focus ) {
808				$focusable.eq( activeIndex )[0].focus();
809			}
810		};
811
812		self.handlePopupTabKey = function( event ) {
813			let $focusable = self.getFocusableElements(),
814				$firstElement = $focusable.first(),
815				$lastElement = $focusable.last();
816
817			if ( ! $focusable.length ) {
818				event.preventDefault();
819				$popup.trigger( 'focus' );
820
821				return;
822			}
823
824			if ( event.shiftKey && document.activeElement === $firstElement[0] ) {
825				event.preventDefault();
826				$lastElement[0].focus();
827			} else if ( ! event.shiftKey && document.activeElement === $lastElement[0] ) {
828				event.preventDefault();
829				$firstElement[0].focus();
830			}
831		};
832
833		self.handlePopupKeydown = function( event ) {
834			let key = event.key || '',
835				$target = $( event.target ),
836				isTypingControl = $target.is( 'input, textarea, select, [contenteditable="true"]' );
837
838			if ( ! isOpen ) {
839				return;
840			}
841
842			if ( 'Tab' === key || 9 === event.keyCode ) {
843				self.handlePopupTabKey( event );
844
845				return;
846			}
847
848			if ( ! isTypingControl && ( 'ArrowDown' === key || 40 === event.keyCode ) ) {
849				event.preventDefault();
850				self.moveFocusByOffset( 1 );
851
852				return;
853			}
854
855			if ( ! isTypingControl && ( 'ArrowUp' === key || 38 === event.keyCode ) ) {
856				event.preventDefault();
857				self.moveFocusByOffset( -1 );
858
859				return;
860			}
861
862			if ( 'Escape' === key || 27 === event.keyCode ) {
863				event.preventDefault();
864				self.hidePopup( {
865					constantly: popupSettings['show-once'],
866					popupId: popupSettings['jet-popup-id']
867				} );
868			}
869		};
870
871		self.onPopupShown = function() {
872			isOpen = true;
873			$popup.attr( 'aria-hidden', 'false' );
874			self.preparePopupAccessibility();
875			self.focusDefaultElement();
876		};
877
878		self.onPopupHidden = function() {
879			isOpen = false;
880			$popup.attr( 'aria-hidden', 'true' );
881			self.restoreFocus();
882		};
883
884		self.init = function() {
885			var popupAvailable = self.popupAvailableCheck();
886
887			if ( ! popupAvailable ) {
888				return false;
889			}
890
891			self.setLocalStorageData( popupId, 'enable' );
892
893			self.initCompatibilityHandler();
894
895			self.initOpenEvent();
896
897			self.initCloseEvent();
898			self.preparePopupAccessibility();
899			$popup.on( 'keydown.jetPopupA11y', self.handlePopupKeydown );
900
901			$window.trigger( 'jet-popup/init/after', {
902				self: self,
903				settings: popupSettings
904			} );
905		};
906
907		/**
908		 * [popupAvailableCheck description]
909		 * @return {[type]} [description]
910		 */
911		self.popupAvailableCheck = function() {
912			var storageData = self.getLocalStorageData() || {};
913
914			if ( ! storageData.hasOwnProperty( popupId ) ) {
915				return true;
916			}
917
918			var popupData     = storageData[ popupId ],
919				status        = 'enable',
920				showAgainDate = 'none';
921
922			if ( 'disable' === popupData ) {
923				return false;
924			}
925
926			if ( 'enable' === popupData ) {
927				return true;
928			}
929
930			if ( popupData.hasOwnProperty( 'status' ) ) {
931				status = popupData['status'];
932			}
933
934			if ( 'enable' === status ) {
935				return true;
936			}
937
938			if ( popupData.hasOwnProperty( 'show-again-date' ) ) {
939				showAgainDate = popupData['show-again-date'];
940			}
941
942			if ( 'none' === showAgainDate && 'disable' === status ) {
943				return false;
944			}
945
946			if ( showAgainDate < Date.now() ) {
947				return true;
948			} else {
949				return false;
950			}
951		};
952
953		/**
954		 * [initOpenEvent description]
955		 * @return {[type]} [description]
956		 */
957		self.initOpenEvent = function() {
958
959			$window.trigger( 'jet-popup/init-events/before', {
960				self: self,
961				settings: popupSettings
962			} );
963
964			switch ( popupSettings['open-trigger'] ) {
965				case 'page-load':
966					self.pageLoadEvent( popupSettings['page-load-delay'] );
967				break;
968
969				case 'user-inactive':
970					self.userInactiveEvent( popupSettings['user-inactivity-time'] );
971				break;
972
973				case 'scroll-trigger':
974					self.scrollPageEvent( popupSettings['scrolled-to'] );
975				break;
976
977				case 'try-exit-trigger':
978					self.tryExitEvent();
979				break;
980
981				case 'on-date':
982					self.onDateEvent( popupSettings['on-date'] );
983				break;
984
985				case 'on-time':
986					self.onTimeEvent( popupSettings['on-time-start'], popupSettings['on-time-end'] );
987				break;
988
989				case 'on-date-and-time':
990					self.onTimeAndDateEvent( popupSettings['start-date-and-time'], popupSettings['end-date-and-time'] );
991				break;
992
993				case 'weekly-schedule':
994					self.onWeekdaysAndTimeEvent(
995						popupSettings['on-weekdays'],
996						popupSettings['on-week-time-start'],
997						popupSettings['on-week-time-end']
998					);
999				break;
1000
1001				case 'custom-selector':
1002					self.onCustomSelector( popupSettings['custom-selector'] );
1003				break;$scope
1004			}
1005
1006			$window.on('jet-popup-open-trigger', function( event ) {
1007				var popupData   = event.popupData || {},
1008					triggeredBy = event.triggeredBy || false,
1009					popupUniqId = popupData.popupId || false,
1010					constantly  = popupData.constantly;
1011			
1012				if ( popupUniqId == popupId ) {
1013					if ( $popup.hasClass( 'jet-popup--hide-state' )) {
1014						self.showPopup( popupData, triggeredBy );
1015					} else {
1016						self.hidePopup( {
1017							constantly: constantly,
1018							popupId: popupUniqId,
1019						} );
1020					}
1021				}
1022			});
1023
1024			$window.on( 'jet-popup-close-trigger', function( event ) {
1025				var popupData   = event.popupData || {},
1026					popupUniqId = popupData.popupId,
1027					constantly  = popupData.constantly;
1028
1029				if ( popupUniqId == popupId ) {
1030					self.hidePopup( {
1031						popupId: popupUniqId,
1032						constantly: constantly,
1033					} );
1034				}
1035			});
1036
1037			$window.trigger( 'jet-popup/init-events/after', {
1038				self: self,
1039				settings: popupSettings
1040			} );
1041		};
1042
1043		/**
1044		 * [initOnCloseEvent description]
1045		 * @return {[type]} [description]
1046		 */
1047		self.initOnCloseEvent = function() {
1048
1049			var $htmlBody = $( 'html, body' );
1050
1051			if ( 'scroll-to-top' === popupSettings['close-event'] ) {
1052				$htmlBody.animate( { scrollTop: 0 }, 'slow' );
1053			}
1054
1055			if ( 'scroll-to-anchor' === popupSettings['close-event'] ) {
1056				var anchor = $( '#' + popupSettings['сlose-event-anchor'] );
1057
1058				if ( anchor.length ) {
1059					$htmlBody.animate( { scrollTop: anchor.offset().top }, 'slow' );
1060				}
1061			}
1062		}
1063
1064		/**
1065		 * [initCloseEvent description]
1066		 * @return {[type]} [description]
1067		 */
1068		self.initCloseEvent = function() {
1069
1070			$popup.on( 'click', '.jet-popup__close-button', function( event ) {
1071				var target = event.currentTarget;
1072
1073				self.hidePopup( {
1074					constantly: popupSettings['show-once'],
1075					popupId: popupSettings['jet-popup-id']
1076				} );
1077				self.initOnCloseEvent();
1078			} );
1079
1080			if ( popupSettings['close-on-overlay-click'] ) {
1081				$popup.on( 'click', '.jet-popup__overlay', function( event ) {
1082					var target = event.currentTarget;
1083
1084					self.hidePopup( {
1085						constantly: popupSettings['show-once'],
1086						popupId: popupSettings['jet-popup-id']
1087					} );
1088					self.initOnCloseEvent();
1089				} );
1090			}
1091
1092			$document.on( 'keyup.jetPopup', function( event ) {
1093				var key = event.keyCode;
1094
1095				if ( 27 === key && isOpen ) {
1096					self.hidePopup( {
1097						constantly: popupSettings['show-once'],
1098						popupId: popupSettings['jet-popup-id']
1099					} );
1100				}
1101			} );
1102		};
1103
1104		/**
1105		 * [initCompatibilityHandler description]
1106		 * @return {[type]} [description]
1107		 */
1108		self.initCompatibilityHandler = function() {
1109			var $elementorProFormWidget = $( '.elementor-widget-form', $popup );
1110
1111			if ( $elementorProFormWidget[0] ) {
1112				$elementorProFormWidget.each( function() {
1113					var $this = $( this ),
1114						$form = $( '.elementor-form', $this );
1115
1116						$form.on( 'submit_success', function() {
1117
1118							if ( true !== popupSettings['close-after-form-submit'] ) {
1119								return;
1120							}
1121
1122							let delay = parseInt( popupSettings['close-after-form-delay'] || 0 );
1123							delay = delay * 1000;
1124						
1125							setTimeout( function() {
1126								$window.trigger( {
1127									type: 'jet-popup-close-trigger',
1128									popupData: {
1129										popupId: popupId,
1130										constantly: false
1131									}
1132								} );
1133							}, delay );
1134						
1135						});
1136				} );
1137			}
1138
1139			$( document ).on( 'jet-form-builder/ajax/on-success', function( event ) {
1140	
1141				if ( true !== popupSettings['close-after-form-submit'] ) {
1142					return;
1143				}
1144			
1145				let delay = parseInt( popupSettings['close-after-form-delay'] || 0 );
1146				delay = delay * 1000;
1147			
1148				setTimeout( function() {
1149					$window.trigger({
1150						type: 'jet-popup-close-trigger',
1151						popupData: {
1152							popupId: popupId,
1153							constantly: false
1154						}
1155					});
1156				}, delay );
1157			
1158			});
1159		};
1160
1161		/**
1162		 * Handle popup opening on page load event.
1163		 *
1164		 * @param {number} openDelay Delay before opening the popup (in seconds).
1165		 * @return {void}
1166		 */
1167		self.autoClosePopup = function() {
1168
1169			if ( ! popupSettings['automatically-close'] ) {
1170				return;
1171			}
1172
1173			let delay = parseInt( popupSettings['automatically-close'], 10 );
1174		
1175			if ( ! delay ) {
1176				return;
1177			}
1178		
1179			setTimeout( function() {
1180		
1181				if ( isOpen ) {
1182					self.hidePopup( {
1183						popupId: popupId,
1184						constantly: false
1185					} );
1186				}
1187		
1188			}, delay * 1000 );
1189		
1190		};
1191
1192		/**
1193		 * Page on load event
1194		 *
1195		 * @param  {int} openDelay Open delay time.
1196		 * @return {void}
1197		 */
1198		self.pageLoadEvent = function( openDelay ) {
1199			var delay = +openDelay || 0;
1200
1201			delay = delay * 1000;
1202
1203			$( function() {
1204				setTimeout( function() {
1205					self.showPopup();
1206				}, delay );
1207			} );
1208		};
1209
1210		/**
1211		 * User Inactivity event
1212		 *
1213		 * @param  {int} inactiveDelay [description]
1214		 * @return {void}
1215		 */
1216		self.userInactiveEvent = function( inactiveDelay ) {
1217			var delay      = +inactiveDelay || 0,
1218				isInactive = true;
1219
1220			delay = delay * 1000;
1221
1222			setTimeout( function() {
1223				if ( isInactive ) {
1224					self.showPopup();
1225				}
1226			}, delay );
1227
1228			$( document ).on( 'click focus resize keyup scroll', function() {
1229				isInactive = false;
1230			} );
1231		};
1232
1233		/**
1234		 * Scrolling Page Event
1235		 *
1236		 * @param  {int} scrollingValue Scrolling porgress value
1237		 * @return {void}
1238		 */
1239		self.scrollPageEvent = function( scrollingValue ) {
1240			var scrolledValue  = +scrollingValue || 0;
1241
1242			$window.on( 'scroll.cherryJetScrollEvent resize.cherryJetResizeEvent', function() {
1243				var $window          = $( window ),
1244					windowHeight     = $window.height(),
1245					documentHeight   = $( document ).height(),
1246					scrolledHeight   = documentHeight - windowHeight,
1247					scrolledProgress = Math.max( 0, Math.min( 1, $window.scrollTop() / scrolledHeight ) ) * 100;
1248
1249				if ( scrolledProgress >= scrolledValue ) {
1250					$window.off( 'scroll.cherryJetScrollEvent resize.cherryJetResizeEvent' );
1251					self.showPopup();
1252				}
1253			} ).trigger( 'scroll.cherryJetResizeEvent' );
1254		};
1255
1256		/**
1257		 * Viewport leave event
1258		 *
1259		 * @return {void}
1260		 */
1261		self.tryExitEvent = function() {
1262			var pageY = 0;
1263
1264			$( document ).on( 'mouseleave', 'body', function( event ) {
1265
1266				pageY = event.pageY - $window.scrollTop();
1267
1268				if ( 0 > pageY && $popup.hasClass( 'jet-popup--hide-state' ) ) {
1269					self.showPopup();
1270				}
1271			} );
1272		};
1273
1274		/**
1275		 * onDateEvent Event
1276		 *
1277		 * @return {void}
1278		 */
1279		self.onDateEvent = function( date ) {
1280			var nowDate   = Date.now(),
1281				startDate = Date.parse( date );
1282
1283			if ( startDate < nowDate ) {
1284
1285				setTimeout( function() {
1286					self.showPopup();
1287				}, 500 );
1288			}
1289		}
1290
1291		self.onWeekdaysAndTimeEvent = function( days = [], startTime = '00:00', endTime = '23:59' ) {
1292
1293			if ( ! days || ! days.length ) {
1294				return;
1295			}
1296		
1297			var nowTimeStamp = Date.now(),
1298				nowDate = new Date(),
1299				currentDay = nowDate.toLocaleString('en-US', { weekday: 'short' }).toLowerCase();
1300		
1301
1302			days = days.map( day => day.toLowerCase() );
1303		
1304			if ( ! days.includes( currentDay ) ) {
1305				return;
1306			}
1307		
1308			startTime = '' !== startTime ? startTime : '00:00';
1309			endTime   = '' !== endTime ? endTime : '23:59';
1310		
1311			var dateTimeFormat = new Intl.DateTimeFormat( 'en', { year: 'numeric', month: 'short', day: '2-digit' } ),
1312				[ { value: month },,{ value: day },,{ value: year } ] = dateTimeFormat.formatToParts( nowTimeStamp );
1313		
1314			var startDateTime = `${ month }. ${ day }, ${ year } ${ startTime }`,
1315				endDateTime   = `${ month }. ${ day }, ${ year } ${ endTime }`;
1316		
1317			var startTimeStamp = Date.parse( startDateTime ),
1318				endTimeStamp   = Date.parse( endDateTime );
1319		
1320			if ( startTimeStamp < nowTimeStamp && nowTimeStamp < endTimeStamp ) {
1321				setTimeout( function() {
1322					self.showPopup();
1323				}, 500 );
1324			}
1325		};
1326
1327		self.onTimeEvent = function( startTime = '00:00', endTime = '23:59' ) {
1328			var startTime = '' !== startTime ? startTime : '00:00',
1329				endTime = '' !== endTime ? endTime : '23:59',
1330				nowTimeStamp = Date.now(),
1331				dateTimeFormat = new Intl.DateTimeFormat( 'en', { year: 'numeric', month: 'short', day: '2-digit' } ),
1332				[ { value: month },,{ value: day },,{ value: year } ] = dateTimeFormat.formatToParts( nowTimeStamp ),
1333				startTime = `${ month }. ${ day }, ${ year } ${ startTime }`,
1334				endTime = `${ month }. ${ day }, ${ year } ${ endTime }`,
1335				startTimeStamp = Date.parse( startTime ),
1336				endTimeStamp = Date.parse( endTime );
1337
1338			if ( ( startTimeStamp < nowTimeStamp ) && ( nowTimeStamp < endTimeStamp ) ) {
1339				setTimeout( function() {
1340					self.showPopup();
1341				}, 500 );
1342			}
1343		}
1344
1345
1346		self.onTimeAndDateEvent = function( start, end ) {
1347
1348			var nowDateStamp   = Date.now(),
1349			startDateStamp = Date.parse( start ),
1350			endDateStamp = Date.parse( end );
1351
1352			if ( ( startDateStamp < nowDateStamp ) && ( nowDateStamp < endDateStamp ) ) {
1353				setTimeout( function() {
1354					self.showPopup();
1355				}, 500 );
1356			}
1357			
1358		}
1359
1360		/**
1361		 * Check DOM Loaded Selector
1362		 * @param  {[type]} selector [description]
1363		 * @return {[type]}          [description]
1364		 */
1365
1366		self.checkLoadedSelector = function( selector ) {
1367
1368			//Check Listing Grid Lazy Load
1369			$( document ).on( 'jet-engine/listing-grid/after-lazy-load', function() {
1370				self.onCustomSelector ( selector );
1371			});
1372
1373			//Check Open Mobile Menu
1374			$( '.jet-mobile-menu__toggle' ).closest( '.jet-mobile-menu__instance--slide-out-layout' ).on( 'click', function() {
1375				self.onCustomSelector ( selector );
1376			});
1377
1378        }
1379
1380		/**
1381		 * [onCustomSelector description]
1382		 * @param  {[type]} selector [description]
1383		 * @return {[type]}          [description]
1384		 */
1385		self.onCustomSelector = function( selector ) {
1386
1387			let $selector = $( selector );
1388
1389			if ( $selector[0] ) {
1390				$( 'body' ).off( 'click.jetPopup', selector ).on( 'click.jetPopup', selector, function( event ) {
1391					event.preventDefault();
1392			
1393					let $this   = $( this );
1394					let popupId = $this.data( 'popup' );
1395					let $popup  = $( '#jet-popup-' + popupId );
1396			
1397					if ( $popup.length && $popup.hasClass( 'jet-popup--show-state' ) ) {
1398						self.hidePopup( popupId, false );
1399					} else {
1400						self.showPopup( popupId, $this );
1401					}
1402				} );
1403			} else {
1404				self.checkLoadedSelector( selector );
1405			}
1406		}
1407
1408		/**
1409		 * Show Popup
1410		 *
1411		 * @return {void}
1412		 */
1413		self.showPopup = function( data, $trigger ) {
1414			var popupData              = data || {},
1415				animeOverlay           = null,
1416				animeContainer         = null,
1417				animeOverlaySettings   = jQuery.extend(
1418					{
1419						targets: $( '.jet-popup__overlay', $popup )[0]
1420					},
1421					self.avaliableEffects[ 'fade' ][ 'show' ]
1422				);
1423
1424			$trigger = $trigger || false;
1425
1426			if ( ! self.popupAvailableCheck() ) {
1427				return false;
1428			}
1429
1430			self.storeFocusContext( $trigger );
1431
1432			animeOverlay = anime( animeOverlaySettings );
1433
1434			$popup.toggleClass( 'jet-popup--hide-state jet-popup--show-state' );
1435
1436			if ( popupSettings['prevent-scrolling'] ) {
1437				$( 'body' ).addClass( 'jet-popup-prevent-scroll' );
1438			}
1439
1440			popupData = JetPopupFrontend.maybeExtendPopupData( popupData, $trigger );
1441			popupData = window.JetPlugins.hooks.applyFilters( 'jet-popup.show-popup.data', popupData, $popup, $trigger );
1442			popupData = JetPopupFrontend.getTooltipPopupData( popupData, $trigger );
1443
1444			self.showContainer( popupData );
1445		};
1446
1447		/**
1448		 * [showContainer description]
1449		 * @return {[type]} [description]
1450		 */
1451		self.showContainer = function( data ) {
1452			var popupData        = data || {},
1453				popupDefaultData = {
1454					forceLoad: popupSettings['force-ajax'] || false, // Trigger Ajax Every Time
1455					customContent: '' // Show Popup with Custom Content
1456				},
1457				animeContainerInstance   = null,
1458				$popupContainer  = $( '.jet-popup__container', $popup ),
1459				$content         = $( '.jet-popup__container-content', $popup ),
1460				animeContainer   = jQuery.extend(
1461					{
1462						targets: $( '.jet-popup__container', $popup )[0],
1463						begin: function( anime ) {
1464							isAnimation = true;
1465
1466							$window.trigger( 'jet-popup/show-event/before-show', {
1467								self: self,
1468								data: popupData,
1469								anime: anime
1470							} );
1471						},
1472						complete: function( anime ) {
1473							isAnimation = false;
1474
1475							self.autoClosePopup();
1476							self.onPopupShown();
1477
1478							$window.trigger( 'jet-popup/show-event/after-show', {
1479								self: self,
1480								data: popupData,
1481								anime: anime
1482							} );
1483						}
1484					},
1485					self.avaliableEffects[ popupSettings['animation'] ][ 'show' ]
1486
1487				);
1488
1489			popupData = jQuery.extend( popupDefaultData, popupData );
1490
1491			// init Custom popup content
1492			if ( '' !== popupData.customContent ) {
1493				$content.html( popupData.customContent );
1494				self.elementorFrontendInit();
1495
1496				// Show Popup Container
1497				animeContainerInstance = anime( animeContainer );
1498
1499				$window.trigger( 'jet-popup/render-content/render-custom-content', {
1500					self: self,
1501					popup_id: id,
1502					data: popupData,
1503				} );
1504
1505				return false;
1506			}
1507
1508			// Dynamic listing popups share one pre-rendered DOM node. Load the
1509			// selected listing item through the existing content endpoint.
1510			let hasDynamicContext = popupData.postId && ( popupData.isJetEngine || popupData.loopDynamicPopup );
1511
1512			if ( hasDynamicContext ) {
1513				popupData.forceLoad = true;
1514				ajaxContentLoaded = false;
1515			}
1516
1517			if ( ! popupSettings['use-ajax'] && ! hasDynamicContext ) {
1518				// Show Popup Container
1519				animeContainerInstance = anime( animeContainer );
1520
1521				$window.trigger( 'jet-popup/render-content/render-custom-content', {
1522					self: self,
1523					popup_id: id,
1524					data: popupData,
1525				} );
1526
1527				return false;
1528			}
1529
1530			if ( popupData.forceLoad ) {
1531				ajaxContentLoaded = false;
1532			}
1533
1534			if ( ajaxContentLoaded ) {
1535				// Show Popup Container
1536				animeContainerInstance = anime( animeContainer );
1537
1538				$window.trigger( 'jet-popup/render-content/show-content', {
1539					self: self,
1540					popup_id: id,
1541					data: popupData,
1542				} );
1543
1544				return false;
1545			}
1546
1547			popupData = jQuery.extend( popupData, {
1548				'popup_id': id,
1549				'page_url': window.location.href
1550			} );
1551
1552			ajaxGetContentHanler = jQuery.ajax( {
1553				type: 'POST',
1554				url: window.jetPopupData.ajax_url,
1555				data: {
1556					'action': 'jet_popup_get_content',
1557					'data': popupData
1558				},
1559				beforeSend: function( jqXHR, ajaxSettings ) {
1560
1561					if ( null !== ajaxGetContentHanler ) {
1562						ajaxGetContentHanler.abort();
1563					}
1564
1565					// Before ajax send Trigger
1566					$window.trigger( 'jet-popup/render-content/ajax/before-send', {
1567						self: self,
1568						popup_id: id,
1569						data: popupData
1570					} );
1571
1572					$popup.addClass( 'jet-popup--loading-state' );
1573				},
1574				error: function( jqXHR, ajaxSettings ) {},
1575				success: function( data, textStatus, jqXHR ) {
1576					// WordPress wraps wp_send_json_error() payloads in data.
1577					if ( data && false === data.success && data.data ) {
1578						data = data.data;
1579					}
1580
1581					var successType = data.type,
1582						contentData = data.content || false,
1583						$popupContainer = $( '.jet-popup__container-content', $popup );
1584
1585					$popup.removeClass( 'jet-popup--loading-state' );
1586
1587					if ( 'error' === successType ) {
1588						var message = data.message;
1589
1590						$content.empty().append( $( '<h3>' ).text( message ) );
1591
1592						// Show Popup Container
1593						animeContainerInstance = anime( animeContainer );
1594					}
1595
1596					if ( 'success' === successType ) {
1597						let popupContent         = contentData['content'],
1598							popupContentElements = contentData['contentElements'],
1599						    popupScripts         = contentData['scripts'],
1600						    popupStyles          = contentData['styles'],
1601							popupAfterScripts   = contentData['afterScripts'];
1602
1603						for ( let { handle: scriptHandler, src: scriptSrc } of popupScripts ) {
1604							JetPopupFrontend.addedAssetsPromises.push( JetPopupFrontend.loadScriptAsync( scriptHandler, scriptSrc ) );
1605						}
1606
1607						if ( popupStyles && Object.keys( popupStyles ).length > 0 ) {
1608							for ( let styleHandler in popupStyles ) {
1609								JetPopupFrontend.addedAssetsPromises.push( JetPopupFrontend.loadStyle( styleHandler, popupStyles[ styleHandler ] ) );
1610							}
1611						}
1612
1613						JetPopupFrontend.assetsLoaderPromise().then( async function( value ) {
1614							ajaxContentLoaded = true;
1615
1616							// Ajax Success Trigger
1617							$window.trigger( 'jet-popup/render-content/ajax/success', {
1618								self: self,
1619								popup_id: id,
1620								data: popupData,
1621								request: data
1622							} );
1623
1624							// Render content
1625							if ( popupContent ) {
1626								$popupContainer.html( popupContent );
1627							}
1628
1629							if ( popupAfterScripts.length ) {
1630								await Promise.all( popupAfterScripts.map(
1631									( { handle, src } ) => JetPopupFrontend.loadScriptAsync( handle, src )
1632								) );
1633							}
1634
1635							// Before ajax frontend init
1636							$( window ).trigger( 'jet-popup/ajax/frontend-init/before', {
1637								$container: $popupContainer,
1638								content: popupContent,
1639								contentElements: popupContentElements,
1640								contentType: popupSettings['content-type'],
1641							} );
1642
1643							// Frontend init
1644							$( window ).trigger( 'jet-popup/ajax/frontend-init', {
1645								$container: $popupContainer,
1646								content: popupContent,
1647								contentElements: popupContentElements,
1648								contentType: popupSettings['content-type'],
1649							} );
1650
1651							// after ajax frontend init
1652							$( window ).trigger( 'jet-popup/ajax/frontend-init/after', {
1653								$container: $popupContainer,
1654								content: popupContent,
1655								contentElements: popupContentElements,
1656								contentType: popupSettings['content-type'],
1657							} );
1658
1659							// Show Popup Container
1660							animeContainerInstance = anime( animeContainer );
1661
1662						}, function( reason ) {
1663							console.log( 'Assets Loaded Error' );
1664						} );
1665					}
1666				}
1667			} );
1668		};
1669
1670		/**
1671		 * Hide Popup
1672		 *
1673		 * @return {void}
1674		 */
1675		self.hidePopup = function ( data ) {
1676			var popupData              = data || {},
1677				$content               = $( '.jet-popup__container-content', $popup ),
1678				constantly             = popupData.constantly || false,
1679				animeOverlay           = null,
1680				animeContainer         = null,
1681				animeOverlaySettings   = jQuery.extend( { targets: $( '.jet-popup__overlay', $popup )[0] }, self.avaliableEffects[ 'fade' ][ 'hide' ] ),
1682				animeContainerSettings = jQuery.extend(
1683					{
1684						targets: $( '.jet-popup__container', $popup )[0],
1685						begin: function( anime ) {
1686							isAnimation = true;
1687
1688							$window.trigger( 'jet-popup/hide-event/before-hide', {
1689								self: self,
1690								data: popupData,
1691								anime: anime
1692							} );
1693						},
1694						complete: function( anime ) {
1695							isAnimation = false;
1696							$popup.toggleClass( 'jet-popup--show-state jet-popup--hide-state' );
1697
1698							if ( popupSettings['use-ajax'] && popupSettings['force-ajax'] ) {
1699								$content.html( '' );
1700							}
1701
1702							if ( popupSettings['prevent-scrolling'] && !$( '.jet-popup--show-state' )[0] ) {
1703								$( 'body' ).removeClass( 'jet-popup-prevent-scroll' );
1704							}
1705
1706							self.onPopupHidden();
1707
1708							// After Popup Hide Action
1709							$window.trigger( 'jet-popup/hide-event/after-hide', {
1710								self: self,
1711								data: popupData,
1712								anime: anime
1713							} );
1714						}
1715					},
1716					self.avaliableEffects[ popupSettings['animation'] ][ 'hide' ]
1717				);
1718
1719			if ( constantly ) {
1720				self.setLocalStorageData( popupId, 'disable' );
1721			}
1722
1723			if ( isAnimation ){
1724				return false;
1725			}
1726
1727			if ( $popup.hasClass('jet-popup--show-state') ) {
1728				animeOverlay = anime( animeOverlaySettings );
1729				animeContainer = anime( animeContainerSettings );
1730			}
1731
1732			// On Hide Handler
1733			self.onHidePopupAction();
1734
1735			// Before Popup Hide Action
1736			$window.trigger( 'jet-popup/close-hide-event/before-hide', {
1737				self: self,
1738				data: popupData
1739			} );
1740		};
1741
1742		/**
1743		 * [elementorFrontendInit description]
1744		 * @return {[type]} [description]
1745		 */
1746		self.elementorFrontendInit = function() {
1747			var $content = $( '.jet-popup__container-content', $popup );
1748
1749			$content.find( 'div[data-element_type]' ).each( function() {
1750				var $this       = $( this ),
1751					elementType = $this.data( 'element_type' );
1752
1753				if (!elementType) {
1754					return;
1755				}
1756
1757				try {
1758					if( 'widget' === elementType ){
1759						elementType = $this.data( 'widget_type' );
1760						window.elementorFrontend.hooks.doAction( 'frontend/element_ready/widget', $this, $ );
1761					}
1762					window.elementorFrontend.hooks.doAction( 'frontend/element_ready/' + elementType, $this, $ );
1763
1764				} catch( err ) {
1765					console.log(err);
1766
1767					$this.remove();
1768
1769					return false;
1770				}
1771
1772			});
1773
1774			// On Show Handler
1775			self.onShowPopupAction();
1776		}
1777
1778		/**
1779		 * [onShowPopupAction description]
1780		 * @return {[type]} [description]
1781		 */
1782		self.onShowPopupAction = function() {};
1783
1784		/**
1785		 * [onHidePopupAction description]
1786		 * @return {[type]} [description]
1787		 */
1788		self.onHidePopupAction = function() {};
1789
1790		/**
1791		 * Avaliable Effects
1792		 */
1793
1794		const useCustomDuration = popupSettings['animation_custom_duration'] === true;
1795
1796		let inDuration  = false;
1797		let outDuration = false;
1798		
1799		if ( useCustomDuration ) {
1800			inDuration  = popupSettings['animation_in_duration'];
1801			outDuration = popupSettings['animation_out_duration'];
1802		}
1803
1804		self.avaliableEffects = {
1805			'none': {
1806				'show': {
1807					duration: inDuration || 0,
1808					opacity: { value: [1, 1] }
1809				},
1810				'hide': {
1811					duration: outDuration || 0,
1812					opacity: { value: [1, 1] }
1813				}
1814			},
1815		
1816			'fade': {
1817				'show': {
1818					opacity: { value: [0, 1], duration: inDuration || 600, easing: 'easeOutQuart' }
1819				},
1820				'hide': {
1821					opacity: { value: [1, 0], duration: outDuration || 400, easing: 'easeOutQuart' }
1822				}
1823			},
1824		
1825			'zoom-in': {
1826				'show': {
1827					duration: inDuration || 500,
1828					easing: 'easeOutQuart',
1829					opacity: { value: [0, 1] },
1830					scale: { value: [0.75, 1] }
1831				},
1832				'hide': {
1833					duration: outDuration || 400,
1834					easing: 'easeOutQuart',
1835					opacity: { value: [1, 0] },
1836					scale: { value: [1, 0.75] }
1837				}
1838			},
1839		
1840			'zoom-out': {
1841				'show': {
1842					duration: inDuration || 500,
1843					easing: 'easeOutQuart',
1844					opacity: { value: [0, 1] },
1845					scale: { value: [1.25, 1] }
1846				},
1847				'hide': {
1848					duration: outDuration || 400,
1849					easing: 'easeOutQuart',
1850					opacity: { value: [1, 0] },
1851					scale: { value: [1, 1.25] }
1852				}
1853			},
1854		
1855			'rotate': {
1856				'show': {
1857					duration: inDuration || 500,
1858					easing: 'easeOutQuart',
1859					opacity: { value: [0, 1] },
1860					scale: { value: [0.75, 1] },
1861					rotate: { value: [-65, 0] }
1862				},
1863				'hide': {
1864					duration: outDuration || 400,
1865					easing: 'easeOutQuart',
1866					opacity: { value: [1, 0] },
1867					scale: { value: [1, 0.9] }
1868				}
1869			},
1870		
1871			'move-up': {
1872				'show': {
1873					duration: inDuration || 500,
1874					easing: 'easeOutExpo',
1875					opacity: { value: [0, 1] },
1876					translateY: { value: [50, 1] }
1877				},
1878				'hide': {
1879					duration: outDuration || 400,
1880					easing: 'easeOutQuart',
1881					opacity: { value: [1, 0] },
1882					translateY: { value: [1, 50] }
1883				}
1884			},
1885		
1886			'flip-x': {
1887				'show': {
1888					duration: inDuration || 500,
1889					easing: 'easeOutExpo',
1890					opacity: { value: [0, 1] },
1891					rotateX: { value: [65, 0] }
1892				},
1893				'hide': {
1894					duration: outDuration || 400,
1895					easing: 'easeOutQuart',
1896					opacity: { value: [1, 0] }
1897				}
1898			},
1899		
1900			'flip-y': {
1901				'show': {
1902					duration: inDuration || 500,
1903					easing: 'easeOutExpo',
1904					opacity: { value: [0, 1] },
1905					rotateY: { value: [65, 0] }
1906				},
1907				'hide': {
1908					duration: outDuration || 400,
1909					easing: 'easeOutQuart',
1910					opacity: { value: [1, 0] }
1911				}
1912			},
1913		
1914			'bounce-in': {
1915				'show': {
1916					opacity: { value: [0, 1], duration: inDuration || 500, easing: 'easeOutQuart' },
1917					scale: {
1918						value: [0.2, 1],
1919						duration: inDuration || 800,
1920						elasticity: function(el, i, l) { return (400 + i * 200); }
1921					}
1922				},
1923				'hide': {
1924					duration: outDuration || 400,
1925					easing: 'easeOutQuart',
1926					opacity: { value: [1, 0] },
1927					scale: { value: [1, 0.8] }
1928				}
1929			},
1930		
1931			'bounce-out': {
1932				'show': {
1933					opacity: { value: [0, 1], duration: inDuration || 500, easing: 'easeOutQuart' },
1934					scale: {
1935						value: [1.8, 1],
1936						duration: inDuration || 800,
1937						elasticity: function(el, i, l) { return (400 + i * 200); }
1938					}
1939				},
1940				'hide': {
1941					duration: outDuration || 400,
1942					easing: 'easeOutQuart',
1943					opacity: { value: [1, 0] },
1944					scale: { value: [1, 1.5] }
1945				}
1946			},
1947		
1948			'slide-in-up': {
1949				'show': {
1950					opacity: { value: [0, 1], duration: inDuration || 400, easing: 'easeOutQuart' },
1951					translateY: { value: ['100vh', 0], duration: inDuration || 750, easing: 'easeOutQuart' }
1952				},
1953				'hide': {
1954					duration: outDuration || 400,
1955					easing: 'easeInQuart',
1956					opacity: { value: [1, 0] },
1957					translateY: { value: [0, '100vh'] }
1958				}
1959			},
1960		
1961			'slide-in-right': {
1962				'show': {
1963					opacity: { value: [0, 1], duration: inDuration || 400, easing: 'easeOutQuart' },
1964					translateX: { value: ['100vw', 0], duration: inDuration || 750, easing: 'easeOutQuart' }
1965				},
1966				'hide': {
1967					duration: outDuration || 400,
1968					easing: 'easeInQuart',
1969					opacity: { value: [1, 0] },
1970					translateX: { value: [0, '100vw'] }
1971				}
1972			},
1973		
1974			'slide-in-down': {
1975				'show': {
1976					opacity: { value: [0, 1], duration: inDuration || 400, easing: 'easeOutQuart' },
1977					translateY: { value: ['-100vh', 0], duration: inDuration || 750, easing: 'easeOutQuart' }
1978				},
1979				'hide': {
1980					duration: outDuration || 400,
1981					easing: 'easeInQuart',
1982					opacity: { value: [1, 0] },
1983					translateY: { value: [0, '-100vh'] }
1984				}
1985			},
1986		
1987			'slide-in-left': {
1988				'show': {
1989					opacity: { value: [0, 1], duration: inDuration || 400, easing: 'easeOutQuart' },
1990					translateX: { value: ['-100vw', 0], duration: inDuration || 750, easing: 'easeOutQuart' }
1991				},
1992				'hide': {
1993					duration: outDuration || 400,
1994					easing: 'easeInQuart',
1995					opacity: { value: [1, 0] },
1996					translateX: { value: [0, '-100vw'] }
1997				}
1998			}
1999		};
2000		
2001		
2002		/**
2003		 * Get localStorage data.
2004		 *
2005		 * @return {object|boolean}
2006		 */
2007		self.getLocalStorageData = function() {
2008
2009			try {
2010				return JSON.parse( localStorage.getItem( 'jetPopupData' ) );
2011			} catch ( e ) {
2012				return false;
2013			}
2014		};
2015
2016		/**
2017		 * Set localStorage data.
2018		 *
2019		 * @return {object|boolean}
2020		 */
2021		self.setLocalStorageData = function( id, status ) {
2022
2023			var jetPopupData = self.getLocalStorageData() || {},
2024				newData      = {};
2025
2026			newData['status'] = status;
2027
2028			if ( 'disable' === status ) {
2029
2030				var nowDate             = Date.now(),
2031					showAgainDelay      = popupSettings['show-again-delay'],
2032					showAgainDate       = 'none' !== showAgainDelay ? ( nowDate + showAgainDelay ) : 'none';
2033
2034				newData['show-again-date'] = showAgainDate;
2035			}
2036
2037			jetPopupData[ id ] = newData;
2038
2039			localStorage.setItem( 'jetPopupData', JSON.stringify( jetPopupData ) );
2040		}
2041
2042	}
2043
2044	window.JetPopupFrontend.init();
2045
2046}( 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.