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 ldToggleExpandableElement(button, true); 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 ldToggleExpandableElement($(this)); 292 293 positionTooltips(); 294 }); 295 296 /** 297 * Initialize collapsed elements to have [hidden="hidden"]. 298 * This should only happen via JavaScript, so we cannot pre-load this on the server. 299 * 300 * @see https://designsystem.digital.gov/components/accordion/ 301 */ 302 $('.ld-expand-button, .ld-search-prompt').each(function ( 303 index, 304 buttonElement 305 ) { 306 if ($(buttonElement).attr('aria-expanded') === 'true') { 307 return; 308 } 309 310 ldToggleExpandableElement($(buttonElement), false); 311 }); 312 313 $('body').on('click', '.ld-search-prompt', function (e) { 314 e.preventDefault(); 315 316 $('#course_name_field').focus(); 317 318 ldToggleExpandableElement($(this)); 319 320 const $controls = $('#' + $(this).attr('aria-controls')); 321 322 if ($controls.find('.ld-closer').length > 0) { 323 $controls 324 .find('.ld-closer') 325 .attr('aria-expanded', $(this).attr('aria-expanded')); 326 } 327 }); 328 329 /** 330 * Handles expanding and collapsing elements on button click. 331 * 332 * @since 4.20.2 333 * 334 * @param {jQuery} $button jQuery Element for the button that was clicked. 335 * @param {boolean} expand Whether to expand the associated element or not. Defaults to a value based on the button's aria-expanded attribute. 336 * 337 * @return {void} 338 */ 339 function ldToggleExpandableElement($button, expand) { 340 if ('undefined' === typeof expand) { 341 // Checking !== true to handle undefined and false. 342 expand = $button.attr('aria-expanded') !== 'true'; 343 } 344 345 const containerID = $button.attr('aria-controls'); 346 347 if ( 348 typeof containerID !== 'undefined' && 349 containerID.indexOf(' ') > -1 && 350 !$button.data('ld-expanding-all') 351 ) { 352 // We're toggling multiple elements at once via an "Expand All"-type button. 353 354 containerID.split(' ').forEach(function (id) { 355 const $element = $('[aria-controls="' + id + '"]'); 356 357 ldToggleExpandableElement($element, expand); 358 }); 359 360 // Temporarily set the "ld-expanding-all" data to allow us to toggle the state of this specific button. 361 362 $button.data('ld-expanding-all', true); 363 364 ldToggleExpandableElement($button, expand); 365 366 $button.data('ld-expanding-all', false); 367 } else { 368 // Toggle a specific button. 369 370 // Account for edge cases where an Expand All button controls only one expandable area. 371 $button = $('[aria-controls="' + containerID + '"]'); 372 373 const $container = $('#' + containerID); 374 375 if (expand && $container.length > 0) { 376 // Unhide right away. 377 $container.attr('hidden', false); 378 } 379 380 $button.each(function (index, element) { 381 /** 382 * Pull the initial text from a cached data attribute, 383 * that way as the button text changes we always know what it was initially. 384 */ 385 const dataInitialText = 386 $(element).data('ld-initial-text') || 387 $(element).find('.ld-text').html(); 388 389 $(element).data('ld-initial-text', dataInitialText); 390 391 const dataExpandText = 392 $(element).data('ld-expand-text') || dataInitialText; 393 const dataCollapseText = 394 $(element).data('ld-collapse-text') || dataInitialText; 395 396 $(element) 397 .attr('aria-expanded', expand) 398 .toggleClass('ld-expanded', expand); 399 400 if (expand && dataCollapseText) { 401 $(element).find('.ld-text').html(dataCollapseText); 402 } else if (!expand && dataExpandText) { 403 $(element).find('.ld-text').html(dataExpandText); 404 } 405 }); 406 407 if ($container.length <= 0) { 408 /** 409 * Expand All buttons with more than one controlled element won't have a valid Container, 410 * so we shouldn't proceed. 411 */ 412 return; 413 } 414 415 let totalHeight = 0; 416 $container.find('> *').each(function () { 417 totalHeight += $(this).outerHeight(); 418 }); 419 420 // Writing to the attribute to make debugging easier. 421 $container.attr('data-height', totalHeight + 50); 422 423 $container.css({ 424 'max-height': expand ? $container.data('height') : 0, 425 }); 426 427 $container.toggleClass('ld-expanded', expand); 428 429 if (!expand) { 430 const waitForCollapsed = setInterval(function () { 431 if ($container.outerHeight() === 0) { 432 clearInterval(waitForCollapsed); 433 $container.attr('hidden', true); 434 } 435 }); 436 } 437 } 438 439 positionTooltips(); 440 } 441 442 /** 443 * Initialize registration link in the classic registration page. 444 * 445 * @since 4.16.0 446 * 447 * @return {void} 448 */ 449 function ldRegistrationLinkInit() { 450 const $loginLink = $('.registration-login-link'); 451 452 if ($loginLink.length === 0) { 453 return; 454 } 455 456 if ('' !== $loginLink.attr('href')) { 457 return; 458 } 459 460 $loginLink.on('click', function (e) { 461 e.preventDefault(); 462 $('#learndash_registerform, .registration-login').hide(); 463 $( 464 '.registration-login-form, .show-register-form, .show-password-reset-link' 465 ).show(); 466 }); 467 468 $('.show-register-form').on('click', function (e) { 469 e.preventDefault(); 470 $( 471 '.registration-login-form, .show-register-form, .show-password-reset-link' 472 ).hide(); 473 $('#learndash_registerform, .registration-login').show(); 474 }); 475 } 476 477 /** 478 * Initialize registration link in the modern registration page. 479 * 480 * @since 4.16.0 481 * 482 * @return {void} 483 */ 484 function ldRegistrationLinkInitModern() { 485 const $loginLink = $('.ld-registration__login-link'); 486 487 if ($loginLink.length === 0) { 488 return; 489 } 490 491 if ('' !== $loginLink.attr('href')) { 492 return; 493 } 494 495 $(document).on('click', '.ld-registration__login-link', function (e) { 496 e.preventDefault(); 497 let $wrapper = $(this).closest('.ld-registration__wrapper'); 498 $wrapper.addClass('ld-registration__wrapper--login'); 499 $wrapper.removeClass('ld-registration__wrapper--register'); 500 }); 501 502 $(document).on( 503 'click', 504 '.ld-registration__register-link', 505 function (e) { 506 e.preventDefault(); 507 let $wrapper = $(this).closest('.ld-registration__wrapper'); 508 $wrapper.removeClass('ld-registration__wrapper--login'); 509 $wrapper.addClass('ld-registration__wrapper--register'); 510 } 511 ); 512 } 513 514 $('body').on('click', '.ld-closer', function (e) { 515 ldToggleExpandableElement($('.ld-search-prompt'), false); 516 $(this).attr('aria-expanded', false); 517 }); 518 519 $('body').on('touch click', '.ld-tabs-navigation .ld-tab', function () { 520 const $tabContent = $('#' + $(this).attr('aria-controls')); 521 if (!$tabContent.length) { 522 return; 523 } 524 525 // Set other Tabs as inactive. 526 $('.ld-tabs-navigation .ld-tab.ld-active') 527 .removeClass('ld-active') 528 .attr('aria-selected', 'false') 529 .attr('tabindex', '-1'); 530 531 // Set current Tab as active. 532 $(this) 533 .addClass('ld-active') 534 .attr('aria-selected', 'true') 535 .removeAttr('tabindex'); 536 537 // Make other Tab Content panels invisible. 538 $('.ld-tabs-content .ld-tab-content.ld-visible').removeClass( 539 'ld-visible' 540 ); 541 542 $tabContent.addClass('ld-visible'); 543 544 positionTooltips(); 545 }); 546 547 $('body').on('keydown', '.ld-tabs-navigation .ld-tab', function (event) { 548 // If the key is not a Left/Right arrow key, Home, or End, do nothing. 549 if ( 550 ['ArrowLeft', 'ArrowRight', 'Home', 'End'].indexOf(event.key) === -1 551 ) { 552 return; 553 } 554 555 const target = event.currentTarget; 556 const $firstTab = $(target) 557 .closest('[role="tablist"]') 558 .find('[role="tab"]') 559 .first(); 560 const $lastTab = $(target) 561 .closest('[role="tablist"]') 562 .find('[role="tab"]') 563 .last(); 564 565 event.stopPropagation(); 566 event.preventDefault(); 567 568 switch (event.key) { 569 case 'ArrowLeft': 570 if (target === $firstTab[0]) { 571 $lastTab.focus(); 572 } else { 573 $(this).prev().focus(); 574 } 575 break; 576 case 'ArrowRight': 577 if (target === $lastTab[0]) { 578 $firstTab.focus(); 579 } else { 580 $(target).next().focus(); 581 } 582 break; 583 case 'Home': 584 $firstTab.focus(); 585 break; 586 case 'End': 587 $lastTab.focus(); 588 break; 589 default: 590 break; 591 } 592 }); 593 594 var $tooltips = $('*[data-ld-tooltip]'); 595 596 initTooltips(); 597 598 function initTooltips() { 599 // Clear out old tooltips 600 601 if ($('#learndash-tooltips').length) { 602 $('#learndash-tooltips').remove(); 603 $tooltips = $('*[data-ld-tooltip]'); 604 } 605 606 if ($tooltips.length) { 607 $('body').prepend('<div id="learndash-tooltips"></div>'); 608 var $ctr = 1; 609 $tooltips.each(function () { 610 var anchor = $(this); 611 if (anchor.hasClass('ld-item-list-item')) { 612 anchor = anchor.find('.ld-item-title'); 613 } 614 615 /** 616 * Prevent calendar icon from being clickable. 617 */ 618 if ( 619 'undefined' !== typeof anchor && 620 $(anchor).hasClass('ld-status-waiting') 621 ) { 622 $(anchor).on('click', function (e) { 623 e.preventDefault(); 624 return false;
625 }); 626 627 // Also prevent parent <a> from being clickable. 628 var parent_anchor = $(anchor).parents('a'); 629 if ('undefined' !== typeof parent_anchor) { 630 $(parent_anchor).on('click', function (e) { 631 e.preventDefault(); 632 return false; 633 }); 634 } 635 } 636 637 var elementOffsets = { 638 top: anchor.offset().top, 639 left: anchor.offset().left + anchor.outerWidth() / 2, 640 }; 641 var $content = $(this).attr('data-ld-tooltip'); 642 var $rel_id = Math.floor(Math.random() * 99999); 643 644 //var $tooltip = '<span id="ld-tooltip-' + $rel_id + '" class="ld-tooltip" style="top:' + elementOffsets.top + 'px; left:' + elementOffsets.left + 'px;">' + $content + '</span>'; 645 var $tooltip = 646 '<span id="ld-tooltip-' + 647 $rel_id + 648 '" class="ld-tooltip">' + 649 $content + 650 '</span>'; 651 $(this).attr('data-ld-tooltip-id', $rel_id); 652 $('#learndash-tooltips').append($tooltip); 653 $ctr++; 654 var $tooltip = $('#ld-tooltip-' + $rel_id); 655 $(this) 656 .on('mouseenter', function () { 657 $tooltip.addClass('ld-visible'); 658 }) 659 .on('mouseleave', function () { 660 $tooltip.removeClass('ld-visible'); 661 }); 662 }); 663 664 $(window).on('resize', function () { 665 // Reposition tooltips after resizing 666 positionTooltips(); 667 }); 668 669 $(window) 670 .add('.ld-focus-sidebar-wrapper') 671 .on('scroll', function () { 672 // Hide tooltips so they don't persist while scrolling 673 $('.ld-visible.ld-tooltip').removeClass('ld-visible'); 674 675 // Reposition tooltips after scrolling 676 positionTooltips(); 677 }); 678 679 positionTooltips(); 680 } 681 } 682 683 function initLoginModal() { 684 var modal_wrapper = $('.learndash-wrapper-login-modal'); 685 if ('undefined' !== typeof modal_wrapper && modal_wrapper.length) { 686 // Move the model to be first element of the body. See LEARNDASH-3503 687 $(modal_wrapper).prependTo('body'); 688 } 689 } 690 691 function openLoginModal() { 692 var modal_wrapper = $('.learndash-wrapper-login-modal'); 693 if ('undefined' !== typeof modal_wrapper && modal_wrapper.length) { 694 $(modal_wrapper).addClass('ld-modal-open'); 695 $(modal_wrapper).removeClass('ld-modal-closed'); 696 697 // Removed LEARNDASH-3867 #4 698 $('html, body').animate( 699 { 700 scrollTop: $('.ld-modal', modal_wrapper).offset().top, 701 }, 702 50 703 ); 704 } 705 } 706 707 function closeLoginModal() { 708 var modal_wrapper = $('.learndash-wrapper-login-modal'); 709 if ('undefined' !== typeof modal_wrapper && modal_wrapper.length) { 710 $(modal_wrapper).removeClass('ld-modal-open'); 711 $(modal_wrapper).addClass('ld-modal-closed'); 712 } 713 } 714 715 function positionTooltips() { 716 if ('undefined' !== typeof $tooltips) { 717 setTimeout(function () { 718 $tooltips.each(function () { 719 var anchor = $(this); 720 var $rel_id = anchor.attr('data-ld-tooltip-id'); 721 $tooltip = $('#ld-tooltip-' + $rel_id); 722 723 if (anchor.hasClass('ld-item-list-item')) { 724 //anchor = anchor.find('.ld-item-title'); 725 anchor = anchor.find('.ld-status-icon'); 726 } 727 728 var parent_focus = 729 jQuery(anchor).parents('.ld-focus-sidebar'); 730 var left_post = 731 anchor.offset().left + (anchor.outerWidth() + 10); 732 if (parent_focus.length) { 733 left_post = 734 anchor.offset().left + (anchor.outerWidth() - 18); 735 } 736 737 // Get the main content height 738 var focusModeMainContentHeight = 739 $('.ld-focus-main').height(); 740 741 // Current tooltip height 742 var focusModeCurrentTooltipHeight = 743 anchor.offset().top + -3; 744 745 // Position tooltip depending on focus mode or not 746 if (!focusModeMainContentHeight) { 747 var anchorTop = anchor.offset().top + -3; 748 var anchorLeft = anchor.offset().left; 749 } else { 750 anchorTop = 751 focusModeCurrentTooltipHeight < 752 focusModeMainContentHeight 753 ? focusModeCurrentTooltipHeight 754 : focusModeMainContentHeight; 755 anchorLeft = left_post; 756 } 757 758 $tooltip 759 .css({ 760 top: anchorTop, 761 762 //'left' : anchor.offset().left + (anchor.outerWidth() / 2), 763 //'left': left_post, //anchor.offset().left + (anchor.outerWidth() +10), 764 left: anchorLeft, //anchor.offset().left + (anchor.outerWidth() +10), 765 'margin-left': 0, 766 'margin-right': 0, 767 }) 768 .removeClass('ld-shifted-left ld-shifted-right'); 769 if ($tooltip.offset().left <= 0) { 770 $tooltip 771 .css({ 772 'margin-left': Math.abs($tooltip.offset().left), 773 }) 774 .addClass('ld-shifted-left'); 775 } 776 var $tooltipRight = 777 $(window).width() - 778 ($tooltip.offset().left + $tooltip.outerWidth()); 779 if (0 >= $tooltipRight && 360 < $(window).width()) { 780 $tooltip 781 .css({ 'margin-right': Math.abs($tooltipRight) }) 782 .addClass('ld-shifted-right'); 783 } 784 }); 785 }, 500); 786 } 787 } 788 789 $('body').on('click', '#ld-profile .ld-reset-button', function (e) { 790 e.preventDefault(); 791 792 $('#ld-profile #course_name_field').val(''); 793 794 var searchVars = { 795 shortcode_instance: $('#ld-profile').data('shortcode_instance'), 796 }; 797 798 searchVars['ld-profile-search'] = $(this) 799 .parents('.ld-item-search-wrapper') 800 .find('#course_name_field') 801 .val(); 802 searchVars['ld-profile-search-nonce'] = $(this) 803 .parents('.ld-item-search-wrapper') 804 .find('form.ld-item-search-fields') 805 .data('nonce'); 806 807 $('#ld-profile #ld-main-course-list').addClass('ld-loading'); 808 809 $.ajax({ 810 type: 'GET', 811 url: ldVars.ajaxurl + '?action=ld30_ajax_profile_search', 812 data: searchVars, 813 success(response) { 814 if ('undefined' !== typeof response.data.markup) { 815 $('#ld-profile').html(response.data.markup); 816 ldToggleExpandableElement( 817 '#ld-profile .ld-search-prompt', 818 true 819 ); 820 } 821 }, 822 }); 823 }); 824 825 $('body').on('submit', '.ld-item-search-fields', function (e) { 826 e.preventDefault(); 827 828 var searchVars = { 829 shortcode_instance: $('#ld-profile').data('shortcode_instance'), 830 }; 831 832 searchVars['ld-profile-search'] = $(this) 833 .parents('.ld-item-search-wrapper') 834 .find('#course_name_field') 835 .val(); 836 searchVars['ld-profile-search-nonce'] = $(this) 837 .parents('.ld-item-search-wrapper') 838 .find('form.ld-item-search-fields') 839 .data('nonce'); 840 841 $('#ld-profile #ld-main-course-list').addClass('ld-loading'); 842 843 $.ajax({ 844 type: 'GET', 845 url: ldVars.ajaxurl + '?action=ld30_ajax_profile_search', 846 data: searchVars, 847 success(response) { 848 if ('undefined' !== typeof response.data.markup) { 849 $('#ld-profile').html(response.data.markup); 850 ldToggleExpandableElement( 851 '#ld-profile .ld-search-prompt', 852 true 853 ); 854 } 855 }, 856 }); 857 }); 858 859 $('body').on('click', '.ld-pagination a', function (e) { 860 e.preventDefault(); 861 862 var linkVars = {}; 863 var parentVars = {}; 864 865 $(this) 866 .attr('href') 867 .replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) { 868 linkVars[key] = value; 869 }); 870 871 linkVars.pager_nonce = $(this) 872 .parents('.ld-pagination') 873 .data('pager-nonce'); 874 875 linkVars.pager_results = $(this) 876 .parents('.ld-pagination') 877 .data('pager-results'); 878 879 linkVars.context = $(this).data('context'); 880 console.log('linkVars[%o]', linkVars); 881 882 parentVars.currentTarget = e.currentTarget; 883 884 if ('profile' != linkVars.context) { 885 linkVars.lesson_id = $(this).data('lesson_id'); 886 linkVars.course_id = $(this).data('course_id'); 887 888 if ($('.ld-course-nav-' + linkVars.course_id).length) { 889 linkVars.widget_instance = $( 890 '.ld-course-nav-' + linkVars.course_id 891 ).data('widget_instance'); 892 } 893 } 894 895 if ('course_topics' == linkVars.context) { 896 $('#ld-topic-list-' + linkVars.lesson_id).addClass('ld-loading'); 897 $('#ld-nav-content-list-' + linkVars.lesson_id).addClass( 898 'ld-loading' 899 ); 900 } 901 902 if ('course_content_shortcode' == linkVars.context) { 903 parentVars.parent_container = $(parentVars.currentTarget).closest( 904 '.ld-course-content-' + linkVars.course_id 905 ); 906 if ( 907 'undefined' !== typeof parentVars.parent_container && 908 parentVars.parent_container.length 909 ) { 910 $(parentVars.parent_container).addClass('ld-loading'); 911 linkVars.shortcode_instance = $( 912 parentVars.parent_container 913 ).data('shortcode_instance'); 914 } else { 915 $('.ld-course-content-' + linkVars.course_id).addClass( 916 'ld-loading' 917 ); 918 linkVars.shortcode_instance = $( 919 '.ld-course-content-' + linkVars.course_id 920 ).data('shortcode_instance'); 921 } 922 } else if ('course_lessons' == linkVars.context) { 923 var parent_container; 924 925 // Check if we are within the Course Navigation Widget. 926 if ( 927 'undefined' === typeof parentVars.parent_container || 928 !parentVars.parent_container.length 929 ) { 930 parent_container = $(parentVars.currentTarget).parents( 931 '.ld-lesson-navigation' 932 ); 933 if ( 934 'undefined' !== typeof parent_container && 935 parent_container.length 936 ) { 937 parentVars.context_sub = 'course_navigation_widget'; 938 parentVars.parent_container = $( 939 parentVars.currentTarget 940 ).parents('#ld-lesson-list-' + linkVars.course_id); 941 } 942 } 943 944 // Check if we are within the Focus Mode Sidebar. 945 if ( 946 'undefined' === typeof parentVars.parent_container || 947 !parentVars.parent_container.length 948 ) { 949 parent_container = $(parentVars.currentTarget).parents( 950 '.ld-focus-sidebar-wrapper' 951 ); 952 if ( 953 'undefined' !== typeof parent_container && 954 parent_container.length 955 ) { 956 parentVars.context_sub = 'focus_mode_sidebar'; 957 parentVars.parent_container = $( 958 parentVars.currentTarget 959 ).parents('#ld-lesson-list-' + linkVars.course_id); 960 } 961 } 962 963 if ( 964 'undefined' === typeof parentVars.parent_container || 965 !parentVars.parent_container.length 966 ) { 967 parentVars.parent_container = $( 968 parentVars.currentTarget 969 ).closest( 970 '#ld-item-list-' + linkVars.course_id, 971 '#ld-lesson-list-' + linkVars.course_id 972 ); 973 } 974 if ( 975 'undefined' !== typeof parentVars.parent_container && 976 parentVars.parent_container.length 977 ) { 978 $(parentVars.parent_container).addClass('ld-loading'); 979 } else { 980 // Fallback solution. 981 $('#ld-item-list-' + linkVars.course_id).addClass('ld-loading'); 982 $('#ld-lesson-list-' + linkVars.course_id).addClass( 983 'ld-loading' 984 ); 985 } 986 } 987 988 if ('profile' == linkVars.context) { 989 $('#ld-profile #ld-main-course-list').addClass('ld-loading'); 990 linkVars.shortcode_instance = 991 $('#ld-profile').data('shortcode_instance'); 992 } 993 994 if ('profile_quizzes' == linkVars.context) { 995 $( 996 '#ld-course-list-item-' + 997 linkVars.pager_results.quiz_course_id + 998 ' .ld-item-contents' 999 ).addClass('ld-loading'); 1000 } 1001 1002 if ('course_info_courses' == linkVars.context) { 1003 $('.ld-user-status').addClass('ld-loading'); 1004 linkVars.shortcode_instance = 1005 $('.ld-user-status').data('shortcode-atts'); 1006 } 1007 1008 if ('group_courses' == linkVars.context) { 1009 linkVars.group_id = $(this).data('group_id'); 1010 if ('undefined' !== typeof linkVars.group_id) { 1011 parent_container = $(parentVars.currentTarget).parents( 1012 '.ld-group-courses-' + linkVars.group_id 1013 ); 1014 if ( 1015 'undefined' !== typeof parent_container && 1016 parent_container.length 1017 ) {
1018 $(parent_container).addClass('ld-loading'); 1019 parentVars.parent_container = parent_container; 1020 } 1021 } 1022 } 1023 1024 $.ajax({ 1025 type: 'GET', 1026 url: ldVars.ajaxurl + '?action=ld30_ajax_pager', 1027 data: linkVars, 1028 success(response) { 1029 // If we have a course listing, update 1030 1031 if ('course_topics' == linkVars.context) { 1032 if ($('#ld-topic-list-' + linkVars.lesson_id).length) { 1033 if ('undefined' !== typeof response.data.topics) { 1034 $('#ld-topic-list-' + linkVars.lesson_id).html( 1035 response.data.topics 1036 ); 1037 } 1038 1039 if ('undefined' !== typeof response.data.pager) { 1040 $('#ld-expand-' + linkVars.lesson_id) 1041 .find('.ld-table-list-footer') 1042 .html(response.data.pager); 1043 } 1044 1045 learndashSetMaxHeight( 1046 $('.ld-lesson-item-' + linkVars.lesson_id).find( 1047 '.ld-item-list-item-expanded' 1048 ) 1049 ); 1050 1051 $('#ld-topic-list-' + linkVars.lesson_id).removeClass( 1052 'ld-loading' 1053 ); 1054 } 1055 1056 if ( 1057 $('#ld-nav-content-list-' + linkVars.lesson_id).length 1058 ) { 1059 if ('undefined' !== typeof response.data.nav_topics) { 1060 $('#ld-nav-content-list-' + linkVars.lesson_id) 1061 .find('.ld-table-list-items') 1062 .html(response.data.topics); 1063 } 1064 1065 if ('undefined' !== typeof response.data.pager) { 1066 $('#ld-nav-content-list-' + linkVars.lesson_id) 1067 .find('.ld-table-list-footer') 1068 .html(response.data.pager); 1069 } 1070 1071 $( 1072 '#ld-nav-content-list-' + linkVars.lesson_id 1073 ).removeClass('ld-loading'); 1074 } 1075 } 1076 1077 if ('course_content_shortcode' == linkVars.context) { 1078 if ('undefined' !== typeof response.data.markup) { 1079 if ( 1080 'undefined' !== 1081 typeof parentVars.parent_container && 1082 parentVars.parent_container.length 1083 ) { 1084 $(parentVars.parent_container).replaceWith( 1085 response.data.markup 1086 ); 1087 } else { 1088 $( 1089 '#learndash_post_' + linkVars.course_id 1090 ).replaceWith(response.data.markup); 1091 } 1092 } 1093 } else if ('course_lessons' == linkVars.context) { 1094 if ( 1095 'undefined' !== typeof parentVars.parent_container && 1096 parentVars.parent_container.length 1097 ) { 1098 if ( 1099 'course_navigation_widget' == parentVars.context_sub 1100 ) { 1101 if ( 1102 'undefined' !== typeof response.data.nav_lessons 1103 ) { 1104 $(parentVars.parent_container) 1105 .html(response.data.nav_lessons) 1106 .removeClass('ld-loading'); 1107 } 1108 } else if ( 1109 'focus_mode_sidebar' == parentVars.context_sub 1110 ) { 1111 if ( 1112 'undefined' !== typeof response.data.nav_lessons 1113 ) { 1114 $(parentVars.parent_container) 1115 .html(response.data.nav_lessons) 1116 .removeClass('ld-loading'); 1117 } 1118 } else if ( 1119 'undefined' !== typeof response.data.lessons 1120 ) { 1121 $(parentVars.parent_container) 1122 .html(response.data.lessons) 1123 .removeClass('ld-loading'); 1124 } 1125 } else { 1126 if ($('#ld-item-list-' + linkVars.course_id).length) { 1127 if ('undefined' !== typeof response.data.lessons) { 1128 $('#ld-item-list-' + linkVars.course_id) 1129 .html(response.data.lessons) 1130 .removeClass('ld-loading'); 1131 } 1132 } 1133 1134 if ($('#ld-lesson-list-' + linkVars.course_id).length) { 1135 if ( 1136 'undefined' !== typeof response.data.nav_lessons 1137 ) { 1138 $('#ld-lesson-list-' + linkVars.course_id) 1139 .html(response.data.nav_lessons) 1140 .removeClass('ld-loading'); 1141 } 1142 } 1143 } 1144 } 1145 1146 if ('group_courses' == linkVars.context) { 1147 if ( 1148 'undefined' !== typeof parentVars.parent_container && 1149 parentVars.parent_container.length 1150 ) { 1151 if ('undefined' !== typeof response.data.markup) { 1152 $(parentVars.parent_container) 1153 .html(response.data.markup) 1154 .removeClass('ld-loading'); 1155 } 1156 } 1157 } 1158 1159 if ('profile' == linkVars.context) { 1160 if ('undefined' !== typeof response.data.markup) { 1161 $('#ld-profile').html(response.data.markup); 1162 } 1163 } 1164 1165 if ('profile_quizzes' == linkVars.context) { 1166 if ('undefined' !== typeof response.data.markup) { 1167 $( 1168 '#ld-course-list-item-' + 1169 linkVars.pager_results.quiz_course_id + 1170 ' .ld-item-list-item-expanded .ld-item-contents' 1171 ).replaceWith(response.data.markup); 1172 $( 1173 '#ld-course-list-item-' + 1174 linkVars.pager_results.quiz_course_id 1175 ) 1176 .get(0) 1177 .scrollIntoView({ behavior: 'smooth' }); 1178 } 1179 } 1180
1181 if ('course_info_courses' == linkVars.context) { 1182 if ('undefined' !== typeof response.data.markup) { 1183 $('.ld-user-status').replaceWith(response.data.markup); 1184 } 1185 } 1186 1187 $('body').trigger('ld_has_paginated'); 1188 1189 initTooltips(); 1190 }, 1191 }); 1192 }); 1193 1194 if ($('#learndash_timer').length) { 1195 var timer_el = jQuery('#learndash_timer'); 1196 var timer_seconds = timer_el.attr('data-timer-seconds'); 1197 var timer_button_el = jQuery(timer_el.attr('data-button')); 1198 1199 var cookie_key = timer_el.attr('data-cookie-key'); 1200 1201 if ('undefined' !== typeof cookie_key) { 1202 var cookie_name = 'learndash_timer_cookie_' + cookie_key; 1203 } else { 1204 var cookie_name = 'learndash_timer_cookie'; 1205 } 1206 1207 cookie_timer_seconds = jQuery.cookie(cookie_name); 1208 1209 if ('undefined' !== typeof cookie_timer_seconds) { 1210 timer_seconds = parseInt(cookie_timer_seconds); 1211 } 1212 1213 if (0 == timer_seconds) { 1214 $(timer_el).hide(); 1215 } 1216 1217 $(timer_button_el).on('learndash-time-finished', function () { 1218 $(timer_el).hide(); 1219 }); 1220 } 1221 1222 $(document).on('learndash_video_disable_assets', function (event, status) { 1223 if ('undefined' === typeof learndash_video_data) { 1224 return false; 1225 } 1226 1227 if ('BEFORE' == learndash_video_data.videos_shown) { 1228 if (true == status) { 1229 $('.ld-lesson-topic-list').hide(); 1230 $('.ld-lesson-navigation') 1231 .find('#ld-nav-content-list-' + ldVars.postID) 1232 .addClass('user_has_no_access'); 1233 $('.ld-quiz-list').hide(); 1234 } else { 1235 $('.ld-lesson-topic-list').slideDown(); 1236 $('.ld-quiz-list').slideDown(); 1237 $('.ld-lesson-navigation') 1238 .find('#ld-nav-content-list-' + ldVars.postID) 1239 .removeClass('user_has_no_access'); 1240 } 1241 } 1242 }); 1243 1244 $('.learndash-wrapper').on( 1245 'click', 1246 '.wpProQuiz_questionListItem input[type="radio"]', 1247 function (e) { 1248 $(this) 1249 .parents('.wpProQuiz_questionList') 1250 .find('label') 1251 .removeClass('is-selected'); 1252 $(this).parents('label').addClass('is-selected'); 1253 } 1254 ); 1255 1256 $('.learndash-wrapper').on( 1257 'click', 1258 '.wpProQuiz_questionListItem input[type="checkbox"]', 1259 function (e) { 1260 if (jQuery(e.currentTarget).is(':checked')) { 1261 $(this).parents('label').addClass('is-selected'); 1262 } else { 1263 $(this).parents('label').removeClass('is-selected'); 1264 } 1265 } 1266 ); 1267 1268 function learndash_ld30_show_user_statistic(e) { 1269 e.preventDefault(); 1270 1271 var refId = jQuery(this).data('ref-id'); 1272 var quizId = jQuery(this).data('quiz-id'); 1273 var userId = jQuery(this).data('user-id'); 1274 var statistic_nonce = jQuery(this).data('statistic-nonce'); 1275 var post_data = { 1276 action: 'wp_pro_quiz_admin_ajax_statistic_load_user', 1277 func: 'statisticLoadUser', 1278 data: { 1279 quizId, 1280 userId, 1281 refId, 1282 statistic_nonce, 1283 avg: 0, 1284 }, 1285 }; 1286 1287 jQuery('#wpProQuiz_user_overlay, #wpProQuiz_loadUserData').show(); 1288 var content = jQuery('#wpProQuiz_user_content').hide(); 1289 1290 //console.log('- learndash.js'); 1291 1292 jQuery.ajax({ 1293 type: 'POST', 1294 url: ldVars.ajaxurl, 1295 dataType: 'json', 1296 cache: false, 1297 data: post_data, 1298 error(jqXHR, textStatus, errorThrown) {}, 1299 success(reply_data) { 1300 if ('undefined' !== typeof reply_data.html) { 1301 content.html(reply_data.html); 1302 jQuery('#wpProQuiz_user_content').show(); 1303 1304 //console.log('trigger event change - learndash.js'); 1305 jQuery('body').trigger( 1306 'learndash-statistics-contentchanged' 1307 ); 1308 1309 jQuery('#wpProQuiz_loadUserData').hide(); 1310 1311 content.find('.statistic_data').on('click', function () { 1312 jQuery(this).parents('tr').next().toggle('fast'); 1313 1314 return false; 1315 }); 1316 } 1317 }, 1318 }); 1319 1320 jQuery('#wpProQuiz_overlay_close').on('click', function () { 1321 jQuery('#wpProQuiz_user_overlay').hide(); 1322 }); 1323 } 1324 1325 function learndashSetMaxHeight(elm) { 1326 var totalHeight = 0; 1327 1328 elm.find('> *').each(function () { 1329 totalHeight += $(this).outerHeight(); 1330 }); 1331 1332 elm.attr('data-height', '' + (totalHeight + 50) + ''); 1333 1334 elm.css({ 1335 'max-height': totalHeight + 50, 1336 }); 1337 } 1338 1339 /** 1340 * Will scroll the position of the Focus Mode sidebar 1341 * to the active step. 1342 */ 1343 function learndashFocusModeSidebarAutoScroll() { 1344 if (jQuery('.learndash-wrapper .ld-focus').length) { 1345 var sidebar_wrapper = jQuery( 1346 '.learndash-wrapper .ld-focus .ld-focus-sidebar-wrapper' 1347 ); 1348 1349 var sidebar_current_topic = jQuery( 1350 '.learndash-wrapper .ld-focus .ld-focus-sidebar-wrapper .ld-is-current-item' 1351 ); 1352 if ( 1353 'undefined' !== typeof sidebar_current_topic && 1354 sidebar_current_topic.length 1355 ) { 1356 var sidebar_scrollTo = sidebar_current_topic; 1357 } else { 1358 var sidebar_current_lesson = jQuery( 1359 '.learndash-wrapper .ld-focus .ld-focus-sidebar-wrapper .ld-is-current-lesson' 1360 ); 1361 if ( 1362 'undefined' !== typeof sidebar_current_lesson && 1363 sidebar_current_lesson.length 1364 ) { 1365 var sidebar_scrollTo = sidebar_current_lesson; 1366 } 1367 } 1368 1369 if ( 1370 'undefined' !== typeof sidebar_scrollTo && 1371 sidebar_scrollTo.length 1372 ) { 1373 var offset_top = 0; 1374 if ( 1375 jQuery('.learndash-wrapper .ld-focus .ld-focus-header') 1376 .length 1377 ) { 1378 var logo_height = jQuery( 1379 '.learndash-wrapper .ld-focus .ld-focus-header' 1380 ).height(); 1381 offset_top += logo_height; 1382 } 1383 if ( 1384 jQuery( 1385 '.learndash-wrapper .ld-focus .ld-focus-sidebar .ld-course-navigation-heading' 1386 ).length 1387 ) { 1388 var heading_height = jQuery( 1389 '.learndash-wrapper .ld-focus .ld-focus-sidebar .ld-course-navigation-heading' 1390 ).height(); 1391 offset_top += heading_height; 1392 } 1393 if ( 1394 jQuery( 1395 '.learndash-wrapper .ld-focus .ld-focus-sidebar .ld-focus-sidebar-wrapper' 1396 ).length 1397 ) { 1398 var container_height = jQuery( 1399 '.learndash-wrapper .ld-focus .ld-focus-sidebar .ld-focus-sidebar-wrapper' 1400 ).height(); 1401 offset_top += container_height; 1402 } 1403 1404 var current_item_height = jQuery(sidebar_scrollTo).height(); 1405 offset_top -= current_item_height; 1406 1407 sidebar_wrapper.animate( 1408 { 1409 scrollTop: sidebar_scrollTo.offset().top - offset_top, 1410 }, 1411 1000 1412 ); 1413 } 1414 } 1415 } 1416 1417 // Coupon processing. 1418 1419 function update_payment_forms(data) { 1420 $('#total-row').attr('data-total', data.total.value); 1421 1422 // Update PayPal form amount. 1423 $('form[name="buynow"] input[name="amount"]').val(data.total.value); 1424 1425 // Update Stripe form amount. 1426 $('form.learndash-stripe-checkout input[name="stripe_price"]').val( 1427 data.total.stripe_value 1428 ); 1429 1430 // Remove Stripe Connect session to respect the new amount.
1431 const stripe_course_id = $( 1432 '.learndash-stripe-checkout input[name="stripe_course_id"]' 1433 ).val(); 1434 1435 if (stripe_course_id) { 1436 LD_Cookies.remove('ld_stripe_session_id_' + stripe_course_id); // Stripe Plugin (Checkout). 1437 LD_Cookies.remove( 1438 'ld_stripe_connect_session_id_' + stripe_course_id 1439 ); // Stripe Connect in core. 1440 } 1441 1442 // Re-init Stripe Plugin (Legacy) to respect the new amount. 1443 if (typeof ld_init_stripe_legacy === 'function') { 1444 ld_init_stripe_legacy(); 1445 } 1446 } 1447 1448 $('.btn-join').on('click', function (e) { 1449 if ($(this).hasClass('btn-disabled')) { 1450 e.preventDefault(); 1451 return false; 1452 } 1453 1454 const supportsCoupon = $('#total-row').attr('data-supports-coupon'); 1455 1456 if (!supportsCoupon) { 1457 return; 1458 } 1459 1460 const total = parseFloat($('#total-row').attr('data-total')); 1461 1462 if (0 === total) { 1463 $.ajax({ 1464 type: 'POST', 1465 url: ldVars.ajaxurl, 1466 dataType: 'json', 1467 cache: false, 1468 data: { 1469 action: 'learndash_enroll_with_zero_price', 1470 nonce: $('#apply-coupon-form').data('nonce'), 1471 post_id: $('#apply-coupon-form').data('post-id'), 1472 }, 1473 success(response) { 1474 if (response.success) { 1475 window.location.replace(response.data.redirect_url); 1476 } else { 1477 alert(response.data.message); 1478 } 1479 }, 1480 }); 1481 1482 e.preventDefault(); 1483 return false; 1484 } 1485 }); 1486 1487 $('#apply-coupon-form').on('submit', function (e) { 1488 e.preventDefault(); 1489 const $el = $(this); 1490 const $wrapper = $el.closest('.ld-registration-order__items'); 1491 1492 $.ajax({ 1493 type: 'POST', 1494 url: ldVars.ajaxurl, 1495 dataType: 'json', 1496 cache: false, 1497 data: { 1498 action: 'learndash_apply_coupon', 1499 nonce: $(this).data('nonce'), 1500 coupon_code: $(this).find('#coupon-field').val(), 1501 post_id: $(this).data('post-id'), 1502 }, 1503 success(response) { 1504 const isModernRegistration = $( 1505 '.ld-form__field-coupon_field' 1506 ).length; 1507 1508 if (isModernRegistration) { 1509 $('#coupon-alerts .coupon-alert').hide(); 1510 1511 const $alert = $('#coupon-alerts').find( 1512 response.success 1513 ? '.coupon-alert-success' 1514 : '.coupon-alert-warning' 1515 ); 1516 1517 if (response.success) { 1518 $wrapper 1519 .find('.ld-coupon__label-text') 1520 .html(response.data.coupon_code); // Set coupon code in totals. 1521 1522 $wrapper 1523 .find('.ld-coupon__value') 1524 .html('(' + response.data.discount + ')'); // Set discount value in totals. 1525 1526 $wrapper 1527 .find('.ld-registration-order__item-price-value') 1528 .html(response.data.total.formatted); // Update course/group price. 1529 1530 $wrapper 1531 .find('.ld-registration-order__total-price') 1532 .html(response.data.total.formatted); // Update Total. 1533 1534 $wrapper.addClass( 1535 'ld-registration-order__items--with-coupon' 1536 ); 1537 1538 update_payment_forms(response.data); 1539 } 1540 1541 $alert 1542 .find('.ld-alert-messages') 1543 .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 const $coupon_row = $('#coupon-row'); 1555 1556 if (response.success) { 1557 $coupon_row 1558 .find('.purchase-label > span') 1559 .html(response.data.coupon_code); // Set coupon code in totals. 1560 $coupon_row 1561 .find('.purchase-value span') 1562 .html(response.data.discount); // Set discount value in totals. 1563 $coupon_row.css('display', 'flex').hide().fadeIn(); // Show a coupon row in totals. 1564 $('#total-row .purchase-value').html( 1565 response.data.total.formatted 1566 ); // Update Total. 1567 $('#totals').show(); 1568 1569 update_payment_forms(response.data); 1570 } 1571 1572 $alert 1573 .find('.ld-alert-messages') 1574 .html(response.data.message); 1575 $alert.fadeIn(); 1576 } 1577 }, 1578 }); 1579 }); 1580 1581 $('#remove-coupon-form').on('submit', function (e) { 1582 e.preventDefault(); 1583 const $el = $(this); 1584 const $wrapper = $el.closest('.ld-registration-order__items'); 1585 1586 $.ajax({ 1587 type: 'POST', 1588 url: ldVars.ajaxurl, 1589 dataType: 'json', 1590 cache: false, 1591 data: { 1592 action: 'learndash_remove_coupon', 1593 nonce: $(this).data('nonce'), 1594 post_id: $(this).data('post-id'), 1595 }, 1596 success(response) { 1597 const isModernRegistration = $( 1598 '.ld-form__field-coupon_field' 1599 ).length; 1600 1601 if (isModernRegistration) { 1602 $('#coupon-alerts .coupon-alert').hide(); 1603 1604 const $alert = $('#coupon-alerts').find( 1605 response.success 1606 ? '.coupon-alert-success' 1607 : '.coupon-alert-warning' 1608 ); 1609 1610 if (response.success) { 1611 $wrapper.removeClass( 1612 'ld-registration-order__items--with-coupon' 1613 ); 1614 $wrapper.find('.ld-form__field-coupon_field').val(''); // Set coupon field empty. 1615 $wrapper 1616 .find('.ld-registration-order__item-price-value') 1617 .html(response.data.total.formatted); // Update course/group price. 1618 $wrapper 1619 .find('.ld-registration-order__total-price') 1620 .html(response.data.total.formatted); // Update Total. 1621 1622 update_payment_forms(response.data); 1623 } 1624 1625 $alert 1626 .find('.ld-alert-messages') 1627 .html(response.data.message); 1628 $alert.fadeIn(); 1629 } else { 1630 $('#coupon-alerts .coupon-alert').hide(); 1631 1632 const $alert = $('#coupon-alerts').find( 1633 response.success 1634 ? '.coupon-alert-success' 1635 : '.coupon-alert-warning' 1636 ); 1637 1638 if (response.success) { 1639 $('#coupon-row').hide(); // Hide a coupon row in totals. 1640 $('#coupon-field').val(''); // Set coupon field empty. 1641 $('#price-row .purchase-value').html( 1642 response.data.total.formatted 1643 ); // Update Price. 1644 $('#subtotal-row .purchase-value').html( 1645 response.data.total.formatted 1646 ); // Update Subtotal. 1647 $('#total-row .purchase-value').html( 1648 response.data.total.formatted 1649 ); // Update Total. 1650 $('#totals').hide(); 1651 1652 update_payment_forms(response.data); 1653 } 1654 1655 $alert 1656 .find('.ld-alert-messages') 1657 .html(response.data.message); 1658 $alert.fadeIn(); 1659 } 1660 }, 1661 }); 1662 }); 1663}); 1664 1665function ldGetUrlVars() { 1666 var vars = {}; 1667 var parts = window.location.href.replace( 1668 /[?&]+([^=&]+)=([^&]*)/gi, 1669 function (m, key, value) { 1670 vars[key] = value; 1671 } 1672 ); 1673 1674 return vars; 1675}
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.