PageSourceSearch

https://www.thereadingleague.org/wp-content/plugins/sfwd-lms/themes/ld30/assets/js/learndash.js?ver=4.16.1

js thereadingleague.org collected 2026-10-01 10:41:11 UTC 41,836 bytes, 1,589 lines download raw bytes

1/* eslint-disable no-var */
2jQuery(function ($) {
3	var hash = window.location.hash;
4
5	learndashFocusModeSidebarAutoScroll();
6
7	initLoginModal();
8	if ('#login' == hash) {
9		openLoginModal();
10	}
11
12	if ('undefined' !== typeof ldGetUrlVars().login) {
13		var loginStatus = ldGetUrlVars().login;
14
15		if ('failed' == loginStatus) {
16			openLoginModal();
17		}
18	}
19
20	if ('undefined' !== typeof ldGetUrlVars()['ld-topic-page']) {
21		var topicPage = ldGetUrlVars()['ld-topic-page'];
22		var topicIds = topicPage.split('-');
23		var topicId = Object.values(topicIds)[0];
24
25		var lesson = $('#ld-expand-' + topicId);
26		var button = $(lesson).find('.ld-expand-button');
27
28		ld_expand_element(button);
29
30		$('html, body').animate(
31			{
32				scrollTop: $(lesson).offset().top,
33			},
34			500
35		);
36	}
37
38	$('body').on('click', 'a[href="#login"]', function (e) {
39		e.preventDefault();
40		openLoginModal();
41	});
42
43	$('body').on('click', '.ld-modal-closer', function (e) {
44		e.preventDefault();
45		closeLoginModal();
46	});
47
48	$('body').on('click', '#ld-comments-post-button', function (e) {
49		$(this).addClass('ld-open');
50		$('#ld-comments-form').removeClass('ld-collapsed');
51		$('textarea#comment').focus();
52	});
53
54	// Close modal if clicking away
55	/*
56	$('body').on('click', function(e) {
57		if ($('.learndash-wrapper').hasClass('ld-modal-open')) {
58			if ( ! $(e.target).parents('.ld-modal').length && (! $(e.target).is('a'))) {
59				closeLoginModal();
60			}
61		}
62	});
63	*/
64
65	// Close modal on Esc key
66	$(document).on('keyup', function (e) {
67		if (27 === e.keyCode) {
68			closeLoginModal();
69		}
70	});
71
72	$('.learndash-wrapper').on(
73		'click',
74		'a.user_statistic',
75		learndash_ld30_show_user_statistic
76	);
77
78	focusMobileCheck();
79
80	$('body').on('click', '.ld-focus-sidebar-trigger', function (e) {
81		if ($('.ld-focus').hasClass('ld-focus-sidebar-collapsed')) {
82			openFocusSidebar();
83		} else {
84			closeFocusSidebar();
85		}
86	});
87
88	$('body').on('click', '.ld-mobile-nav a', function (e) {
89		e.preventDefault();
90		if ($('.ld-focus').hasClass('ld-focus-sidebar-collapsed')) {
91			openFocusSidebar();
92		} else {
93			closeFocusSidebar();
94		}
95	});
96
97	$('.ld-js-register-account').on('click', function (e) {
98		e.preventDefault();
99
100		$('.ld-login-modal-register .ld-modal-text').slideUp('slow');
101		$('.ld-login-modal-register .ld-alert').slideUp('slow');
102		$(this).slideUp('slow', function () {
103			$('#ld-user-register').slideDown('slow');
104		});
105	});
106
107	// If registration login link filter not defined, allow to replace the register form with login form
108	ldRegistrationLinkInit();
109	ldRegistrationLinkInitModern();
110
111	var windowWidth = $(window).width();
112
113	$(window).on('orientationchange', function () {
114		windowWidth = $(window).width();
115	});
116
117	$(window).on('resize', function () {
118		if ($(this).width() !== windowWidth && 1024 >= $(this).width()) {
119			setTimeout(function () {
120				focusMobileResizeCheck();
121			}, 50);
122		}
123	});
124
125	if ($('.ld-course-status-content').length) {
126		var tallest = 0;
127
128		$('.ld-course-status-content').each(function () {
129			if ($(this).height() > tallest) {
130				tallest = $(this).height();
131			}
132		});
133
134		$('.ld-course-status-content').height(tallest);
135	}
136
137	function focusMobileCheck() {
138		if (1024 > $(window).width()) {
139			closeFocusSidebarPageLoad();
140		}
141	}
142
143	function focusMobileResizeCheck() {
144		if (
145			1024 > $(window).width() &&
146			!$('.ld-focus').hasClass('ld-focus-sidebar-collapsed')
147		) {
148			closeFocusSidebar();
149		} else if (
150			1024 <= $(window).width() &&
151			$('.ld-focus').hasClass('ld-focus-sidebar-filtered')
152		) {
153			closeFocusSidebar();
154		} else if (
155			1024 <= $(window).width() &&
156			!$('.ld-focus').hasClass('ld-focus-sidebar-filtered') &&
157			$('.ld-focus').hasClass('ld-focus-sidebar-collapsed')
158		) {
159			openFocusSidebar();
160		}
161	}
162
163	function focusMobileHandleOrientationChange(e) {
164		if (e.matches) {
165			if (
166				1024 <= $(window).width() &&
167				!$('.ld-focus').hasClass('ld-focus-sidebar-filtered') &&
168				$('.ld-focus').hasClass('ld-focus-sidebar-collapsed')
169			) {
170				openFocusSidebar();
171			}
172		}
173	}
174	window
175		.matchMedia('(orientation: landscape)')
176		.addListener(focusMobileHandleOrientationChange);
177
178	function closeFocusSidebarPageLoad() {
179		$('.ld-focus').addClass('ld-focus-sidebar-collapsed');
180		$('.ld-focus').removeClass('ld-focus-initial-transition');
181		$('.ld-mobile-nav').removeClass('expanded');
182		positionTooltips();
183	}
184
185	function closeFocusSidebar() {
186		$('.ld-focus').addClass('ld-focus-sidebar-collapsed');
187		$('.ld-mobile-nav').removeClass('expanded');
188
189		if (
190			$('.ld-focus-sidebar-trigger .ld-icon').hasClass(
191				'ld-icon-arrow-left'
192			)
193		) {
194			$('.ld-focus-sidebar-trigger .ld-icon').removeClass(
195				'ld-icon-arrow-left'
196			);
197			$('.ld-focus-sidebar-trigger .ld-icon').addClass(
198				'ld-icon-arrow-right'
199			);
200		} else if (
201			$('.ld-focus-sidebar-trigger .ld-icon').hasClass(
202				'ld-icon-arrow-right'
203			)
204		) {
205			$('.ld-focus-sidebar-trigger .ld-icon').removeClass(
206				'ld-icon-arrow-right'
207			);
208			$('.ld-focus-sidebar-trigger .ld-icon').addClass(
209				'ld-icon-arrow-left'
210			);
211		}
212
213		positionTooltips();
214	}
215
216	function openFocusSidebar() {
217		focusMobileCheck();
218		$('.ld-focus').removeClass('ld-focus-sidebar-collapsed');
219		$('.ld-mobile-nav').addClass('expanded');
220
221		if (
222			$('.ld-focus-sidebar-trigger .ld-icon').hasClass(
223				'ld-icon-arrow-left'
224			)
225		) {
226			$('.ld-focus-sidebar-trigger .ld-icon').removeClass(
227				'ld-icon-arrow-left'
228			);
229			$('.ld-focus-sidebar-trigger .ld-icon').addClass(
230				'ld-icon-arrow-right'
231			);
232		} else if (
233			$('.ld-focus-sidebar-trigger .ld-icon').hasClass(
234				'ld-icon-arrow-right'
235			)
236		) {
237			$('.ld-focus-sidebar-trigger .ld-icon').removeClass(
238				'ld-icon-arrow-right'
239			);
240			$('.ld-focus-sidebar-trigger .ld-icon').addClass(
241				'ld-icon-arrow-left'
242			);
243		}
244
245		positionTooltips();
246	}
247
248	$('.ld-file-input').each(function () {
249		var $input = $(this),
250			$label = $input.next('label'),
251			labelVal = $label.html();
252
253		$input.on('change', function (e) {
254			var fileName = '';
255			if (this.files && 1 < this.files.length) {
256				fileName = (
257					this.getAttribute('data-multiple-caption') || ''
258				).replace('{count}', this.files.length);
259			} else if (e.target.value) {
260				fileName = e.target.value.split('\\').pop();
261			}
262			if (fileName) {
263				$label.find('span').html(fileName);
264				$label.addClass('ld-file-selected');
265				$('#uploadfile_btn').attr('disabled', false);
266			} else {
267				$label.html(labelVal);
268				$label.removeClass('ld-file-selected');
269				$('#uploadfile_btn').attr('disabled', true);
270			}
271		});
272
273		$('#uploadfile_form').on('submit', function () {
274			$label.removeClass('ld-file-selected');
275			$('#uploadfile_btn').attr('disabled', true);
276		});
277
278		// Firefox bug fix
279		$input
280			.on('focus', function () {
281				$input.addClass('has-focus');
282			})
283			.on('blur', function () {
284				$input.removeClass('has-focus');
285			});
286	});
287
288	$('body').on('click', '.ld-expand-button', function (e) {
289		e.preventDefault();
290
291		ld_expand_element($(this));
292
293		positionTooltips();
294	});
295
296	$('body').on('click', '.ld-search-prompt', function (e) {
297		e.preventDefault();
298
299		$('#course_name_field').focus();
300
301		ld_expand_element($(this));
302	});
303
304	function ld_expand_button_state(state, elm) {
305		var $expandText = $(elm)[0].hasAttribute('data-ld-expand-text')
306			? $(elm).attr('data-ld-expand-text')
307			: 'Expand';
308		var $collapseText = $(elm)[0].hasAttribute('data-ld-collapse-text')
309			? $(elm).attr('data-ld-collapse-text')
310			: 'Collapse';
311
312		if ('collapse' == state) {
313			$(elm).removeClass('ld-expanded');
314			if ('false' !== $collapseText) {
315				$(elm).find('.ld-text').text($expandText);
316			}
317		} else {
318			$(elm).addClass('ld-expanded');
319			if ('false' !== $collapseText) {
320				$(elm).find('.ld-text').text($collapseText);
321			}
322		}
323	}
324
325	function ld_expand_element(elm, collapse) {
326		if (collapse === undefined) {
327			collapse = false;
328		}
329
330		var elmParentWrapper = elm.parents('.ld-focus-sidebar');
331		if (
332			'undefined' === typeof elmParentWrapper ||
333			!elmParentWrapper.length
334		) {
335			var elmParentWrapper = elm.parents('.learndash-wrapper');
336		}
337		if (
338			'undefined' === typeof elmParentWrapper ||
339			!elmParentWrapper.length
340		) {
341			return;
342		}
343
344		// Get the button's state
345		var $expanded = $(elm).hasClass('ld-expanded');
346
347		// Get the element to expand
348		if ($(elm)[0] && $(elm)[0].hasAttribute('data-ld-expands')) {
349			var $expands = $(elm).attr('data-ld-expands');
350			if ('undefined' === typeof $expands || !$expands.length) {
351				return;
352			}
353
354			var $expandElm = $(elmParentWrapper).find(
355				'[data-ld-expand-id="' + $expands + '"]'
356			);
357			if ('undefined' === typeof $expandElm || !$expandElm.length) {
358				return;
359			}
360
361			var $expandsChild = $($expandElm).find(
362				'.ld-item-list-item-expanded'
363			);
364
365			if ($expandsChild.length) {
366				$expandElm = $expandsChild;
367			}
368
369			var totalHeight = 0;
370
371			$expandElm.find('> *').each(function () {
372				totalHeight += $(this).outerHeight();
373			});
374
375			$expandElm.attr('data-height', '' + (totalHeight + 50) + '');
376
377			// If the element expands a list
378
379			if (
380				$(elmParentWrapper)
381					.find('[data-ld-expand-id="' + $expands + '"]')[0]
382					.hasAttribute('data-ld-expand-list')
383			) {
384				var $container = $(elmParentWrapper).find(
385					'[data-ld-expand-id="' + $expands + '"]'
386				);
387				var innerButtons = $container.find('.ld-expand-button');
388				if ($expanded) {
389					ld_expand_button_state('collapse', elm);
390					innerButtons.each(function () {
391						ld_expand_element($(this), true);
392					});
393				} else {
394					ld_expand_button_state('expand', elm);
395					innerButtons.each(function () {
396						ld_expand_element($(this));
397					});
398				}
399
400				// If the element expands an item
401			} else if (
402				$(elmParentWrapper).find(
403					'[data-ld-expand-id="' + $expands + '"]'
404				).length
405			) {
406				if ($expanded || true == collapse) {
407					ld_expand_singular_item(
408						elm,
409						$(elmParentWrapper).find(
410							'[data-ld-expand-id="' + $expands + '"]'
411						),
412						$expandElm
413					);
414				} else {
415					ld_collapse_singular_item(
416						elm,
417						$(elmParentWrapper).find(
418							'[data-ld-expand-id="' + $expands + '"]'
419						),
420						$expandElm
421					);
422				}
423			} else {
424				console.log('LearnDash: No expandable content was found');
425			}
426			positionTooltips();
427		}
428	}
429
430	function ld_expand_singular_item(elm, $containerElm, $expandElm) {
431		$containerElm.removeClass('ld-expanded');
432		ld_expand_button_state('collapse', elm);
433
434		$expandElm.css({
435			'max-height': 0,
436		});
437	}
438
439	function ld_collapse_singular_item(elm, $containerElm, $expandElm) {
440		$containerElm.addClass('ld-expanded');
441
442		ld_expand_button_state('expand', elm);
443
444		$expandElm.css({
445			'max-height': $expandElm.data('height'),
446		});
447	}
448
449	/**
450	 * Initialize registration link in the classic registration page.
451	 *
452	 * @since 4.16.0
453	 *
454	 * @return {void}
455	 */
456	function ldRegistrationLinkInit() {
457		const $loginLink = $( '.registration-login-link' );
458
459		if ( $loginLink.length === 0 ) {
460			return;
461		}
462
463		if ( '' !== $loginLink.attr( 'href' ) ) {
464			return;
465		}
466
467		$loginLink.on( 'click', function( e ) {
468			e.preventDefault();
469			$( '#learndash_registerform, .registration-login' ).hide();
470			$(
471				'.registration-login-form, .show-register-form, .show-password-reset-link'
472			).show();
473		} );
474
475		$( '.show-register-form' ).on( 'click', function( e ) {
476			e.preventDefault();
477			$(
478				'.registration-login-form, .show-register-form, .show-password-reset-link'
479			).hide();
480			$( '#learndash_registerform, .registration-login' ).show();
481		} );
482	}
483
484	/**
485	 * Initialize registration link in the modern registration page.
486	 *
487	 * @since 4.16.0
488	 *
489	 * @return {void}
490	 */
491	function ldRegistrationLinkInitModern() {
492		const $loginLink = $( '.ld-registration__login-link' );
493
494		if ( $loginLink.length === 0 ) {
495			return;
496		}
497
498		if ( '' !== $loginLink.attr( 'href' ) ) {
499			return;
500		}
501
502		$( document ).on( 'click', '.ld-registration__login-link', function( e ) {
503			e.preventDefault();
504			let $wrapper = $( this ).closest( '.ld-registration__wrapper' );
505			$wrapper.addClass( 'ld-registration__wrapper--login' );
506			$wrapper.removeClass( 'ld-registration__wrapper--register' );
507		} );
508
509		$( document ).on( 'click', '.ld-registration__register-link', function( e ) {
510			e.preventDefault();
511			let $wrapper = $( this ).closest( '.ld-registration__wrapper' );
512			$wrapper.removeClass( 'ld-registration__wrapper--login' );
513			$wrapper.addClass( 'ld-registration__wrapper--register' );
514		} );
515	}
516
517	$('body').on('click', '.ld-closer', function (e) {
518		ld_expand_element($('.ld-search-prompt'), true);
519	});
520
521	$('body').on('click', '.ld-tabs-navigation .ld-tab', function () {
522		var $tab = $('#' + $(this).attr('data-ld-tab'));
523		if ($tab.length) {
524			$('.ld-tabs-navigation .ld-tab.ld-active').removeClass('ld-active');
525			$('.ld-tabs-navigation .ld-tab').removeAttr('aria-selected');
526			$(this).addClass('ld-active');
527			$(this).attr('aria-selected', 'true');
528			$('.ld-tabs-content .ld-tab-content.ld-visible').removeClass(
529				'ld-visible'
530			);
531			$tab.addClass('ld-visible');
532		}
533		positionTooltips();
534	});
535
536	var $tooltips = $('*[data-ld-tooltip]');
537
538	initTooltips();
539
540	function initTooltips() {
541		// Clear out old tooltips
542
543		if ($('#learndash-tooltips').length) {
544			$('#learndash-tooltips').remove();
545			$tooltips = $('*[data-ld-tooltip]');
546		}
547
548		if ($tooltips.length) {
549			$('body').prepend('<div id="learndash-tooltips"></div>');
550			var $ctr = 1;
551			$tooltips.each(function () {
552				var anchor = $(this);
553				if (anchor.hasClass('ld-item-list-item')) {
554					anchor = anchor.find('.ld-item-title');
555				}
556
557				/**
558				 * Prevent calendar icon from being clickable.
559				 */
560				if (
561					'undefined' !== typeof anchor &&
562					$(anchor).hasClass('ld-status-waiting')
563				) {
564					$(anchor).on('click', function (e) {
565						e.preventDefault();
566						return false;
567					});
568
569					// Also prevent parent <a> from being clickable.
570					var parent_anchor = $(anchor).parents('a');
571					if ('undefined' !== typeof parent_anchor) {
572						$(parent_anchor).on('click', function (e) {
573							e.preventDefault();
574							return false;
575						});
576					}
577				}
578
579				var elementOffsets = {
580					top: anchor.offset().top,
581					left: anchor.offset().left + anchor.outerWidth() / 2,
582				};
583				var $content = $(this).attr('data-ld-tooltip');
584				var $rel_id = Math.floor(Math.random() * 99999);
585
586				//var $tooltip = '<span id="ld-tooltip-' + $rel_id + '" class="ld-tooltip" style="top:' + elementOffsets.top + 'px; left:' + elementOffsets.left + 'px;">' + $content + '</span>';
587				var $tooltip =
588					'<span id="ld-tooltip-' +
589					$rel_id +
590					'" class="ld-tooltip">' +
591					$content +
592					'</span>';
593				$(this).attr('data-ld-tooltip-id', $rel_id);
594				$('#learndash-tooltips').append($tooltip);
595				$ctr++;
596				var $tooltip = $('#ld-tooltip-' + $rel_id);
597				$(this)
598					.on('mouseenter', function () {
599						$tooltip.addClass('ld-visible');
600					})
601					.on('mouseleave', function () {
602						$tooltip.removeClass('ld-visible');
603					});
604			});
605
606			$(window).on('resize', function () {
607				// Reposition tooltips after resizing
608				positionTooltips();
609			});
610
611			$(window)
612				.add('.ld-focus-sidebar-wrapper')
613				.on('scroll', function () {
614					// Hide tooltips so they don't persist while scrolling
615					$('.ld-visible.ld-tooltip').removeClass('ld-visible');
616
617					// Reposition tooltips after scrolling
618					positionTooltips();
619				});
620
621			positionTooltips();
622		}
623	}
624
625	function initLoginModal() {
626		var modal_wrapper = $('.learndash-wrapper-login-modal');
627		if ('undefined' !== typeof modal_wrapper && modal_wrapper.length) {
628			// Move the model to be first element of the body. See LEARNDASH-3503
629			$(modal_wrapper).prependTo('body');
630		}
631	}
632
633	function openLoginModal() {
634		var modal_wrapper = $('.learndash-wrapper-login-modal');
635		if ('undefined' !== typeof modal_wrapper && modal_wrapper.length) {
636			$(modal_wrapper).addClass('ld-modal-open');
637			$(modal_wrapper).removeClass('ld-modal-closed');
638
639			// Removed LEARNDASH-3867 #4
640			$('html, body').animate(
641				{
642					scrollTop: $('.ld-modal', modal_wrapper).offset().top,
643				},
644				50
645			);
646		}
647	}
648
649	function closeLoginModal() {
650		var modal_wrapper = $('.learndash-wrapper-login-modal');
651		if ('undefined' !== typeof modal_wrapper && modal_wrapper.length) {
652			$(modal_wrapper).removeClass('ld-modal-open');
653			$(modal_wrapper).addClass('ld-modal-closed');
654		}
655	}
656
657	function positionTooltips() {
658		if ('undefined' !== typeof $tooltips) {
659			setTimeout(function () {
660				$tooltips.each(function () {
661					var anchor = $(this);
662					var $rel_id = anchor.attr('data-ld-tooltip-id');
663					$tooltip = $('#ld-tooltip-' + $rel_id);
664
665					if (anchor.hasClass('ld-item-list-item')) {
666						//anchor = anchor.find('.ld-item-title');
667						anchor = anchor.find('.ld-status-icon');
668					}
669
670					var parent_focus =
671						jQuery(anchor).parents('.ld-focus-sidebar');
672					var left_post =
673						anchor.offset().left + (anchor.outerWidth() + 10);
674					if (parent_focus.length) {
675						left_post =
676							anchor.offset().left + (anchor.outerWidth() - 18);
677					}
678
679					// Get the main content height
680					var focusModeMainContentHeight =
681						$('.ld-focus-main').height();
682
683					// Current tooltip height
684					var focusModeCurrentTooltipHeight =
685						anchor.offset().top + -3;
686
687					// Position tooltip depending on focus mode or not
688					if (!focusModeMainContentHeight) {
689						var anchorTop = anchor.offset().top + -3;
690						var anchorLeft = anchor.offset().left;
691					} else {
692						anchorTop =
693							focusModeCurrentTooltipHeight <
694							focusModeMainContentHeight
695								? focusModeCurrentTooltipHeight
696								: focusModeMainContentHeight;
697						anchorLeft = left_post;
698					}
699
700					$tooltip
701						.css({
702							top: anchorTop,
703
704							//'left' : anchor.offset().left + (anchor.outerWidth() / 2),
705							//'left': left_post, //anchor.offset().left + (anchor.outerWidth() +10),
706							left: anchorLeft, //anchor.offset().left + (anchor.outerWidth() +10),
707							'margin-left': 0,
708							'margin-right': 0,
709						})
710						.removeClass('ld-shifted-left ld-shifted-right');
711					if ($tooltip.offset().left <= 0) {
712						$tooltip
713							.css({
714								'margin-left': Math.abs($tooltip.offset().left),
715							})
716							.addClass('ld-shifted-left');
717					}
718					var $tooltipRight =
719						$(window).width() -
720						($tooltip.offset().left + $tooltip.outerWidth());
721					if (0 >= $tooltipRight && 360 < $(window).width()) {
722						$tooltip
723							.css({ 'margin-right': Math.abs($tooltipRight) })
724							.addClass('ld-shifted-right');
725					}
726				});
727			}, 500);
728		}
729	}
730
731	$('body').on('click', '#ld-profile .ld-reset-button', function (e) {
732		e.preventDefault();
733
734		$('#ld-profile #course_name_field').val('');
735
736		var searchVars = {
737			shortcode_instance: $('#ld-profile').data('shortcode_instance'),
738		};
739
740		searchVars['ld-profile-search'] = $(this)
741			.parents('.ld-item-search-wrapper')
742			.find('#course_name_field')
743			.val();
744		searchVars['ld-profile-search-nonce'] = $(this)
745			.parents('.ld-item-search-wrapper')
746			.find('form.ld-item-search-fields')
747			.data('nonce');
748
749		$('#ld-profile #ld-main-course-list').addClass('ld-loading');
750
751		$.ajax({
752			type: 'GET',
753			url: ldVars.ajaxurl + '?action=ld30_ajax_profile_search',
754			data: searchVars,
755			success(response) {
756				if ('undefined' !== typeof response.data.markup) {
757					$('#ld-profile').html(response.data.markup);
758					ld_expand_element('#ld-profile .ld-search-prompt', false);
759				}
760			},
761		});
762	});
763
764	$('body').on('submit', '.ld-item-search-fields', function (e) {
765		e.preventDefault();
766
767		var searchVars = {
768			shortcode_instance: $('#ld-profile').data('shortcode_instance'),
769		};
770
771		searchVars['ld-profile-search'] = $(this)
772			.parents('.ld-item-search-wrapper')
773			.find('#course_name_field')
774			.val();
775		searchVars['ld-profile-search-nonce'] = $(this)
776			.parents('.ld-item-search-wrapper')
777			.find('form.ld-item-search-fields')
778			.data('nonce');
779
780		$('#ld-profile #ld-main-course-list').addClass('ld-loading');
781
782		$.ajax({
783			type: 'GET',
784			url: ldVars.ajaxurl + '?action=ld30_ajax_profile_search',
785			data: searchVars,
786			success(response) {
787				if ('undefined' !== typeof response.data.markup) {
788					$('#ld-profile').html(response.data.markup);
789					ld_expand_element('#ld-profile .ld-search-prompt', false);
790				}
791			},
792		});
793	});
794
795	$('body').on('click', '.ld-pagination a', function (e) {
796		e.preventDefault();
797
798		var linkVars = {};
799		var parentVars = {};
800
801		$(this)
802			.attr('href')
803			.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
804				linkVars[key] = value;
805			});
806
807		linkVars.pager_nonce = $(this)
808			.parents('.ld-pagination')
809			.data('pager-nonce');
810
811		linkVars.pager_results = $(this)
812			.parents('.ld-pagination')
813			.data('pager-results');
814
815		linkVars.context = $(this).data('context');
816		console.log('linkVars[%o]', linkVars);
817
818		parentVars.currentTarget = e.currentTarget;
819
820		if ('profile' != linkVars.context) {
821			linkVars.lesson_id = $(this).data('lesson_id');
822			linkVars.course_id = $(this).data('course_id');
823
824			if ($('.ld-course-nav-' + linkVars.course_id).length) {
825				linkVars.widget_instance = $(
826					'.ld-course-nav-' + linkVars.course_id
827				).data('widget_instance');
828			}
829		}
830
831		if ('course_topics' == linkVars.context) {
832			$('#ld-topic-list-' + linkVars.lesson_id).addClass('ld-loading');
833			$('#ld-nav-content-list-' + linkVars.lesson_id).addClass(
834				'ld-loading'
835			);
836		}
837
838		if ('course_content_shortcode' == linkVars.context) {
839			parentVars.parent_container = $(parentVars.currentTarget).closest(
840				'.ld-course-content-' + linkVars.course_id
841			);
842			if (
843				'undefined' !== typeof parentVars.parent_container &&
844				parentVars.parent_container.length
845			) {
846				$(parentVars.parent_container).addClass('ld-loading');
847				linkVars.shortcode_instance = $(
848					parentVars.parent_container
849				).data('shortcode_instance');
850			} else {
851				$('.ld-course-content-' + linkVars.course_id).addClass(
852					'ld-loading'
853				);
854				linkVars.shortcode_instance = $(
855					'.ld-course-content-' + linkVars.course_id
856				).data('shortcode_instance');
857			}
858		} else if ('course_lessons' == linkVars.context) {
859			var parent_container;
860
861			// Check if we are within the Course Navigation Widget.
862			if (
863				'undefined' === typeof parentVars.parent_container ||
864				!parentVars.parent_container.length
865			) {
866				parent_container = $(parentVars.currentTarget).parents(
867					'.ld-lesson-navigation'
868				);
869				if (
870					'undefined' !== typeof parent_container &&
871					parent_container.length
872				) {
873					parentVars.context_sub = 'course_navigation_widget';
874					parentVars.parent_container = $(
875						parentVars.currentTarget
876					).parents('#ld-lesson-list-' + linkVars.course_id);
877				}
878			}
879
880			// Check if we are within the Focus Mode Sidebar.
881			if (
882				'undefined' === typeof parentVars.parent_container ||
883				!parentVars.parent_container.length
884			) {
885				parent_container = $(parentVars.currentTarget).parents(
886					'.ld-focus-sidebar-wrapper'
887				);
888				if (
889					'undefined' !== typeof parent_container &&
890					parent_container.length
891				) {
892					parentVars.context_sub = 'focus_mode_sidebar';
893					parentVars.parent_container = $(
894						parentVars.currentTarget
895					).parents('#ld-lesson-list-' + linkVars.course_id);
896				}
897			}
898
899			if (
900				'undefined' === typeof parentVars.parent_container ||
901				!parentVars.parent_container.length
902			) {
903				parentVars.parent_container = $(
904					parentVars.currentTarget
905				).closest(
906					'#ld-item-list-' + linkVars.course_id,
907					'#ld-lesson-list-' + linkVars.course_id
908				);
909			}
910			if (
911				'undefined' !== typeof parentVars.parent_container &&
912				parentVars.parent_container.length
913			) {
914				$(parentVars.parent_container).addClass('ld-loading');
915			} else {
916				// Fallback solution.
917				$('#ld-item-list-' + linkVars.course_id).addClass('ld-loading');
918				$('#ld-lesson-list-' + linkVars.course_id).addClass(
919					'ld-loading'
920				);
921			}
922		}
923
924		if ('profile' == linkVars.context) {
925			$('#ld-profile #ld-main-course-list').addClass('ld-loading');
926			linkVars.shortcode_instance =
927				$('#ld-profile').data('shortcode_instance');
928		}
929
930		if ('profile_quizzes' == linkVars.context) {
931			$(
932				'#ld-course-list-item-' +
933					linkVars.pager_results.quiz_course_id +
934					' .ld-item-contents'
935			).addClass('ld-loading');
936		}
937
938		if ('course_info_courses' == linkVars.context) {
939			$('.ld-user-status').addClass('ld-loading');
940			linkVars.shortcode_instance =
941				$('.ld-user-status').data('shortcode-atts');
942		}
943
944		if ('group_courses' == linkVars.context) {
945			linkVars.group_id = $(this).data('group_id');
946			if ('undefined' !== typeof linkVars.group_id) {
947				parent_container = $(parentVars.currentTarget).parents(
948					'.ld-group-courses-' + linkVars.group_id
949				);
950				if (
951					'undefined' !== typeof parent_container &&
952					parent_container.length
953				) {
954					$(parent_container).addClass('ld-loading');
955					parentVars.parent_container = parent_container;
956				}
957			}
958		}
959
960		$.ajax({
961			type: 'GET',
962			url: ldVars.ajaxurl + '?action=ld30_ajax_pager',
963			data: linkVars,
964			success(response) {
965				// If we have a course listing, update
966
967				if ('course_topics' == linkVars.context) {
968					if ($('#ld-topic-list-' + linkVars.lesson_id).length) {
969						if ('undefined' !== typeof response.data.topics) {
970							$('#ld-topic-list-' + linkVars.lesson_id).html(
971								response.data.topics
972							);
973						}
974
975						if ('undefined' !== typeof response.data.pager) {
976							$('#ld-expand-' + linkVars.lesson_id)
977								.find('.ld-table-list-footer')
978								.html(response.data.pager);
979						}
980
981						learndashSetMaxHeight(
982							$('.ld-lesson-item-' + linkVars.lesson_id).find(
983								'.ld-item-list-item-expanded'
984							)
985						);
986
987						$('#ld-topic-list-' + linkVars.lesson_id).removeClass(
988							'ld-loading'
989						);
990					}
991
992					if (
993						$('#ld-nav-content-list-' + linkVars.lesson_id).length
994					) {
995						if ('undefined' !== typeof response.data.nav_topics) {
996							$('#ld-nav-content-list-' + linkVars.lesson_id)
997								.find('.ld-table-list-items')
998								.html(response.data.topics);
999						}
1000
1001						if ('undefined' !== typeof response.data.pager) {
1002							$('#ld-nav-content-list-' + linkVars.lesson_id)
1003								.find('.ld-table-list-footer')
1004								.html(response.data.pager);
1005						}
1006
1007						$(
1008							'#ld-nav-content-list-' + linkVars.lesson_id
1009						).removeClass('ld-loading');
1010					}
1011				}
1012
1013				if ('course_content_shortcode' == linkVars.context) {
1014					if ('undefined' !== typeof response.data.markup) {
1015						if (
1016							'undefined' !==
1017								typeof parentVars.parent_container &&
1018							parentVars.parent_container.length
1019						) {
1020							$(parentVars.parent_container).replaceWith(
1021								response.data.markup
1022							);
1023						} else {
1024							$(
1025								'#learndash_post_' + linkVars.course_id
1026							).replaceWith(response.data.markup);
1027						}
1028					}
1029				} else if ('course_lessons' == linkVars.context) {
1030					if (
1031						'undefined' !== typeof parentVars.parent_container &&
1032						parentVars.parent_container.length
1033					) {
1034						if (
1035							'course_navigation_widget' == parentVars.context_sub
1036						) {
1037							if (
1038								'undefined' !== typeof response.data.nav_lessons
1039							) {
1040								$(parentVars.parent_container)
1041									.html(response.data.nav_lessons)
1042									.removeClass('ld-loading');
1043							}
1044						} else if (
1045							'focus_mode_sidebar' == parentVars.context_sub
1046						) {
1047							if (
1048								'undefined' !== typeof response.data.nav_lessons
1049							) {
1050								$(parentVars.parent_container)
1051									.html(response.data.nav_lessons)
1052									.removeClass('ld-loading');
1053							}
1054						} else if (
1055							'undefined' !== typeof response.data.lessons
1056						) {
1057							$(parentVars.parent_container)
1058								.html(response.data.lessons)
1059								.removeClass('ld-loading');
1060						}
1061					} else {
1062						if ($('#ld-item-list-' + linkVars.course_id).length) {
1063							if ('undefined' !== typeof response.data.lessons) {
1064								$('#ld-item-list-' + linkVars.course_id)
1065									.html(response.data.lessons)
1066									.removeClass('ld-loading');
1067							}
1068						}
1069
1070						if ($('#ld-lesson-list-' + linkVars.course_id).length) {
1071							if (
1072								'undefined' !== typeof response.data.nav_lessons
1073							) {
1074								$('#ld-lesson-list-' + linkVars.course_id)
1075									.html(response.data.nav_lessons)
1076									.removeClass('ld-loading');
1077							}
1078						}
1079					}
1080				}
1081
1082				if ('group_courses' == linkVars.context) {
1083					if (
1084						'undefined' !== typeof parentVars.parent_container &&
1085						parentVars.parent_container.length
1086					) {
1087						if ('undefined' !== typeof response.data.markup) {
1088							$(parentVars.parent_container)
1089								.html(response.data.markup)
1090								.removeClass('ld-loading');
1091						}
1092					}
1093				}
1094
1095				if ('profile' == linkVars.context) {
1096					if ('undefined' !== typeof response.data.markup) {
1097						$('#ld-profile').html(response.data.markup);
1098					}
1099				}
1100
1101				if ('profile_quizzes' == linkVars.context) {
1102					if ('undefined' !== typeof response.data.markup) {
1103						$(
1104							'#ld-course-list-item-' +
1105								linkVars.pager_results.quiz_course_id +
1106								' .ld-item-list-item-expanded .ld-item-contents'
1107						).replaceWith(response.data.markup);
1108						$(
1109							'#ld-course-list-item-' +
1110								linkVars.pager_results.quiz_course_id
1111						)
1112							.get(0)
1113							.scrollIntoView({ behavior: 'smooth' });
1114					}
1115				}
1116
1117				if ('course_info_courses' == linkVars.context) {
1118					if ('undefined' !== typeof response.data.markup) {
1119						$('.ld-user-status').replaceWith(response.data.markup);
1120					}
1121				}
1122
1123				$('body').trigger('ld_has_paginated');
1124
1125				initTooltips();
1126			},
1127		});
1128	});
1129
1130	if ($('#learndash_timer').length) {
1131		var timer_el = jQuery('#learndash_timer');
1132		var timer_seconds = timer_el.attr('data-timer-seconds');
1133		var timer_button_el = jQuery(timer_el.attr('data-button'));
1134
1135		var cookie_key = timer_el.attr('data-cookie-key');
1136
1137		if ('undefined' !== typeof cookie_key) {
1138			var cookie_name = 'learndash_timer_cookie_' + cookie_key;
1139		} else {
1140			var cookie_name = 'learndash_timer_cookie';
1141		}
1142
1143		cookie_timer_seconds = jQuery.cookie(cookie_name);
1144
1145		if ('undefined' !== typeof cookie_timer_seconds) {
1146			timer_seconds = parseInt(cookie_timer_seconds);
1147		}
1148
1149		if (0 == timer_seconds) {
1150			$(timer_el).hide();
1151		}
1152
1153		$(timer_button_el).on('learndash-time-finished', function () {
1154			$(timer_el).hide();
1155		});
1156	}
1157
1158	$(document).on('learndash_video_disable_assets', function (event, status) {
1159		if ('undefined' === typeof learndash_video_data) {
1160			return false;
1161		}
1162
1163		if ('BEFORE' == learndash_video_data.videos_shown) {
1164			if (true == status) {
1165				$('.ld-lesson-topic-list').hide();
1166				$('.ld-lesson-navigation')
1167					.find('#ld-nav-content-list-' + ldVars.postID)
1168					.addClass('user_has_no_access');
1169				$('.ld-quiz-list').hide();
1170			} else {
1171				$('.ld-lesson-topic-list').slideDown();
1172				$('.ld-quiz-list').slideDown();
1173				$('.ld-lesson-navigation')
1174					.find('#ld-nav-content-list-' + ldVars.postID)
1175					.removeClass('user_has_no_access');
1176			}
1177		}
1178	});
1179
1180	$('.learndash-wrapper').on(
1181		'click',
1182		'.wpProQuiz_questionListItem input[type="radio"]',
1183		function (e) {
1184			$(this)
1185				.parents('.wpProQuiz_questionList')
1186				.find('label')
1187				.removeClass('is-selected');
1188			$(this).parents('label').addClass('is-selected');
1189		}
1190	);
1191
1192	$('.learndash-wrapper').on(
1193		'click',
1194		'.wpProQuiz_questionListItem input[type="checkbox"]',
1195		function (e) {
1196			if (jQuery(e.currentTarget).is(':checked')) {
1197				$(this).parents('label').addClass('is-selected');
1198			} else {
1199				$(this).parents('label').removeClass('is-selected');
1200			}
1201		}
1202	);
1203
1204	function learndash_ld30_show_user_statistic(e) {
1205		e.preventDefault();
1206
1207		var refId = jQuery(this).data('ref-id');
1208		var quizId = jQuery(this).data('quiz-id');
1209		var userId = jQuery(this).data('user-id');
1210		var statistic_nonce = jQuery(this).data('statistic-nonce');
1211		var post_data = {
1212			action: 'wp_pro_quiz_admin_ajax_statistic_load_user',
1213			func: 'statisticLoadUser',
1214			data: {
1215				quizId,
1216				userId,
1217				refId,
1218				statistic_nonce,
1219				avg: 0,
1220			},
1221		};
1222
1223		jQuery('#wpProQuiz_user_overlay, #wpProQuiz_loadUserData').show();
1224		var content = jQuery('#wpProQuiz_user_content').hide();
1225
1226		//console.log('- learndash.js');
1227
1228		jQuery.ajax({
1229			type: 'POST',
1230			url: ldVars.ajaxurl,
1231			dataType: 'json',
1232			cache: false,
1233			data: post_data,
1234			error(jqXHR, textStatus, errorThrown) {},
1235			success(reply_data) {
1236				if ('undefined' !== typeof reply_data.html) {
1237					content.html(reply_data.html);
1238					jQuery('#wpProQuiz_user_content').show();
1239
1240					//console.log('trigger event change - learndash.js');
1241					jQuery('body').trigger(
1242						'learndash-statistics-contentchanged'
1243					);
1244
1245					jQuery('#wpProQuiz_loadUserData').hide();
1246
1247					content.find('.statistic_data').on('click', function () {
1248						jQuery(this).parents('tr').next().toggle('fast');
1249
1250						return false;
1251					});
1252				}
1253			},
1254		});
1255
1256		jQuery('#wpProQuiz_overlay_close').on('click', function () {
1257			jQuery('#wpProQuiz_user_overlay').hide();
1258		});
1259	}
1260
1261	function learndashSetMaxHeight(elm) {
1262		var totalHeight = 0;
1263
1264		elm.find('> *').each(function () {
1265			totalHeight += $(this).outerHeight();
1266		});
1267
1268		elm.attr('data-height', '' + (totalHeight + 50) + '');
1269
1270		elm.css({
1271			'max-height': totalHeight + 50,
1272		});
1273	}
1274
1275	/**
1276	 * Will scroll the position of the Focus Mode sidebar
1277	 * to the active step.
1278	 */
1279	function learndashFocusModeSidebarAutoScroll() {
1280		if (jQuery('.learndash-wrapper .ld-focus').length) {
1281			var sidebar_wrapper = jQuery(
1282				'.learndash-wrapper .ld-focus .ld-focus-sidebar-wrapper'
1283			);
1284
1285			var sidebar_current_topic = jQuery(
1286				'.learndash-wrapper .ld-focus .ld-focus-sidebar-wrapper .ld-is-current-item'
1287			);
1288			if (
1289				'undefined' !== typeof sidebar_current_topic &&
1290				sidebar_current_topic.length
1291			) {
1292				var sidebar_scrollTo = sidebar_current_topic;
1293			} else {
1294				var sidebar_current_lesson = jQuery(
1295					'.learndash-wrapper .ld-focus .ld-focus-sidebar-wrapper .ld-is-current-lesson'
1296				);
1297				if (
1298					'undefined' !== typeof sidebar_current_lesson &&
1299					sidebar_current_lesson.length
1300				) {
1301					var sidebar_scrollTo = sidebar_current_lesson;
1302				}
1303			}
1304
1305			if (
1306				'undefined' !== typeof sidebar_scrollTo &&
1307				sidebar_scrollTo.length
1308			) {
1309				var offset_top = 0;
1310				if (
1311					jQuery('.learndash-wrapper .ld-focus .ld-focus-header')
1312						.length
1313				) {
1314					var logo_height = jQuery(
1315						'.learndash-wrapper .ld-focus .ld-focus-header'
1316					).height();
1317					offset_top += logo_height;
1318				}
1319				if (
1320					jQuery(
1321						'.learndash-wrapper .ld-focus .ld-focus-sidebar .ld-course-navigation-heading'
1322					).length
1323				) {
1324					var heading_height = jQuery(
1325						'.learndash-wrapper .ld-focus .ld-focus-sidebar .ld-course-navigation-heading'
1326					).height();
1327					offset_top += heading_height;
1328				}
1329				if (
1330					jQuery(
1331						'.learndash-wrapper .ld-focus .ld-focus-sidebar .ld-focus-sidebar-wrapper'
1332					).length
1333				) {
1334					var container_height = jQuery(
1335						'.learndash-wrapper .ld-focus .ld-focus-sidebar .ld-focus-sidebar-wrapper'
1336					).height();
1337					offset_top += container_height;
1338				}
1339
1340				var current_item_height = jQuery(sidebar_scrollTo).height();
1341				offset_top -= current_item_height;
1342
1343				sidebar_wrapper.animate(
1344					{
1345						scrollTop: sidebar_scrollTo.offset().top - offset_top,
1346					},
1347					1000
1348				);
1349			}
1350		}
1351	}
1352
1353	// Coupon processing.
1354
1355	function update_payment_forms(data) {
1356		$('#total-row').attr('data-total', data.total.value);
1357
1358		// Update PayPal form amount.
1359		$('form[name="buynow"] input[name="amount"]').val(data.total.value);
1360
1361		// Update Stripe form amount.
1362		$('form.learndash-stripe-checkout input[name="stripe_price"]').val(
1363			data.total.stripe_value
1364		);
1365
1366		// Remove Stripe Connect session to respect the new amount.
1367		const stripe_course_id = $(
1368			'.learndash-stripe-checkout input[name="stripe_course_id"]'
1369		).val();
1370
1371		if (stripe_course_id) {
1372			LD_Cookies.remove('ld_stripe_session_id_' + stripe_course_id); // Stripe Plugin (Checkout).
1373			LD_Cookies.remove(
1374				'ld_stripe_connect_session_id_' + stripe_course_id
1375			); // Stripe Connect in core.
1376		}
1377
1378		// Re-init Stripe Plugin (Legacy) to respect the new amount.
1379		if (typeof ld_init_stripe_legacy === 'function') {
1380			ld_init_stripe_legacy();
1381		}
1382	}
1383
1384	$('.btn-join').on('click', function (e) {
1385		if ($(this).hasClass('btn-disabled')) {
1386			e.preventDefault();
1387			return false;
1388		}
1389
1390		const total = parseFloat($('#total-row').attr('data-total'));
1391
1392		if (0 === total) {
1393			$.ajax({
1394				type: 'POST',
1395				url: ldVars.ajaxurl,
1396				dataType: 'json',
1397				cache: false,
1398				data: {
1399					action: 'learndash_enroll_with_zero_price',
1400					nonce: $('#apply-coupon-form').data('nonce'),
1401					post_id: $('#apply-coupon-form').data('post-id'),
1402				},
1403				success(response) {
1404					if (response.success) {
1405						window.location.replace(response.data.redirect_url);
1406					} else {
1407						alert(response.data.message);
1408					}
1409				},
1410			});
1411
1412			e.preventDefault();
1413			return false;
1414		}
1415	});
1416
1417	$('#apply-coupon-form').on('submit', function (e) {
1418		e.preventDefault();
1419		const $el = $(this);
1420		const $wrapper = $el.closest('.ld-registration-order__items');
1421
1422		$.ajax({
1423			type: 'POST',
1424			url: ldVars.ajaxurl,
1425			dataType: 'json',
1426			cache: false,
1427			data: {
1428				action: 'learndash_apply_coupon',
1429				nonce: $(this).data('nonce'),
1430				coupon_code: $(this).find('#coupon-field').val(),
1431				post_id: $(this).data('post-id'),
1432			},
1433			success(response) {
1434				const isModernRegistration = $('.ld-form__field-coupon_field').length;
1435
1436				if ( isModernRegistration ) {
1437					$('#coupon-alerts .coupon-alert').hide();
1438
1439					const $alert = $('#coupon-alerts').find(
1440						response.success
1441							? '.coupon-alert-success'
1442							: '.coupon-alert-warning'
1443					);
1444
1445					if (response.success) {
1446						$wrapper
1447							.find('.ld-coupon__label-text')
1448							.html(response.data.coupon_code); // Set coupon code in totals.
1449
1450						$wrapper
1451							.find('.ld-coupon__value')
1452							.html('(' + response.data.discount + ')'); // Set discount value in totals.
1453
1454						$wrapper
1455							.find('.ld-registration-order__item-price-value')
1456							.html(response.data.total.formatted); // Update course/group price.
1457
1458						$wrapper.find('.ld-registration-order__total-price').html(
1459							response.data.total.formatted
1460						); // Update Total.
1461
1462						$wrapper.addClass('ld-registration-order__items--with-coupon');
1463
1464						update_payment_forms(response.data);
1465					}
1466
1467					$alert.find('.ld-alert-messages').html(response.data.message);
1468					$alert.fadeIn();
1469				} else {
1470					$('#coupon-alerts .coupon-alert').hide();
1471
1472					const $alert = $('#coupon-alerts').find(
1473						response.success
1474							? '.coupon-alert-success'
1475							: '.coupon-alert-warning'
1476					);
1477
1478					const $coupon_row = $('#coupon-row');
1479
1480					if (response.success) {
1481						$coupon_row
1482							.find('.purchase-label > span')
1483							.html(response.data.coupon_code); // Set coupon code in totals.
1484						$coupon_row
1485							.find('.purchase-value span')
1486							.html(response.data.discount); // Set discount value in totals.
1487						$coupon_row.css('display', 'flex').hide().fadeIn(); // Show a coupon row in totals.
1488						$('#total-row .purchase-value').html(
1489							response.data.total.formatted
1490						); // Update Total.
1491						$('#totals').show();
1492
1493						update_payment_forms(response.data);
1494					}
1495
1496					$alert.find('.ld-alert-messages').html(response.data.message);
1497					$alert.fadeIn();
1498				}
1499			},
1500		});
1501	});
1502
1503	$('#remove-coupon-form').on('submit', function (e) {
1504		e.preventDefault();
1505		const $el = $(this);
1506		const $wrapper = $el.closest('.ld-registration-order__items');
1507
1508		$.ajax({
1509			type: 'POST',
1510			url: ldVars.ajaxurl,
1511			dataType: 'json',
1512			cache: false,
1513			data: {
1514				action: 'learndash_remove_coupon',
1515				nonce: $(this).data('nonce'),
1516				post_id: $(this).data('post-id'),
1517			},
1518			success(response) {
1519				const isModernRegistration = $('.ld-form__field-coupon_field').length;
1520
1521				if ( isModernRegistration ) {
1522					$('#coupon-alerts .coupon-alert').hide();
1523
1524					const $alert = $('#coupon-alerts').find(
1525						response.success
1526							? '.coupon-alert-success'
1527							: '.coupon-alert-warning'
1528					);
1529
1530					if (response.success) {
1531						$wrapper.removeClass('ld-registration-order__items--with-coupon');
1532						$wrapper.find('.ld-form__field-coupon_field').val(''); // Set coupon field empty.
1533						$wrapper
1534							.find('.ld-registration-order__item-price-value')
1535							.html(response.data.total.formatted); // Update course/group price.
1536						$wrapper.find('.ld-registration-order__total-price').html(
1537							response.data.total.formatted
1538						); // Update Total.
1539
1540						update_payment_forms(response.data);
1541					}
1542
1543					$alert.find('.ld-alert-messages').html(response.data.message);
1544					$alert.fadeIn();
1545				} else {
1546					$('#coupon-alerts .coupon-alert').hide();
1547
1548					const $alert = $('#coupon-alerts').find(
1549						response.success
1550							? '.coupon-alert-success'
1551							: '.coupon-alert-warning'
1552					);
1553
1554					if (response.success) {
1555						$('#coupon-row').hide(); // Hide a coupon row in totals.
1556						$('#coupon-field').val(''); // Set coupon field empty.
1557						$('#price-row .purchase-value').html(
1558							response.data.total.formatted
1559						); // Update Price.
1560						$('#subtotal-row .purchase-value').html(
1561							response.data.total.formatted
1562						); // Update Subtotal.
1563						$('#total-row .purchase-value').html(
1564							response.data.total.formatted
1565						); // Update Total.
1566						$('#totals').hide();
1567
1568						update_payment_forms(response.data);
1569					}
1570
1571					$alert.find('.ld-alert-messages').html(response.data.message);
1572					$alert.fadeIn();
1573				}
1574			},
1575		});
1576	});
1577});
1578
1579function ldGetUrlVars() {
1580	var vars = {};
1581	var parts = window.location.href.replace(
1582		/[?&]+([^=&]+)=([^&]*)/gi,
1583		function (m, key, value) {
1584			vars[key] = value;
1585		}
1586	);
1587
1588	return vars;
1589}

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.