PageSourceSearch

https://coeliac.ie/wp-content/plugins/sfwd-lms/themes/ld30/assets/js/learndash.js?ver=4.4.1.2-1790866050

js coeliac.ie collected 2026-10-01 14:48:48 UTC 38,101 bytes, 1,114 lines download raw bytes

1jQuery( function( $ ) {
2	var hash = window.location.hash;
3
4	learndashFocusModeSidebarAutoScroll();
5
6	initLoginModal();
7	if ( '#login' == hash ) {
8		openLoginModal();
9	}
10
11	if ( 'undefined' !== typeof ldGetUrlVars().login ) {
12		var loginStatus = ldGetUrlVars().login;
13
14		if ( 'failed' == loginStatus ) {
15			openLoginModal();
16		}
17	}
18
19	if ( 'undefined' !== typeof ldGetUrlVars()['ld-topic-page'] ) {
20		var topicPage = ldGetUrlVars()['ld-topic-page'];
21		var topicIds = topicPage.split( '-' );
22		var topicId = Object.values( topicIds )[0];
23
24		var lesson = $( '#ld-expand-' + topicId );
25		var button = $( lesson ).find( '.ld-expand-button' );
26
27		ld_expand_element( button );
28
29		$( 'html, body' ).animate( {
30			scrollTop: ( $( lesson ).offset().top ),
31		}, 500 );
32	}
33
34	$( 'body' ).on( 'click', 'a[href="#login"]', function( e ) {
35		e.preventDefault();
36		openLoginModal();
37	} );
38
39	$( 'body' ).on( 'click', '.ld-modal-closer', function( e ) {
40		e.preventDefault();
41		closeLoginModal();
42	} );
43
44	$( 'body' ).on( 'click', '#ld-comments-post-button', function( e ) {
45		$( this ).addClass( 'ld-open' );
46		$( '#ld-comments-form' ).removeClass( 'ld-collapsed' );
47		$( 'textarea#comment' ).focus();
48	} );
49
50	// Close modal if clicking away
51	/*
52	$('body').on('click', function(e) {
53		if ($('.learndash-wrapper').hasClass('ld-modal-open')) {
54			if ( ! $(e.target).parents('.ld-modal').length && (! $(e.target).is('a'))) {
55				closeLoginModal();
56			}
57		}
58	});
59	*/
60
61	// Close modal on Esc key
62	$( document ).on( 'keyup', function( e ) {
63		if ( 27 === e.keyCode ) {
64			closeLoginModal();
65		}
66	} );
67
68	$( '.learndash-wrapper' ).on( 'click', 'a.user_statistic', learndash_ld30_show_user_statistic );
69
70	focusMobileCheck();
71
72	$( 'body' ).on( 'click', '.ld-focus-sidebar-trigger', function( e ) {
73		if ( $( '.ld-focus' ).hasClass( 'ld-focus-sidebar-collapsed' ) ) {
74			openFocusSidebar();
75		} else {
76			closeFocusSidebar();
77		}
78	} );
79
80	$( 'body' ).on( 'click', '.ld-mobile-nav a', function( e ) {
81		e.preventDefault();
82		if ( $( '.ld-focus' ).hasClass( 'ld-focus-sidebar-collapsed' ) ) {
83			openFocusSidebar();
84		} else {
85			closeFocusSidebar();
86		}
87	} );
88
89	$( '.ld-js-register-account' ).on( 'click', function( e ) {
90		e.preventDefault();
91
92		$( '.ld-login-modal-register .ld-modal-text' ).slideUp( 'slow' );
93		$( '.ld-login-modal-register .ld-alert' ).slideUp( 'slow' );
94		$( this ).slideUp( 'slow', function() {
95			$( '#ld-user-register' ).slideDown( 'slow' );
96		} );
97	} );
98
99	// If registration login link filter not defined, allow to replace the register form with login form
100	if ( '' == $( '.registration-login-link' ).attr('href') ) {
101		$( '.registration-login-link' ).on( 'click', function( e ) {
102			e.preventDefault();
103			$( '#learndash_registerform, .registration-login' ).hide();
104			$( '.registration-login-form, .show-register-form, .show-password-reset-link' ).show();
105		} );
106		$( '.show-register-form' ).on( 'click', function( e ) {
107			e.preventDefault();
108			$( '.registration-login-form, .show-register-form, .show-password-reset-link' ).hide();
109			$( '#learndash_registerform, .registration-login').show();
110		})
111	}
112
113	var windowWidth = $( window ).width();
114
115	$( window ).on( 'orientationchange', function() {
116		windowWidth = $( window ).width();
117	} );
118
119	$( window ).on( 'resize', function() {
120		if ( $( this ).width() !== windowWidth && 1024 >= $( this ).width() ) {
121			setTimeout( function() {
122				focusMobileResizeCheck();
123			}, 50 );
124		}
125	} );
126
127	if ( $( '.ld-course-status-content' ).length ) {
128		var tallest = 0;
129
130		$( '.ld-course-status-content' ).each( function() {
131			if ( $( this ).height() > tallest ) {
132				tallest = $( this ).height();
133			}
134		} );
135
136		$( '.ld-course-status-content' ).height( tallest );
137	}
138
139	function focusMobileCheck() {
140		if ( 1024 > $( window ).width() ) {
141			closeFocusSidebarPageLoad();
142		}
143	}
144
145	function focusMobileResizeCheck() {
146		if ( 1024 > $( window ).width() && ! $( '.ld-focus' ).hasClass( 'ld-focus-sidebar-collapsed' ) ) {
147			closeFocusSidebar();
148		} else if ( 1024 <= $( window ).width() && $( '.ld-focus' ).hasClass( 'ld-focus-sidebar-filtered' ) ) {
149			closeFocusSidebar();
150		} else if ( 1024 <= $( window ).width() &&
151			! $( '.ld-focus' ).hasClass( 'ld-focus-sidebar-filtered' ) &&
152			$( '.ld-focus' ).hasClass( 'ld-focus-sidebar-collapsed' ) ) {
153			openFocusSidebar();
154		}
155	}
156
157	function focusMobileHandleOrientationChange( e ) {
158		if ( e.matches ) {
159			if ( 1024 <= $( window ).width() &&
160			! $( '.ld-focus' ).hasClass( 'ld-focus-sidebar-filtered' ) &&
161			$( '.ld-focus' ).hasClass( 'ld-focus-sidebar-collapsed' ) ) {
162				openFocusSidebar();
163			}
164		}
165	}
166	window.matchMedia( '(orientation: landscape)' ).addListener( focusMobileHandleOrientationChange );
167
168	function closeFocusSidebarPageLoad() {
169		$( '.ld-focus' ).addClass( 'ld-focus-sidebar-collapsed' );
170		$( '.ld-focus' ).removeClass( 'ld-focus-initial-transition' );
171		$( '.ld-mobile-nav' ).removeClass( 'expanded' );
172		positionTooltips();
173	}
174
175	function closeFocusSidebar() {
176		$( '.ld-focus' ).addClass( 'ld-focus-sidebar-collapsed' );
177		$( '.ld-mobile-nav' ).removeClass( 'expanded' );
178
179		if ( $( '.ld-focus-sidebar-trigger .ld-icon' ).hasClass( 'ld-icon-arrow-left' ) ) {
180			$( '.ld-focus-sidebar-trigger .ld-icon' ).removeClass( 'ld-icon-arrow-left' );
181			$( '.ld-focus-sidebar-trigger .ld-icon' ).addClass( 'ld-icon-arrow-right' );
182		} else if ( $( '.ld-focus-sidebar-trigger .ld-icon' ).hasClass( 'ld-icon-arrow-right' ) ) {
183			$( '.ld-focus-sidebar-trigger .ld-icon' ).removeClass( 'ld-icon-arrow-right' );
184			$( '.ld-focus-sidebar-trigger .ld-icon' ).addClass( 'ld-icon-arrow-left' );
185		}
186
187		positionTooltips();
188	}
189
190	function openFocusSidebar() {
191		$( '.ld-focus' ).removeClass( 'ld-focus-sidebar-collapsed' );
192		$( '.ld-mobile-nav' ).addClass( 'expanded' );
193
194		if ( $( '.ld-focus-sidebar-trigger .ld-icon' ).hasClass( 'ld-icon-arrow-left' ) ) {
195			$( '.ld-focus-sidebar-trigger .ld-icon' ).removeClass( 'ld-icon-arrow-left' );
196			$( '.ld-focus-sidebar-trigger .ld-icon' ).addClass( 'ld-icon-arrow-right' );
197		} else if ( $( '.ld-focus-sidebar-trigger .ld-icon' ).hasClass( 'ld-icon-arrow-right' ) ) {
198			$( '.ld-focus-sidebar-trigger .ld-icon' ).removeClass( 'ld-icon-arrow-right' );
199			$( '.ld-focus-sidebar-trigger .ld-icon' ).addClass( 'ld-icon-arrow-left' );
200		}
201
202		positionTooltips();
203	}
204
205	$( '.ld-file-input' ).each( function() {
206		var $input	 = $( this ),
207			$label	 = $input.next( 'label' ),
208			labelVal = $label.html();
209
210		$input.on( 'change', function( e ) {
211			var fileName = '';
212			if ( this.files && 1 < this.files.length ) {
213				fileName = ( this.getAttribute( 'data-multiple-caption' ) || '' ).replace( '{count}', this.files.length );
214			} else if ( e.target.value ) {
215				fileName = e.target.value.split( '\\' ).pop();
216			}
217			if ( fileName ) {
218				$label.find( 'span' ).html( fileName );
219				$label.addClass( 'ld-file-selected' );
220				$( '#uploadfile_btn' ).attr( 'disabled', false );
221			} else {
222				$label.html( labelVal );
223				$label.removeClass( 'ld-file-selected' );
224				$( '#uploadfile_btn' ).attr( 'disabled', true );
225			}
226		} );
227
228		$( '#uploadfile_form' ).on( 'submit', function() {
229			$label.removeClass( 'ld-file-selected' );
230			$( '#uploadfile_btn' ).attr( 'disabled', true );
231		} );
232
233		// Firefox bug fix
234		$input
235			.on( 'focus', function() {
236				$input.addClass( 'has-focus' );
237			} )
238			.on( 'blur', function() {
239				$input.removeClass( 'has-focus' );
240			} );
241	} );
242
243	$( 'body' ).on( 'click', '.ld-expand-button', function( e ) {
244		e.preventDefault();
245
246		ld_expand_element( $( this ) );
247
248		positionTooltips();
249	} );
250
251	$( 'body' ).on( 'click', '.ld-search-prompt', function( e ) {
252		e.preventDefault();
253
254		$( '#course_name_field' ).focus();
255
256		ld_expand_element( $( this ) );
257	} );
258
259	function ld_expand_button_state( state, elm ) {
260		var $expandText = ( $( elm )[0].hasAttribute( 'data-ld-expand-text' ) ) ? $( elm ).attr( 'data-ld-expand-text' ) : 'Expand';
261		var $collapseText = ( $( elm )[0].hasAttribute( 'data-ld-collapse-text' ) ) ? $( elm ).attr( 'data-ld-collapse-text' ) : 'Collapse';
262
263		if ( 'collapse' == state ) {
264			$( elm ).removeClass( 'ld-expanded' );
265			if ( 'false' !== $collapseText ) {
266				$( elm ).find( '.ld-text' ).text( $expandText );
267			}
268		} else {
269			$( elm ).addClass( 'ld-expanded' );
270			if ( 'false' !== $collapseText ) {
271				$( elm ).find( '.ld-text' ).text( $collapseText );
272			}
273		}
274	}
275
276	function ld_expand_element( elm, collapse ) {
277		if ( collapse === undefined ) {
278			collapse = false;
279		}
280
281		var elmParentWrapper = elm.parents( '.ld-focus-sidebar' );
282		if ( ( 'undefined' === typeof elmParentWrapper ) || ( ! elmParentWrapper.length ) ) {
283			var elmParentWrapper = elm.parents( '.learndash-wrapper' );
284		}
285		if ( ( 'undefined' === typeof elmParentWrapper ) || ( ! elmParentWrapper.length ) ) {
286			return;
287		}
288
289		// Get the button's state
290		var $expanded = $( elm ).hasClass( 'ld-expanded' );
291
292		// Get the element to expand
293		if ( $( elm )[0] && $( elm )[0].hasAttribute( 'data-ld-expands' ) ) {
294			var $expands      = $( elm ).attr( 'data-ld-expands' );
295			if ( ( 'undefined' === typeof $expands ) || ( ! $expands.length ) ) {
296				return;
297			}
298
299			var $expandElm    = $(elmParentWrapper).find( '[data-ld-expand-id="'+ $expands+'"]' );
300			if ( ( 'undefined' === typeof $expandElm ) || ( ! $expandElm.length ) ) {
301				return;
302			}
303
304			var $expandsChild = $( $expandElm ).find( '.ld-item-list-item-expanded' );
305
306			if ( $expandsChild.length ) {
307				$expandElm = $expandsChild;
308			}
309
310			var totalHeight = 0;
311
312			$expandElm.find( '> *' ).each( function() {
313				totalHeight += $( this ).outerHeight();
314			} );
315
316			$expandElm.attr( 'data-height', '' + ( totalHeight + 50 ) + '' );
317
318			// If the element expands a list
319
320			if ( $(elmParentWrapper).find( '[data-ld-expand-id="'+ $expands+'"]' )[0].hasAttribute( 'data-ld-expand-list' ) ) {
321
322				var $container = $(elmParentWrapper).find( '[data-ld-expand-id="'+ $expands+'"]' );
323				var innerButtons = $container.find( '.ld-expand-button' );
324				if ( $expanded ) {
325					ld_expand_button_state( 'collapse', elm );
326					innerButtons.each( function() {
327						ld_expand_element( $( this ), true );
328					} );
329				} else {
330					ld_expand_button_state( 'expand', elm );
331					innerButtons.each( function() {
332						ld_expand_element( $( this ) );
333					} );
334				}
335
336				// If the element expands an item
337			} else if ( $(elmParentWrapper).find( '[data-ld-expand-id="'+ $expands+'"]' ).length ) {
338				if ( $expanded || true == collapse ) {
339					ld_expand_singular_item( elm, $(elmParentWrapper).find( '[data-ld-expand-id="'+ $expands+'"]' ), $expandElm );
340				} else {
341					ld_collapse_singular_item( elm, $(elmParentWrapper).find( '[data-ld-expand-id="'+ $expands+'"]' ), $expandElm );
342				}
343			} else {
344				console.log( 'LearnDash: No expandable content was found' );
345			}
346			positionTooltips();
347		}
348	}
349
350	function ld_expand_singular_item( elm, $containerElm, $expandElm ) {
351		$containerElm.removeClass( 'ld-expanded' );
352		ld_expand_button_state( 'collapse', elm );
353
354		$expandElm.css( {
355			'max-height': 0,
356		} );
357	}
358
359	function ld_collapse_singular_item( elm, $containerElm, $expandElm ) {
360		$containerElm.addClass( 'ld-expanded' );
361
362		ld_expand_button_state( 'expand', elm );
363
364		$expandElm.css( {
365			'max-height': $expandElm.data( 'height' ),
366		} );
367	}
368
369	$( 'body' ).on( 'click', '.ld-closer', function( e ) {
370		ld_expand_element( $( '.ld-search-prompt' ), true );
371	} );
372
373	$( 'body' ).on( 'click', '.ld-tabs-navigation .ld-tab', function() {
374		var $tab = $( '#' + $( this ).attr( 'data-ld-tab' ) );
375		if ( $tab.length ) {
376			$( '.ld-tabs-navigation .ld-tab.ld-active' ).removeClass( 'ld-active' );
377			$( '.ld-tabs-navigation .ld-tab' ).removeAttr( 'aria-selected' );
378			$( this ).addClass( 'ld-active' );
379			$( this ).attr( 'aria-selected', 'true' );
380			$( '.ld-tabs-content .ld-tab-content.ld-visible' ).removeClass( 'ld-visible' );
381			$tab.addClass( 'ld-visible' );
382		}
383		positionTooltips();
384	} );
385
386	var $tooltips = $( '*[data-ld-tooltip]' );
387
388	initTooltips();
389
390	function initTooltips() {
391		// Clear out old tooltips
392
393		if ( $( '#learndash-tooltips' ).length ) {
394			$( '#learndash-tooltips' ).remove();
395			$tooltips = $( '*[data-ld-tooltip]' );
396		}
397
398		if ( $tooltips.length ) {
399			$( 'body' ).prepend( '<div id="learndash-tooltips"></div>' );
400			var $ctr = 1;
401			$tooltips.each( function() {
402				var anchor = $( this );
403				if ( anchor.hasClass( 'ld-item-list-item' ) ) {
404					anchor = anchor.find( '.ld-item-title' );
405				}
406
407				/**
408				 * Prevent calendar icon from being clickable.
409				 */
410				if ( ( "undefined" !== typeof anchor ) && ( $( anchor ).hasClass( 'ld-status-waiting' ) ) ) {
411					$( anchor ).on( 'click', function( e ) {
412						e.preventDefault();
413						return false;
414					} );
415
416					// Also prevent parent <a> from being clickable.
417					var parent_anchor = $( anchor ).parents( 'a' );
418					if ( "undefined" !== typeof parent_anchor ) {
419						$( parent_anchor ).on( 'click', function( e ) {
420							e.preventDefault();
421							return false;
422						} );
423					}
424				}
425
426
427				var elementOffsets = {
428					top: anchor.offset().top,
429					left: anchor.offset().left + ( anchor.outerWidth() / 2 ),
430				};
431				var $content = $( this ).attr( 'data-ld-tooltip' );
432				var $rel_id = Math.floor( ( Math.random() * 99999 ) );
433
434				//var $tooltip = '<span id="ld-tooltip-' + $rel_id + '" class="ld-tooltip" style="top:' + elementOffsets.top + 'px; left:' + elementOffsets.left + 'px;">' + $content + '</span>';
435				var $tooltip = '<span id="ld-tooltip-' + $rel_id + '" class="ld-tooltip">' + $content + '</span>';
436				$( this ).attr( 'data-ld-tooltip-id', $rel_id );
437				$( '#learndash-tooltips' ).append( $tooltip );
438				$ctr++;
439				var $tooltip = $( '#ld-tooltip-' + $rel_id );
440				$( this ).on( 'mouseenter', function() {
441					$tooltip.addClass( 'ld-visible' );
442				} ).on( 'mouseleave', function() {
443					$tooltip.removeClass( 'ld-visible' );
444				} );
445			} );
446
447			$( window ).on( 'resize', function() {
448				// Reposition tooltips after resizing
449				positionTooltips();
450			} );
451
452			$( window ).add( '.ld-focus-sidebar-wrapper' ).on( 'scroll', function() {
453				// Hide tooltips so they don't persist while scrolling
454				$( '.ld-visible.ld-tooltip' ).removeClass( 'ld-visible' );
455
456				// Reposition tooltips after scrolling
457				positionTooltips();
458			} );
459
460			positionTooltips();
461		}
462	}
463
464	function initLoginModal() {
465		var modal_wrapper = $( '.learndash-wrapper-login-modal' );
466		if ( ( 'undefined' !== typeof modal_wrapper ) && ( modal_wrapper.length ) ) {
467			// Move the model to be first element of the body. See LEARNDASH-3503
468			$( modal_wrapper ).prependTo( 'body' );
469		}
470	}
471
472	function openLoginModal() {
473		var modal_wrapper = $( '.learndash-wrapper-login-modal' );
474		if ( ( 'undefined' !== typeof modal_wrapper ) && ( modal_wrapper.length ) ) {
475			$( modal_wrapper ).addClass( 'ld-modal-open' );
476			$( modal_wrapper ).removeClass( 'ld-modal-closed' );
477
478			// Removed LEARNDASH-3867 #4
479			$( 'html, body' ).animate( {
480				scrollTop: $( '.ld-modal', modal_wrapper ).offset().top,
481			}, 50 );
482		}
483	}
484
485	function closeLoginModal() {
486		var modal_wrapper = $( '.learndash-wrapper-login-modal' );
487		if ( ( 'undefined' !== typeof modal_wrapper ) && ( modal_wrapper.length ) ) {
488			$( modal_wrapper ).removeClass( 'ld-modal-open' );
489			$( modal_wrapper ).addClass( 'ld-modal-closed' );
490		}
491	}
492
493	function positionTooltips() {
494		if ( 'undefined' !== typeof $tooltips ) {
495			setTimeout( function() {
496				$tooltips.each( function() {
497					var anchor = $( this );
498					var $rel_id = anchor.attr( 'data-ld-tooltip-id' );
499					$tooltip = $( '#ld-tooltip-' + $rel_id );
500
501					if ( anchor.hasClass( 'ld-item-list-item' ) ) {
502						//anchor = anchor.find('.ld-item-title');
503						anchor = anchor.find( '.ld-status-icon' );
504					}
505
506					var parent_focus = jQuery( anchor ).parents( '.ld-focus-sidebar' );
507					var left_post = anchor.offset().left + ( anchor.outerWidth() + 10 );
508					if ( parent_focus.length ) {
509						left_post = anchor.offset().left + ( anchor.outerWidth() - 18 );
510					}
511
512					// Get the main content height
513					var focusModeMainContentHeight = $( '.ld-focus-main' ).height();
514
515					// Current tooltip height
516					var focusModeCurrentTooltipHeight = anchor.offset().top + -3;
517
518					// Position tooltip depending on focus mode or not
519					if ( ! focusModeMainContentHeight ) {
520						var anchorTop = anchor.offset().top + -3;
521						var anchorLeft = anchor.offset().left;
522					} else {
523						anchorTop = focusModeCurrentTooltipHeight < focusModeMainContentHeight ? focusModeCurrentTooltipHeight : focusModeMainContentHeight;
524						anchorLeft = left_post;
525					}
526
527					$tooltip.css( {
528						top: anchorTop,
529
530						//'left' : anchor.offset().left + (anchor.outerWidth() / 2),
531						//'left': left_post, //anchor.offset().left + (anchor.outerWidth() +10),
532						left: anchorLeft, //anchor.offset().left + (anchor.outerWidth() +10),
533						'margin-left': 0,
534						'margin-right': 0,
535					} ).removeClass( 'ld-shifted-left ld-shifted-right' );
536					if ( $tooltip.offset().left <= 0 ) {
537						$tooltip.css( { 'margin-left': Math.abs( $tooltip.offset().left ) } ).addClass( 'ld-shifted-left' );
538					}
539					var $tooltipRight = $( window ).width() - ( $tooltip.offset().left + $tooltip.outerWidth() );
540					if ( 0 >= $tooltipRight && 360 < $( window ).width() ) {
541						$tooltip.css( { 'margin-right': Math.abs( $tooltipRight ) } ).addClass( 'ld-shifted-right' );
542					}
543				} );
544			}, 500 );
545		}
546	}
547
548	$( 'body' ).on( 'click', '#ld-profile .ld-reset-button', function( e ) {
549		e.preventDefault();
550
551		$( '#ld-profile #course_name_field' ).val('');
552
553		var searchVars = {
554			shortcode_instance: $( '#ld-profile' ).data( 'shortcode_instance' ),
555		};
556
557		searchVars['ld-profile-search'] = $( this ).parents( '.ld-item-search-wrapper' ).find( '#course_name_field' ).val();
558		searchVars['ld-profile-search-nonce'] = $( this ).parents( '.ld-item-search-wrapper' ).find( 'form.ld-item-search-fields' ).data( 'nonce' );
559
560		$( '#ld-profile #ld-main-course-list' ).addClass( 'ld-loading' );
561
562		$.ajax( {
563			type: 'GET',
564			url: ldVars.ajaxurl + '?action=ld30_ajax_profile_search',
565			data: searchVars,
566			success: function( response ) {
567				if ( 'undefined' !== typeof response.data.markup ) {
568					$( '#ld-profile' ).html( response.data.markup );
569					ld_expand_element( '#ld-profile .ld-search-prompt', false );
570				}
571			},
572		} );
573	} );
574
575	$( 'body' ).on( 'submit', '.ld-item-search-fields', function( e ) {
576		e.preventDefault();
577
578		var searchVars = {
579			shortcode_instance: $( '#ld-profile' ).data( 'shortcode_instance' ),
580		};
581
582		searchVars['ld-profile-search'] = $( this ).parents( '.ld-item-search-wrapper' ).find( '#course_name_field' ).val();
583		searchVars['ld-profile-search-nonce'] = $( this ).parents( '.ld-item-search-wrapper' ).find( 'form.ld-item-search-fields' ).data( 'nonce' );
584
585		$( '#ld-profile #ld-main-course-list' ).addClass( 'ld-loading' );
586
587		$.ajax( {
588			type: 'GET',
589			url: ldVars.ajaxurl + '?action=ld30_ajax_profile_search',
590			data: searchVars,
591			success: function( response ) {
592				if ( 'undefined' !== typeof response.data.markup ) {
593					$( '#ld-profile' ).html( response.data.markup );
594					ld_expand_element( '#ld-profile .ld-search-prompt', false );
595				}
596			},
597		} );
598	} );
599
600	$( 'body' ).on( 'click', '.ld-pagination a', function( e ) {
601		e.preventDefault();
602
603		var linkVars = {};
604		var parentVars = {};
605
606		$( this ).attr( 'href' ).replace( /[?&]+([^=&]+)=([^&]*)/gi, function( m, key, value ) {
607			linkVars[key] = value;
608		} );
609
610		linkVars.pager_nonce = $( this ).parents( '.ld-pagination' ).data( 'pager-nonce' );
611
612		linkVars.pager_results = $( this ).parents( '.ld-pagination' ).data( 'pager-results' );
613
614		linkVars.context = $( this ).data( 'context' );
615		console.log( 'linkVars[%o]', linkVars );
616
617		parentVars.currentTarget = e.currentTarget;
618
619		if ( 'profile' != linkVars.context ) {
620			linkVars.lesson_id = $( this ).data( 'lesson_id' );
621			linkVars.course_id = $( this ).data( 'course_id' );
622
623			if ( $( '.ld-course-nav-' + linkVars.course_id ).length ) {
624				linkVars.widget_instance = $( '.ld-course-nav-' + linkVars.course_id ).data( 'widget_instance' );
625			}
626		}
627
628		if ( 'course_topics' == linkVars.context ) {
629			$( '#ld-topic-list-' + linkVars.lesson_id ).addClass( 'ld-loading' );
630			$( '#ld-nav-content-list-' + linkVars.lesson_id ).addClass( 'ld-loading' );
631		}
632
633		if ( 'course_content_shortcode' == linkVars.context ) {
634			parentVars.parent_container = $( parentVars.currentTarget ).closest( '.ld-course-content-' + linkVars.course_id );
635			if ( ( 'undefined' !== typeof parentVars.parent_container ) && ( parentVars.parent_container.length ) ) {
636				$( parentVars.parent_container ).addClass( 'ld-loading' );
637				linkVars.shortcode_instance = $( parentVars.parent_container ).data( 'shortcode_instance' );
638			} else {
639				$( '.ld-course-content-' + linkVars.course_id ).addClass( 'ld-loading' );
640				linkVars.shortcode_instance = $( '.ld-course-content-' + linkVars.course_id ).data( 'shortcode_instance' );
641			}
642		} else if ( 'course_lessons' == linkVars.context ) {
643			var parent_container;
644
645			// Check if we are within the Course Navigation Widget.
646			if ( ( 'undefined' === typeof parentVars.parent_container ) || ( ! parentVars.parent_container.length ) ) {
647				parent_container = $( parentVars.currentTarget ).parents( '.ld-lesson-navigation' );
648				if ( ( 'undefined' !== typeof parent_container ) && ( parent_container.length ) ) {
649					parentVars.context_sub = 'course_navigation_widget';
650					parentVars.parent_container = $( parentVars.currentTarget ).parents( '#ld-lesson-list-' + linkVars.course_id );
651				}
652			}
653
654			// Check if we are within the Focus Mode Sidebar.
655			if ( ( 'undefined' === typeof parentVars.parent_container ) || ( ! parentVars.parent_container.length ) ) {
656				parent_container = $( parentVars.currentTarget ).parents( '.ld-focus-sidebar-wrapper' );
657				if ( ( 'undefined' !== typeof parent_container ) && ( parent_container.length ) ) {
658					parentVars.context_sub = 'focus_mode_sidebar';
659					parentVars.parent_container = $( parentVars.currentTarget ).parents( '#ld-lesson-list-' + linkVars.course_id );
660				}
661			}
662
663			if ( ( 'undefined' === typeof parentVars.parent_container ) || ( ! parentVars.parent_container.length ) ) {
664				parentVars.parent_container = $( parentVars.currentTarget ).closest( '#ld-item-list-' + linkVars.course_id, '#ld-lesson-list-' + linkVars.course_id );
665			}
666			if ( ( 'undefined' !== typeof parentVars.parent_container ) && ( parentVars.parent_container.length ) ) {
667				$( parentVars.parent_container ).addClass( 'ld-loading' );
668			} else {
669				// Fallback solution.
670				$( '#ld-item-list-' + linkVars.course_id ).addClass( 'ld-loading' );
671				$( '#ld-lesson-list-' + linkVars.course_id ).addClass( 'ld-loading' );
672			}
673		}
674
675		if ( 'profile' == linkVars.context ) {
676			$( '#ld-profile #ld-main-course-list' ).addClass( 'ld-loading' );
677			linkVars.shortcode_instance = $( '#ld-profile' ).data( 'shortcode_instance' );
678		}
679
680		if ( 'profile_quizzes' == linkVars.context ) {
681			$( '#ld-course-list-item-' + linkVars.pager_results.quiz_course_id + ' .ld-item-contents' ).addClass( 'ld-loading' );
682		}
683
684		if ( 'course_info_courses' == linkVars.context ) {
685			$( '.ld-user-status' ).addClass( 'ld-loading' );
686			linkVars.shortcode_instance = $( '.ld-user-status' ).data( 'shortcode-atts' );
687		}
688
689		if ( 'group_courses' == linkVars.context ) {
690			linkVars.group_id = $( this ).data( 'group_id' );
691			if ( 'undefined' !== typeof linkVars.group_id ) {
692				parent_container = $( parentVars.currentTarget ).parents( '.ld-group-courses-' + linkVars.group_id );
693				if ( ( 'undefined' !== typeof parent_container ) && ( parent_container.length ) ) {
694					$( parent_container ).addClass( 'ld-loading' );
695					parentVars.parent_container = parent_container;
696				}
697			}
698		}
699
700		$.ajax( {
701			type: 'GET',
702			url: ldVars.ajaxurl + '?action=ld30_ajax_pager',
703			data: linkVars,
704			success: function( response ) {
705				// If we have a course listing, update
706
707				if ( 'course_topics' == linkVars.context ) {
708					if ( $( '#ld-topic-list-' + linkVars.lesson_id ).length ) {
709						if ( 'undefined' !== typeof response.data.topics ) {
710							$( '#ld-topic-list-' + linkVars.lesson_id ).html( response.data.topics );
711						}
712
713						if ( 'undefined' !== typeof response.data.pager ) {
714							$( '#ld-expand-' + linkVars.lesson_id ).find( '.ld-table-list-footer' ).html( response.data.pager );
715						}
716
717						learndashSetMaxHeight( $( '.ld-lesson-item-' + linkVars.lesson_id ).find( '.ld-item-list-item-expanded' ) );
718
719						$( '#ld-topic-list-' + linkVars.lesson_id ).removeClass( 'ld-loading' );
720					}
721
722					if ( $( '#ld-nav-content-list-' + linkVars.lesson_id ).length ) {
723						if ( 'undefined' !== typeof response.data.nav_topics ) {
724							$( '#ld-nav-content-list-' + linkVars.lesson_id ).find( '.ld-table-list-items' ).html( response.data.topics );
725						}
726
727						if ( 'undefined' !== typeof response.data.pager ) {
728							$( '#ld-nav-content-list-' + linkVars.lesson_id ).find( '.ld-table-list-footer' ).html( response.data.pager );
729						}
730
731						$( '#ld-nav-content-list-' + linkVars.lesson_id ).removeClass( 'ld-loading' );
732					}
733				}
734
735				if ( 'course_content_shortcode' == linkVars.context ) {
736					if ( 'undefined' !== typeof response.data.markup ) {
737						if ( ( 'undefined' !== typeof parentVars.parent_container ) && ( parentVars.parent_container.length ) ) {
738							$( parentVars.parent_container ).replaceWith( response.data.markup );
739						} else {
740							$( '#learndash_post_' + linkVars.course_id ).replaceWith( response.data.markup );
741						}
742					}
743				} else if ( 'course_lessons' == linkVars.context ) {
744					if ( ( 'undefined' !== typeof parentVars.parent_container ) && ( parentVars.parent_container.length ) ) {
745						if ( 'course_navigation_widget' == parentVars.context_sub ) {
746							if ( 'undefined' !== typeof response.data.nav_lessons ) {
747								$( parentVars.parent_container ).html( response.data.nav_lessons ).removeClass( 'ld-loading' );
748							}
749						} else if ( 'focus_mode_sidebar' == parentVars.context_sub ) {
750							if ( 'undefined' !== typeof response.data.nav_lessons ) {
751								$( parentVars.parent_container ).html( response.data.nav_lessons ).removeClass( 'ld-loading' );
752							}
753						} else if ( 'undefined' !== typeof response.data.lessons ) {
754							$( parentVars.parent_container ).html( response.data.lessons ).removeClass( 'ld-loading' );
755						}
756					} else {
757						if ( $( '#ld-item-list-' + linkVars.course_id ).length ) {
758							if ( 'undefined' !== typeof response.data.lessons ) {
759								$( '#ld-item-list-' + linkVars.course_id ).html( response.data.lessons ).removeClass( 'ld-loading' );
760							}
761						}
762
763						if ( $( '#ld-lesson-list-' + linkVars.course_id ).length ) {
764							if ( 'undefined' !== typeof response.data.nav_lessons ) {
765								$( '#ld-lesson-list-' + linkVars.course_id ).html( response.data.nav_lessons ).removeClass( 'ld-loading' );
766							}
767						}
768					}
769				}
770
771				if ( 'group_courses' == linkVars.context ) {
772					if ( ( 'undefined' !== typeof parentVars.parent_container ) && ( parentVars.parent_container.length ) ) {
773						if ( 'undefined' !== typeof response.data.markup ) {
774							$( parentVars.parent_container ).html( response.data.markup ).removeClass( 'ld-loading' );
775						}
776					}
777				}
778
779				if ( 'profile' == linkVars.context ) {
780					if ( 'undefined' !== typeof response.data.markup ) {
781						$( '#ld-profile' ).html( response.data.markup );
782					}
783				}
784
785				if ( 'profile_quizzes' == linkVars.context ) {
786					if ( 'undefined' !== typeof response.data.markup ) {
787						$( '#ld-course-list-item-' + linkVars.pager_results.quiz_course_id + ' .ld-item-list-item-expanded .ld-item-contents' ).replaceWith( response.data.markup );
788						$( '#ld-course-list-item-' + linkVars.pager_results.quiz_course_id ).get( 0 ).scrollIntoView( { behavior: 'smooth' } );
789					}
790				}
791
792				if ( 'course_info_courses' == linkVars.context ) {
793					if ( 'undefined' !== typeof response.data.markup ) {
794						$( '.ld-user-status' ).replaceWith( response.data.markup );
795					}
796				}
797
798				$( 'body' ).trigger( 'ld_has_paginated' );
799
800				initTooltips();
801			},
802		} );
803	} );
804
805	if ( $( '#learndash_timer' ).length ) {
806		var timer_el 		= jQuery( '#learndash_timer' );
807		var timer_seconds 	= timer_el.attr( 'data-timer-seconds' );
808		var timer_button_el = jQuery( timer_el.attr( 'data-button' ) );
809
810		var cookie_key = timer_el.attr( 'data-cookie-key' );
811
812		if ( 'undefined' !== typeof cookie_key ) {
813			var cookie_name = 'learndash_timer_cookie_' + cookie_key;
814		} else {
815			var cookie_name = 'learndash_timer_cookie';
816		}
817
818		cookie_timer_seconds = jQuery.cookie( cookie_name );
819
820		if ( 'undefined' !== typeof cookie_timer_seconds ) {
821			timer_seconds = parseInt( cookie_timer_seconds );
822		}
823
824		if ( 0 == timer_seconds ) {
825			$( timer_el ).hide();
826		}
827
828		$( timer_button_el ).on( 'learndash-time-finished', function() {
829			$( timer_el ).hide();
830		} );
831	}
832
833	$( document ).on( 'learndash_video_disable_assets', function( event, status ) {
834		if ( 'undefined' === typeof learndash_video_data ) {
835			return false;
836		}
837
838		if ( 'BEFORE' == learndash_video_data.videos_shown ) {
839			if ( true == status ) {
840				$( '.ld-lesson-topic-list' ).hide();
841				$( '.ld-lesson-navigation' ).find( '#ld-nav-content-list-' + ldVars.postID ).addClass( 'user_has_no_access' );
842				$( '.ld-quiz-list' ).hide();
843			} else {
844				$( '.ld-lesson-topic-list' ).slideDown();
845				$( '.ld-quiz-list' ).slideDown();
846				$( '.ld-lesson-navigation' ).find( '#ld-nav-content-list-' + ldVars.postID ).removeClass( 'user_has_no_access' );
847			}
848		}
849	} );
850
851	$( '.learndash-wrapper' ).on( 'click', '.wpProQuiz_questionListItem input[type="radio"]', function( e ) {
852		$( this ).parents( '.wpProQuiz_questionList' ).find( 'label' ).removeClass( 'is-selected' );
853		$( this ).parents( 'label' ).addClass( 'is-selected' );
854	} );
855
856	$( '.learndash-wrapper' ).on( 'click', '.wpProQuiz_questionListItem input[type="checkbox"]', function( e ) {
857		if ( jQuery( e.currentTarget ).is( ':checked' ) ) {
858			$( this ).parents( 'label' ).addClass( 'is-selected' );
859		} else {
860			$( this ).parents( 'label' ).removeClass( 'is-selected' );
861		}
862	} );
863
864	function learndash_ld30_show_user_statistic( e ) {
865		e.preventDefault();
866
867		var refId 				= 	jQuery( this ).data( 'ref-id' );
868		var quizId 				= 	jQuery( this ).data( 'quiz-id' );
869		var userId 				= 	jQuery( this ).data( 'user-id' );
870		var statistic_nonce 	= 	jQuery( this ).data( 'statistic-nonce' );
871		var post_data = {
872			action: 'wp_pro_quiz_admin_ajax_statistic_load_user',
873			func: 'statisticLoadUser',
874			data: {
875				quizId: quizId,
876				userId: userId,
877				refId: refId,
878				statistic_nonce: statistic_nonce,
879				avg: 0,
880			},
881		};
882
883		jQuery( '#wpProQuiz_user_overlay, #wpProQuiz_loadUserData' ).show();
884		var content = jQuery( '#wpProQuiz_user_content' ).hide();
885
886		//console.log('- learndash.js');
887
888		jQuery.ajax( {
889			type: 'POST',
890			url: ldVars.ajaxurl,
891			dataType: 'json',
892			cache: false,
893			data: post_data,
894			error: function( jqXHR, textStatus, errorThrown ) {
895			},
896			success: function( reply_data ) {
897				if ( 'undefined' !== typeof reply_data.html ) {
898					content.html( reply_data.html );
899					jQuery( '#wpProQuiz_user_content' ).show();
900
901					//console.log('trigger event change - learndash.js');
902					jQuery( 'body' ).trigger( 'learndash-statistics-contentchanged' );
903
904					jQuery( '#wpProQuiz_loadUserData' ).hide();
905
906					content.find( '.statistic_data' ).on( 'click', function() {
907						jQuery( this ).parents( 'tr' ).next().toggle( 'fast' );
908
909						return false;
910					} );
911				}
912			},
913		} );
914
915		jQuery( '#wpProQuiz_overlay_close' ).on( 'click', function() {
916			jQuery( '#wpProQuiz_user_overlay' ).hide();
917		} );
918	}
919
920	function learndashSetMaxHeight( elm ) {
921		var totalHeight = 0;
922
923		elm.find( '> *' ).each( function() {
924			totalHeight += $( this ).outerHeight();
925		} );
926
927		elm.attr( 'data-height', '' + ( totalHeight + 50 ) + '' );
928
929		elm.css( {
930			'max-height': totalHeight + 50,
931		} );
932	}
933
934	/**
935	 * Will scroll the position of the Focus Mode sidebar
936	 * to the active step.
937	 */
938	function learndashFocusModeSidebarAutoScroll() {
939		if ( jQuery( '.learndash-wrapper .ld-focus' ).length ) {
940			var sidebar_wrapper = jQuery( '.learndash-wrapper .ld-focus .ld-focus-sidebar-wrapper' );
941
942			var sidebar_current_topic = jQuery( '.learndash-wrapper .ld-focus .ld-focus-sidebar-wrapper .ld-is-current-item' );
943			if ( ( 'undefined' !== typeof sidebar_current_topic ) && ( sidebar_current_topic.length ) ) {
944				var sidebar_scrollTo = sidebar_current_topic;
945			} else {
946				var sidebar_current_lesson = jQuery( '.learndash-wrapper .ld-focus .ld-focus-sidebar-wrapper .ld-is-current-lesson' );
947				if ( ( 'undefined' !== typeof sidebar_current_lesson ) && ( sidebar_current_lesson.length ) ) {
948					var sidebar_scrollTo = sidebar_current_lesson;
949				}
950			}
951
952			if ( ( 'undefined' !== typeof sidebar_scrollTo ) && ( sidebar_scrollTo.length ) ) {
953				var offset_top = 0;
954				if ( jQuery( '.learndash-wrapper .ld-focus .ld-focus-header' ).length ) {
955					var logo_height = jQuery( '.learndash-wrapper .ld-focus .ld-focus-header' ).height();
956					offset_top += logo_height;
957				}
958				if ( jQuery( '.learndash-wrapper .ld-focus .ld-focus-sidebar .ld-course-navigation-heading' ).length ) {
959					var heading_height = jQuery( '.learndash-wrapper .ld-focus .ld-focus-sidebar .ld-course-navigation-heading' ).height();
960					offset_top += heading_height;
961				}
962				if ( jQuery( '.learndash-wrapper .ld-focus .ld-focus-sidebar .ld-focus-sidebar-wrapper' ).length ) {
963					var container_height = jQuery( '.learndash-wrapper .ld-focus .ld-focus-sidebar .ld-focus-sidebar-wrapper' ).height();
964					offset_top += container_height;
965				}
966
967				var current_item_height = jQuery( sidebar_scrollTo ).height();
968				offset_top -= current_item_height;
969
970				sidebar_wrapper.animate( {
971					scrollTop: sidebar_scrollTo.offset().top - offset_top,
972				}, 1000 );
973			}
974		}
975	}
976
977	// Coupon processing.
978
979	function update_payment_forms( data ) {
980		$( '#total-row' ).attr( 'data-total', data.total.value )
981
982		// Update PayPal form amount.
983		$( 'form[name="buynow"] input[name="amount"]' ).val( data.total.value );
984
985		// Update Stripe form amount.
986		$( 'form.learndash-stripe-checkout input[name="stripe_price"]' ).val( data.total.stripe_value );
987
988		// Remove Stripe Connect session to respect the new amount.
989		const stripe_course_id = $( '.learndash-stripe-checkout input[name="stripe_course_id"]' ).val();
990
991		if ( stripe_course_id ) {
992			LD_Cookies.remove( 'ld_stripe_session_id_' + stripe_course_id ); // Stripe Plugin (Checkout).
993			LD_Cookies.remove( 'ld_stripe_connect_session_id_' + stripe_course_id ); // Stripe Connect in core.
994		}
995
996		// Re-init Stripe Plugin (Legacy) to respect the new amount.
997		if ( typeof ld_init_stripe_legacy === "function" ) {
998			ld_init_stripe_legacy();
999		}
1000	}
1001
1002	$( '.btn-join' ).on( 'click', function( e ) {
1003		const total = parseFloat( $( '#total-row' ).attr( 'data-total' ) );
1004
1005		if ( 0 === total ) {
1006			$.ajax( {
1007				type: 'POST',
1008				url: ldVars.ajaxurl,
1009				dataType: 'json',
1010				cache: false,
1011				data: {
1012					action: 'learndash_enroll_with_zero_price',
1013					nonce: $( '#apply-coupon-form' ).data( 'nonce' ),
1014					post_id: $( '#apply-coupon-form' ).data( 'post-id' ),
1015				},
1016				success: function( response ) {
1017					if ( response.success ) {
1018						window.location.replace( response.data.redirect_url );
1019					} else {
1020						alert( response.data.message );
1021					}
1022				},
1023			} );
1024
1025			e.preventDefault();
1026			return false;
1027		}
1028	});
1029
1030	$( '#apply-coupon-form' ).on( 'submit', function( e ) {
1031		e.preventDefault();
1032
1033		$.ajax( {
1034			type: 'POST',
1035			url: ldVars.ajaxurl,
1036			dataType: 'json',
1037			cache: false,
1038			data: {
1039				action: 'learndash_apply_coupon',
1040				nonce: $( this ).data( 'nonce' ),
1041				coupon_code: $( this ).find( '#coupon-field' ).val(),
1042				post_id: $( this ).data( 'post-id' ),
1043			},
1044			success: function( response ) {
1045				$( '#coupon-alerts .coupon-alert' ).hide();
1046
1047				let $alert = $( '#coupon-alerts' ).find(
1048					response.success ? '.coupon-alert-success' : '.coupon-alert-warning'
1049				);
1050
1051				let $coupon_row = $( '#coupon-row' );
1052
1053				if ( response.success ) {
1054					$coupon_row.find( '.purchase-label > span' ).html( response.data.coupon_code ); // Set coupon code in totals.
1055					$coupon_row.find( '.purchase-value span' ).html( response.data.discount ); // Set discount value in totals.
1056					$coupon_row.css( 'display', 'flex' ).hide().fadeIn(); // Show a coupon row in totals.
1057					$( '#total-row .purchase-value' ).html( response.data.total.formatted ); // Update Total.
1058					$( '#totals' ).show();
1059
1060					update_payment_forms( response.data );
1061				}
1062
1063				$alert.find( '.ld-alert-messages' ).html( response.data.message );
1064				$alert.fadeIn();
1065			},
1066		} );
1067	} );
1068
1069	$( '#remove-coupon-form' ).on( 'submit', function( e ) {
1070		e.preventDefault();
1071
1072		$.ajax( {
1073			type: 'POST',
1074			url: ldVars.ajaxurl,
1075			dataType: 'json',
1076			cache: false,
1077			data: {
1078				action: 'learndash_remove_coupon',
1079				nonce: $( this ).data( 'nonce' ),
1080				post_id: $( this ).data( 'post-id' ),
1081			},
1082			success: function( response ) {
1083				$( '#coupon-alerts .coupon-alert' ).hide();
1084
1085				let $alert = $( '#coupon-alerts' ).find(
1086					response.success ? '.coupon-alert-success' : '.coupon-alert-warning'
1087				);
1088
1089				if ( response.success ) {
1090					$( '#coupon-row' ).hide(); // Hide a coupon row in totals.
1091					$( '#coupon-field' ).val( '' ); // Set coupon field empty.
1092					$( '#price-row .purchase-value' ).html( response.data.total.formatted ); // Update Price.
1093					$( '#subtotal-row .purchase-value' ).html( response.data.total.formatted ); // Update Subtotal.
1094					$( '#total-row .purchase-value' ).html( response.data.total.formatted ); // Update Total.
1095					$( '#totals' ).hide();
1096
1097					update_payment_forms( response.data );
1098				}
1099
1100				$alert.find( '.ld-alert-messages' ).html( response.data.message );
1101				$alert.fadeIn();
1102			},
1103		} );
1104	} );
1105} );
1106
1107function ldGetUrlVars() {
1108	var vars = {};
1109	var parts = window.location.href.replace( /[?&]+([^=&]+)=([^&]*)/gi, function( m, key, value ) {
1110		vars[key] = value;
1111	} );
1112
1113	return vars;
1114}

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.