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