PageSourceSearch

https://lifehappens.org/wp-content/plugins/divi-modal-popup/divi-5…/ModalPopup/assets/script.min.js?ver=2.0.3

js lifehappens.org collected 2026-09-24 09:26:48 UTC 19,062 bytes, 472 lines download raw bytes

1( function( $ ) {
2	let windowWidth = $(window).width();
3	$.fn.DiviModalPopupRemoveClasses = function( orderClass ) {
4		let $this   = this,
5		$classes    = el_modal_popup_get_module_classes();
6
7		$classes.push(orderClass);
8		$this.removeClass( $classes.join(' ') );
9
10		$this.css( {
11			'animation-delay'           : '',
12			'animation-duration'        : '',
13			'animation-timing-function' : '',
14			'opacity'                   : '',
15			'transform'                 : '',
16			'filter'                    : '',
17		} );
18		return this;
19	};
20	
21	$.fn.DiviModalPopup = function( options ) {
22		let defaults = {
23			action: '',
24			href: '#',
25			delay: '0',
26		};
27		
28		let $modal   = this,
29			$timeOut = 0,
30			$options = $.extend({}, defaults, options);
31
32		if ( 'undefined' !== typeof( $modal.find('.el_modal_popup_inner_wrap').data('animation-duration') ) ) {
33			$timeOut = parseFloat( $modal.find('.el_modal_popup_inner_wrap').data('animation-duration') );
34			if ( windowWidth < 981 ) {
35				if ( 'undefined' !== typeof( $modal.find('.el_modal_popup_inner_wrap').data('animation-duration-tablet') ) && '' !== $modal.find('.el_modal_popup_wrapper').data('animation-duration-tablet') ) {
36					$timeOut = parseFloat( $modal.find('.el_modal_popup_inner_wrap').data('animation-duration-tablet') );
37				}
38			} else if ( windowWidth < 768 ) {
39				if ( 'undefined' !== typeof( $modal.find('.el_modal_popup_inner_wrap').data('animation-duration-phone') ) && '' !== $modal.find('.el_modal_popup_wrapper').data('animation-duration-phone') ) {
40					$timeOut = parseFloat( $modal.find('.el_modal_popup_inner_wrap').data('animation-duration-phone') );
41				}
42			}
43		}
44
45		if ( 'open' === $options.action ) {
46			let delay = parseInt( $options.delay );
47			setTimeout( function() {
48
49				$('body').find('.el_modal_popup').removeClass('el_modal_popup_active_modal');
50				$('body').addClass('el_modal_popup_active');
51				$modal.addClass('el_modal_popup_active_modal');
52
53				/* The wrapper was just unhidden (display:none -> flex) in this same
54				   tick, so its subtree has never been laid out. Force a reflow before
55				   triggering the entrance animation on the first open, otherwise the
56				   browser has no "before" frame to animate from and just snaps to the
57				   end state instantly. */
58				void $modal.find('.el_modal_popup_wrapper')[0].offsetWidth;
59
60				if ( 'off' === $modal.find('.el_modal_popup_wrapper').data('disable-website-scroll') ) {
61					$('body').addClass('el_modal_popup_enable_scroll');
62				}
63				setTimeout( function() {
64					$('body').find('.el_modal_popup').removeClass('el_modal_popup_opened');
65					$modal.addClass('el_modal_popup_opened');
66				}, $timeOut );
67				setTimeout( function() {
68					el_modal_popup_autoplay_video( $modal );
69				}, ( 0.7 * $timeOut ) );
70
71				el_modal_popup_trigger_entrance_animation( $modal );
72				$(document).trigger( 'diviModalPopupOpened' );
73			}, delay);
74		}
75 
76		if ( 'close' === $options.action ) {
77			let modalId     = $modal.prop( 'id' ),
78				triggerType = $modal.find( '.el_modal_popup_wrapper' ).data( 'trigger-type' ),
79				reRender    = $modal.find( '.el_modal_popup_wrapper' ).data( 're-render' );
80
81			if ( 0 !== $timeOut ) {
82				$modal.addClass( 'el_modal_popup_closing' );
83				$modal.removeClass( 'el_modal_popup_active_modal' );
84				$modal.removeClass( 'el_modal_popup_opened' );
85
86				/* Force a reflow on the animated element so the browser restarts
87				   its (already finished) entrance animation in reverse, instead of
88				   treating the animation-direction change as a no-op. Only touch
89				   animation-name here (not the 'animation' shorthand) so we don't
90				   clobber the animation-duration/delay/timing-function inline
91				   styles that Divi's own animateElement() already set on open. */
92				let $animatedEls = $modal.find( '.el_modal_popup_animated' );
93				if ( $animatedEls.length > 0 ) {
94					$animatedEls.css( 'animation-name', 'none' );
95					void $animatedEls[0].offsetWidth;
96				}
97				$modal.addClass( 'el_modal_popup_animate_reverse' );
98				if ( $animatedEls.length > 0 ) {
99					$animatedEls.css( 'animation-name', '' );
100				}
101
102				$( 'body' ).removeClass( 'el_modal_popup_enable_scroll' );
103				$( 'body' ).removeClass( 'el_modal_popup_active' );
104				if ( $options.href && '#' !== $options.href ) {
105					window.location.href = $options.href;
106				}
107				setTimeout( function() {
108					$modal.removeClass( 'el_modal_popup_animate_reverse' );
109					$modal.removeClass( 'el_modal_popup_closing' );
110				}, $timeOut );
111			} else {
112				$modal.removeClass( 'el_modal_popup_active_modal' );
113				$modal.removeClass( 'el_modal_popup_opened' );
114				$( 'body' ).removeClass( 'el_modal_popup_active' );
115				$( 'body' ).removeClass( 'el_modal_popup_enable_scroll' );
116				if ( $options.href && '#' !== $options.href ) {
117					window.location.href = $options.href;
118				}
119			}
120			
121			el_modal_popup_stop_video($modal);
122			if ( -1 !== $.inArray( triggerType, [ 'exit_intent', 'on_page_load', 'on_scroll', 'user_inactivity' ] ) ) {
123				let modalStorageKey = modalId + '_' + triggerType + '_hide';
124				if ( ( 'on_page_load' === triggerType && 'off' === reRender ) || ( 'exit_intent' === triggerType && 'off' === reRender ) || 
125					 ( 'on_scroll' === triggerType && 'off' === reRender ) || ( 'user_inactivity' === triggerType && 'off' === reRender ) ) {
126					sessionStorage.setItem( modalStorageKey, 'true' );
127				}
128				if ( ( 'exit_intent' === triggerType && 'on' === reRender ) || ( 'on_scroll' === triggerType && 'on' === reRender ) ) {
129					$modal.find('.el_modal_popup_wrapper').data('rendered', 'yes');
130				}
131			}
132			if ( $options.href && '#' !== $options.href ) {
133				window.location.href = $options.href;
134			}
135
136			$(document).trigger( 'diviModalPopupClosed' );
137		}
138		return this;
139	};
140
141	if ( $('body').find('.el_modal_popup').length > 0 ) {
142
143		let $user_inactivity_modals = {};
144		$('body').find('.el_modal_popup').each( function() {
145			let $this               = $(this),
146				$modalClass         = $this.prop('class'),
147				$orderClass         = $this.prop('class').match(/el_modal_popup_\d+/)[0],
148				$modalId            = $this.find('.el_modal_popup_wrapper').data('id'),
149				$modalStorageKey    = $modalId + '_' + $this.find('.el_modal_popup_wrapper').data('trigger-type') + '_hide',
150				$modal_container    = $('<div class="el_modal_popup_section entry-content et_pb_section et-l"></div>'),
151				$modal              = $('<div></div>');
152
153			$modal.prop( 'id', $modalId );
154			$modal.prop( 'class', $modalClass );
155			$modal.DiviModalPopupRemoveClasses($orderClass).addClass('el_modal_popup_module');
156			
157			if ( $this.hasClass( $orderClass + '_tb_header' ) ) {
158				$modal.addClass( $orderClass + '_tb_header_module' );
159			} else if ( $this.hasClass( $orderClass + '_tb_body' ) ) {
160				$modal.addClass( $orderClass + '_tb_body_module' );
161			} else if ( $this.hasClass( $orderClass + '_tb_footer' ) ) {
162				$modal.addClass( $orderClass + '_tb_footer_module' );
163			} else {
164				$modal.addClass( $orderClass + '_module' );
165			} 
166
167			$modal.html( $(this).find('.el_modal_popup_wrapper').detach() );
168			$modal_container.html($modal);
169
170			if ( $('body').find('#page-container').find('#et-boc').length > 0 ) {
171				$('body').find('#page-container').find('#et-boc').append( $modal_container );
172			} else if ( $('body').find('#page-container').length > 0 ) {
173				$('body').find('#page-container').append( $modal_container );
174			} else if ( $('body').find('#et_builder_outer_content').length > 0 ) {
175				$('body').find('#et_builder_outer_content').append( $modal_container );
176			} else if ( $('body').find('#et-boc').length > 0 ) {
177				$('body').find('#et-boc').append( $modal_container );
178			} else {
179				$('body').append( $modal_container );
180			}
181
182			if ( $('body').find('.el_modal_popup_body .el_modal_popup_close').length > 0 ) {
183				$('body').find('.el_modal_popup_body .el_modal_popup_close').each(function(){
184					if ( $(this).attr('href') ) {
185						$(this).attr('data-href', $(this).attr('href'));
186						$(this).attr('href', '#');
187					}
188				});
189			}
190
191			if ( 'none' === $this.css('display') ) {
192				return;
193			}
194			
195			if ( 'element' === $modal.find('.el_modal_popup_wrapper').data('trigger-type') ) {
196				if ( 'undefined' !== typeof( $modal.find('.el_modal_popup_wrapper').data('trigger-element-id') ) && '' !== $modal.find('.el_modal_popup_wrapper').data('trigger-element-id') ) {
197					/* Trigger modal on user defined element */
198					let $elem = '#' + $modal.find('.el_modal_popup_wrapper').data('trigger-element-id');
199					$('body').on('click', $elem, function(e){
200						e.preventDefault();
201						$modal.DiviModalPopup({
202							action: 'open',
203						});
204					});
205				} else if ( 'undefined' !== typeof( $modal.find('.el_modal_popup_wrapper').data('trigger-element-class') ) && '' !== $modal.find('.el_modal_popup_wrapper').data('trigger-element-class') ) {
206					/* Trigger modal on user defined element */
207					let $elem = '.' + $modal.find('.el_modal_popup_wrapper').data('trigger-element-class');
208					$('body').on('click', $elem, function(e){
209						e.preventDefault();
210						$modal.DiviModalPopup({
211							action: 'open',
212						});
213					});
214				} else if ( $this.find('.el_modal_popup_trigger_element').length > 0 ) {
215					/* Trigger modal on modal trigger element */
216					$this.find('.el_modal_popup_trigger_element').on('click', function(e){
217						e.preventDefault();
218						$modal.DiviModalPopup({
219							action: 'open',
220						});
221					});
222				}
223			} else if ( 'on_page_load' === $modal.find('.el_modal_popup_wrapper').data('trigger-type') ) {
224				/* Trigger modal on page load */
225				let delay       = parseFloat( $modal.find('.el_modal_popup_wrapper').data('trigger-delay') ),
226					reRender    = $modal.find('.el_modal_popup_wrapper').data('re-render');
227					if ( ( 'off' === reRender && 'true' !== sessionStorage.getItem( $modalStorageKey ) ) || 'on' === reRender ) {
228						$modal.DiviModalPopup({
229							action: 'open',
230							delay: delay,
231						});
232					}
233			} else if ( 'exit_intent' === $modal.find('.el_modal_popup_wrapper').data('trigger-type') ) {
234				/* Trigger modal on exit intent */
235				let reRender = $modal.find('.el_modal_popup_wrapper').data('re-render');
236				$(document).on('mouseout', function(e) {
237					if ( ! $modal.hasClass('el_modal_popup_opened') ) {
238						if ( 
239							( e.toElement == null && e.relatedTarget == null && ( 'off' === reRender && 'true' !== sessionStorage.getItem( $modalStorageKey ) ) ) ||
240							( e.toElement == null && e.relatedTarget == null && 'on' === reRender && 'yes' !== $modal.find('.el_modal_popup_wrapper').data('rendered') )
241						) {
242							$modal.DiviModalPopup({
243								action: 'open',
244							});
245						}
246					}
247				});
248			} else if ( 'on_scroll' === $modal.find('.el_modal_popup_wrapper').data('trigger-type') ) {
249				/* Trigger modal on scroll */
250				let docHeight = $('body').outerHeight(),
251					scrollPos = $modal.find('.el_modal_popup_wrapper').data('scroll-position'),
252					reRender  = $modal.find('.el_modal_popup_wrapper').data('re-render');
253					if ( scrollPos.includes('%') ) {
254						scrollPos = ( parseFloat( scrollPos )/100 ) * ( parseFloat( docHeight ) - $(window).outerHeight(true) );
255					}
256					scrollPos = parseFloat( scrollPos );
257				$(window).on('scroll', function(e) {
258					let scrollY = $(window).scrollTop();
259					if ( ! $modal.hasClass('el_modal_popup_opened') ) {
260						if ( 
261							( 'off' === reRender && 'true' !== sessionStorage.getItem( $modalStorageKey ) && scrollY >= scrollPos ) ||
262							( 'on' === reRender && 'yes' !== $modal.find('.el_modal_popup_wrapper').data('rendered') && scrollY >= scrollPos )
263						) {
264							$modal.DiviModalPopup({
265								action: 'open',
266							});
267						}
268					}
269				});
270			} else if ( 'user_inactivity' === $modal.find('.el_modal_popup_wrapper').data('trigger-type') ) {
271				// Get the timeout
272				let reRender             = $modal.find('.el_modal_popup_wrapper').data('re-render'),
273					user_inactivity_time = parseInt( $modal.find('.el_modal_popup_wrapper').data('user-inactivity-time') );
274
275				// Add to the timer
276				$user_inactivity_modals[$orderClass] = { 'modal_obj': $modal, 'modalstoragekey': $modalStorageKey, 'timer': '' };
277				if ( ! $modal.hasClass('el_modal_popup_opened') ) {
278					if ( ( 'off' === reRender && 'true' !== sessionStorage.getItem( $modalStorageKey ) ) || 'on' === reRender ) {
279						$user_inactivity_modals[$orderClass]['timer'] = setTimeout( function() {
280							$modal.DiviModalPopup( {
281								action: 'open',
282							} );
283						}, (user_inactivity_time * 1000) );
284					}
285				}
286			}
287		} );
288
289		// Reset user models, on user does activity.
290		const events = [ 'load', 'mousemove', 'mousedown', 'touchstart', 'touchmove', 'click', 'keydown', 'scroll' ];
291		events.forEach( s => window.addEventListener( s, user_inactivity_time_reset, true ) );
292		function user_inactivity_time_reset() {
293			$.each( $user_inactivity_modals, function( key, um ) {
294				// Reset timer if already saved.
295				if ( um.timer && '' !== um.timer ) {
296					clearTimeout( um.timer );
297				}
298
299				// Check the models.
300				const $modal = ( um.modal_obj ) ? um.modal_obj : '';
301				if ( $modal ) {
302					// Get the timeout.
303					let reRender             = $modal.find('.el_modal_popup_wrapper').data('re-render'),
304						user_inactivity_time = parseInt( $modal.find('.el_modal_popup_wrapper').data('user-inactivity-time') ),
305						$modalStorageKey     = ( um.modalstoragekey ) ? um.modalstoragekey : '';
306
307					if ( ! $modal.hasClass('el_modal_popup_opened') ) {
308						if ( ( 'off' === reRender && 'true' !== sessionStorage.getItem( $modalStorageKey ) ) || 'on' === reRender ) {
309							$user_inactivity_modals[key]['timer'] = setTimeout( function() {
310								$modal.DiviModalPopup( {
311									action: 'open',
312								} );
313							}, (user_inactivity_time * 1000) );
314						}
315					}
316				}
317			} );
318		}
319
320		/* Prevent modal closing before it's fully rendered */
321		$('body').on( 'click', '.el_modal_popup_close', function(e){
322			e.preventDefault();
323		} );
324
325		/* Close modal on outside click */
326		$('body').on('click', '.el_modal_popup_opened .el_modal_popup_close_on_background_click', function(e){
327			if ( $(e.target).is( $(this) ) ) {
328				let $modal = $(this).parents('.el_modal_popup');
329				$modal.DiviModalPopup({
330					action: 'close',
331				});
332			}
333		});
334		
335		/* Close modal on close icon click after its fully rendered */
336		$('body').on('click', '.el_modal_popup_opened .el_modal_popup_close', function(e){
337			e.preventDefault();
338			let $modal = $(this).parents('.el_modal_popup'),
339				$href  = $(this).attr('href');
340			$modal.DiviModalPopup({
341				action: 'close',
342				href: $href,
343			});
344		});
345
346		/* Close modal on esc key after its fully rendered */
347		$(document).on('keyup', function(e){
348			if ( e.keyCode === 27 ) {
349				if ( 
350					$('body').hasClass('el_modal_popup_active') &&
351					$('body').find('.el_modal_popup_opened .el_modal_popup_wrapper').hasClass('el_modal_popup_close_on_esc') &&
352					$('body').find('.el_modal_popup_opened .el_modal_popup_wrapper').length > 0
353				) {
354					let $modal = $('body').find('.el_modal_popup_opened');
355					$modal.DiviModalPopup({
356						action: 'close',
357					});
358				}
359			}
360		});
361
362		if ( document.onfullscreenchange === null ) {
363			document.onfullscreenchange = el_modal_popup_on_full_screen_change;
364		} else if ( document.onmsfullscreenchange === null ) {
365			document.onmsfullscreenchange = el_modal_popup_on_full_screen_change;
366		} else if ( document.onmozfullscreenchange === null ) {
367			document.onmozfullscreenchange = el_modal_popup_on_full_screen_change;
368		} else if ( document.onwebkitfullscreenchange === null ) {
369			document.onwebkitfullscreenchange = el_modal_popup_on_full_screen_change;
370		}
371	}
372
373	function el_modal_popup_trigger_entrance_animation( $modal ) {
374		if ( typeof et_animate_element === 'function' ) {
375			et_animate_element( $modal.find( '.el_modal_popup_inner_wrap' ) );
376		} else {
377			$modal.find( '.el_modal_popup_inner_wrap' ).removeClass( 'et_animated' );
378		}
379	}
380
381	function el_modal_popup_stop_video($modal) {
382		if ( typeof($modal) === 'undefined' || '' === $modal ) {
383			return false;
384		}
385
386		if ( $modal.find('iframe').length > 0 ) {
387			let src = $modal.find('iframe').attr('src').replace('?autoplay=1&amp;', '?').replace('?autoplay=1&', '?').replace('?autoplay=1', '').replace('&amp;autoplay=1', '').replace('&autoplay=1', '').replace('&mute=1&muted=1', '');
388			$modal.find('iframe').attr('src', src );
389		} else if ( $modal.find('video').length > 0 ) {
390			$modal.find('video').get(0).pause();
391			$modal.find('video').get(0).currentTime = 0;
392		}
393	}
394
395	function el_modal_popup_autoplay_video($modal) {
396		if ( typeof($modal) === 'undefined' || '' === $modal ) {
397			return false;
398		}
399
400		if ( 'on' === $modal.find('.el_modal_popup_wrapper').data('autoplay-video') ) {
401			if ( $modal.find('iframe').length > 0 ) {
402				let mute = 'on_page_load' === $modal.find('.el_modal_popup_wrapper').data('trigger-type') ? true : false;
403				let src = el_modal_popup_add_autoplay_to_url( $modal.find('iframe').attr('src'), mute );
404				$modal.find('iframe').attr('src', src );
405			} else if ( $modal.find('video').length > 0 ) {
406				let promise = $modal.find('video').get(0).play();
407				if ( promise !== undefined ) {
408					promise.then(_ => {
409					}).catch(error => {
410						$modal.find('video').prop('muted', true);
411						$modal.find('video').get(0).play();
412					});
413				}
414			}
415		}
416	}
417
418	function el_modal_popup_add_autoplay_to_url(src, mute) {
419		let uri     = decodeURIComponent( src );
420		let atts    = uri.split('&');
421		if ( 1 === atts.length ) {
422			atts = uri.split('?');
423			if ( 1 !== atts.length ) {
424				uri = uri + '&autoplay=1';
425				if ( mute ) {
426					uri = uri + '&mute=1&muted=1';
427				}
428			} else {
429				uri = uri + '?autoplay=1';
430				if ( mute ) {
431					uri = uri + '&mute=1&muted=1';
432				}
433			}
434		} else {
435			uri = uri + '&autoplay=1';
436			if ( mute ) {
437				uri = uri + '&mute=1&muted=1';
438			}
439		}
440		return uri;
441	}
442
443	function el_modal_popup_get_module_classes() {
444		return [
445			'et_pb_sticky_module', 'et_pb_sticky',
446			'et_pb_sticky--top', 'et_pb_sticky--bottom', 'et_pb_sticky--top_bottom',
447			'et_animated', 'infinite', 'et-waypoint', 'et_had_animation',
448			'fade', 'fadeTop', 'fadeRight', 'fadeBottom', 'fadeLeft',
449			'slide', 'slideTop', 'slideRight', 'slideBottom', 'slideLeft',
450			'bounce', 'bounceTop', 'bounceRight', 'bounceBottom', 'bounceLeft',
451			'zoom', 'zoomTop', 'zoomRight', 'zoomBottom', 'zoomLeft',
452			'flip', 'flipTop', 'flipRight', 'flipBottom', 'flipLeft',
453			'fold', 'foldTop', 'foldRight', 'foldBottom', 'foldLeft',
454			'roll', 'rollTop', 'rollRight', 'rollBottom', 'rollLeft', 'transformAnim',
455		];
456	}
457
458	function el_modal_popup_on_full_screen_change() {
459		let dmpFullScreenElement =
460			document.fullscreenElement ||
461			document.msFullscreenElement ||
462			document.mozFullScreenElement ||
463			document.webkitFullscreenElement;
464
465			if ( !! dmpFullScreenElement ) {
466				jQuery('body').find('.el_modal_popup_active_modal .el_modal_popup_inner_wrap').addClass('el_modal_popup_fullscreen');
467			} else {
468				jQuery('body').find('.el_modal_popup_module .el_modal_popup_inner_wrap').removeClass('el_modal_popup_fullscreen');
469			}
470	}
471 
472}( 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.