1// import learndash_sidebar from "./learndash-sidebar"; 2/* global bs_data, BBGetUrlParameter */ 3( function ( $ ) { 4 5 "use strict"; 6 7 window.BBLMS = { 8 init: function () { 9 this.switchLdGridList(); 10 this.toggleTheme(); 11 this.learnDashSidePanel(); 12 this.lms_user_profile_js(); 13 // this.lms_course_single_js(); 14 this.lms_single_course(); 15 this.course_archive_js(); 16 // this.quiz_progress(); 17 this.quizDetails(); 18 // this.ajaxCompleteProcess(); 19 this.quizUpload(); 20 this.setElementorSpacing(); 21 this.bbStickyLdSidebar(); 22 // this.StyleInputQuestion(); 23 this.singleLesson(); 24 this.singleTopic(); 25 this.singleQuiz(); 26 this.showMoreParticipants(); 27 this.inforBarStatus(); 28 }, 29 30 switchLdGridList: function() { 31 32 var courseLoopSelector = $( '.bb-course-items:not(.is-cover)' ); 33 $( document ).on( 34 'click', 35 '.grid-filters .layout-view-course:not(.active)', 36 function(e) { 37 e.preventDefault(); 38 39 if ( 40 'undefined' === typeof $( this ).parent().attr( 'data-view' ) || 41 'ld-course' !== $( this ).parent().attr( 'data-view' ) 42 ) { 43 return; 44 } 45 46 var main = $( this ).parents( 'form' ); 47 48 if ( BBLMS.ajax_request ) { 49 BBLMS.ajax_request.abort(); 50 } 51 52 courseLoopSelector = $( this ).parents( 'form' ).find( '.bb-course-items:not(.is-cover)' ); 53 if ( $( this ).hasClass( 'layout-list-view' ) ) { 54 main.find( '.layout-view-course' ).removeClass( 'active' ); 55 courseLoopSelector.removeClass( 'grid-view' ); 56 courseLoopSelector.removeClass( 'bb-grid' ); 57 courseLoopSelector.removeClass( 'list-view' ); 58 courseLoopSelector.removeClass( 'bb-list' ); 59 $( this ).addClass( 'active' ); 60 courseLoopSelector.addClass( 'list-view' ); 61 courseLoopSelector.addClass( 'bb-list' ); 62 BBLMS.ajax_request = $.ajax( 63 { 64 method : 'POST', 65 url : bs_data.ajaxurl, 66 nonce : bs_data.nonce_list_grid, 67 data : 'action=buddyboss_lms_save_view&option=bb_layout_view&object=' + $( this ).parent().attr( 'data-view' ) + '&type=list&nonce=' + bs_data.nonce_list_grid, 68 success : function ( response ) { 69 } 70 } 71 ); 72 } else { 73 main.find( '.layout-view-course' ).removeClass( 'active' ); 74 courseLoopSelector.removeClass( 'grid-view' ); 75 courseLoopSelector.removeClass( 'bb-grid' ); 76 courseLoopSelector.removeClass( 'list-view' ); 77 courseLoopSelector.removeClass( 'bb-list' ); 78 $( this ).addClass( 'active' ); 79 courseLoopSelector.addClass( 'grid-view' ); 80 courseLoopSelector.addClass( 'bb-grid' ); 81 BBLMS.ajax_request = $.ajax( 82 { 83 method : 'POST', 84 url : bs_data.ajaxurl, 85 nonce : bs_data.nonce_list_grid, 86 data : 'action=buddyboss_lms_save_view&option=bb_layout_view&object=' + $( this ).parent().attr( 'data-view' ) + '&type=grid&nonce=' + bs_data.nonce_list_grid, 87 success : function ( response ) { 88 } 89 } 90 ); 91 } 92 } 93 ); 94 }, 95 96 showMoreParticipants: function() { 97 98 var total = $( '.lms-course-members-list .lms-course-sidebar-heading .lms-count' ).text(); 99 var paged = 2; 100 var course = $( '.lms-course-members-list #buddyboss_theme_learndash_course_participants_course_id' ).val(); 101 var spinnerSelector = $( '.lms-course-members-list .bb-course-member-wrap .lme-more i' ); 102 var viewMoreSelector = $( '.lms-course-members-list .bb-course-member-wrap .lme-more' ); 103 104 $( '.lms-course-members-list' ).on( 105 'click', 106 '.bb-course-member-wrap .lme-more', 107 function() { 108 109 if ( $( this ).hasClass( 'loading-members' ) ) { 110 return; 111 } 112 113 $( this ).addClass( 'loading-members' ); 114 115 spinnerSelector.removeClass( 'bb-icon-angle-down' ); 116 spinnerSelector.addClass( 'bb-icon-spin' ); 117 spinnerSelector.addClass( 'animate-spin' ); 118 $( '.lms-course-members-list .bb-course-member-wrap .lme-less' ).hide(); 119 120 $.ajax( 121 { 122 method : 'GET', 123 url : bs_data.ajaxurl, 124 data : 'action=buddyboss_lms_get_course_participants&_wpnonce=' + bs_data.learndash.nonce_get_courses + '&total=' + total + '&page=' + paged + '&course=' + course, 125 success : function ( response ) { 126 $( '.lms-course-members-list .bb-course-member-wrap .course-members-list.course-members-list-extra' ).show(); 127 $( '.lms-course-members-list .bb-course-member-wrap .course-members-list-extra' ).append( response.data.html ); 128 $( window ).trigger( 'resize' ); 129 if ( 'false' === response.data.show_more ) { 130 $( '.lms-course-members-list .bb-course-member-wrap .lme-more' ).remove(); 131 } 132 paged = response.data.page; 133 if ( $( '.ld-sidebar-widgets' ).length === 0 ) { 134 $( '.lms-topic-sidebar-wrapper .lms-topic-sidebar-data' ).animate( { scrollTop: $( document ).height() }, 1000 ); 135 } 136 spinnerSelector.addClass( 'bb-icon-angle-down' ); 137 spinnerSelector.removeClass( 'bb-icon-spin' ); 138 spinnerSelector.removeClass( 'animate-spin' ); 139 viewMoreSelector.removeClass( 'loading-members' ); 140 } 141 } 142 ); 143 } 144 ); 145 146 }, 147 148 fetchCourses: function( target ) { 149 var $form = $( '#bb-courses-directory-form' ); 150 if ( typeof target !== 'undefined' && $( target ).length > 0 ) { 151 $form = $( target ).closest( 'form.bb-courses-directory' ); 152 } 153 154 var reset_pagination = false;
155 156 // reset pagintion if categories or instructor filters are changed. 157 // reset pagination if search term has changed. 158 var resetting_fields = [ 'filter-categories', 'filter-instructors', 'search' ]; 159 for ( var i = 0; i < resetting_fields.length; i++ ) { 160 var prev_val = BBGetUrlParameter( window.location.search, resetting_fields[ i ] ); 161 var new_val = $form.find( '[name="' + resetting_fields[ i ] + '"]' ).val(); 162 163 if ( prev_val !== new_val ) { 164 165 switch ( resetting_fields[ i ] ) { 166 case 'filter-categories': 167 case 'filter-instructors': 168 if ( ! prev_val && new_val === 'all' ) { 169 // hasn't really changed. 170 } else { 171 reset_pagination = true; 172 } 173 break; 174 default: 175 reset_pagination = true; 176 break; 177 } 178 179 } 180 181 if ( reset_pagination ) { 182 break; 183 } 184 } 185 186 if ( reset_pagination ) { 187 $form.find( '[name="current_page"]' ).val( 1 ); 188 } 189 190 var data = $form.serialize(); 191 192 // update url. 193 var new_url = bs_data.learndash.course_archive_url; 194 if ( $form.hasClass( 'bb-elementor-widget' ) ) { 195 new_url = $form.data( 'current_page_url' ); 196 } 197 198 data += '&request_url=' + encodeURIComponent( new_url ); 199 200 BBLMS.ajax_request = $.ajax( 201 { 202 method : 'GET', 203 url : bs_data.ajaxurl, 204 data : data + '&action=buddyboss_lms_get_courses&_wpnonce=' + bs_data.learndash.nonce_get_courses, 205 success : function ( response ) { 206 if ( !_.isUndefined( response.data.layout ) ) { 207 $( '.layout-view' ).removeClass( 'active' ); 208 $( '.layout-' + response.data.layout + '-view' ).addClass( 'active' ); 209 } 210 var current_page = $form.find( '[name="current_page"]' ).val(); 211 if ( isNaN( current_page ) ) { 212 current_page = 1; 213 } 214 if ( current_page > 1 && ! $( 'body' ).hasClass( 'bp-user' ) ) { 215 new_url += 'page/' + current_page + '/'; 216 } 217 218 new_url += '?' + data; 219 220 window.history.pushState( { 'bblms_has_changes' : true, 'courses_html' : response.data.html, 'type' : $form.find( '[name="type"]' ).val() }, "", new_url ); 221 222 // update html. 223 $form.find( '.bs-dir-list' ).html( response.data.html ); 224 225 // update count. 226 $form.find( 'li.selected a span' ).text( response.data.count ); 227 228 var course_label = $form.data( 'courses_label' ); 229 if ( 1 === parseInt( response.data.count ) ) { 230 course_label = $form.data( 'course_label' ); 231 } 232 233 $form.find( '.bb-item-count' ).html( '<span class="bb-count">' + response.data.count + '</span> ' + course_label ); 234 235 if ( response.data.scopes ) { 236 for (var i in response.data.scopes) { 237 $form.find( 'li#courses-' + i + ' a span' ).text( response.data.scopes[i] ).show(); 238 } 239 } 240 241 $( '.courses-nav' ).find( '.bb-icon-loader' ).remove(); 242 } 243 } 244 ); 245 246 return false; 247 // $( '#bb-courses-directory-form' ).submit(); 248 }, 249 250 fetchCoursesPagination: function( target ) { 251 var $form = $( '#bb-courses-directory-form' ); 252 if ( typeof target !== 'undefined' && $( target ).length > 0 ) { 253 $form = $( target ).closest( 'form.bb-courses-directory' ); 254 } 255 var data = $form.serialize(); 256 257 // update url. 258 var new_url = $form.attr( 'action' ); 259 if ( $form.hasClass( 'bb-elementor-widget' ) ) { 260 new_url = $form.data( 'current_page_url' ); 261 } 262 263 if ( '' === new_url ) { 264 new_url = bs_data.learndash.course_archive_url; 265 } 266 267 data += '&request_url=' + encodeURIComponent( new_url ); 268 269 var order = $form.data( 'order' ); 270 if ( typeof order !== 'undefined' && order !== false ) { 271 data = data + '&order=' + order; 272 } 273 274 var orderby = $form.data( 'orderby' ); 275 if ( typeof orderby !== 'undefined' && orderby !== false ) { 276 data = data + '&orderby=' + orderby; 277 } 278 279 $.ajax( 280 { 281 method : 'GET', 282 url : bs_data.ajaxurl, 283 data : data + '&action=buddyboss_lms_get_courses&_wpnonce=' + bs_data.learndash.nonce_get_courses, 284 success : function ( response ) { 285 if ( !_.isUndefined( response.data.layout ) ) { 286 $( '.layout-view' ).removeClass( 'active' ); 287 $( '.layout-' + response.data.layout + '-view' ).addClass( 'active' ); 288 } 289 290 var current_page = $form.find( '[name="current_page"]' ).val(); 291 if ( isNaN( current_page ) ) { 292 current_page = 1; 293 } 294 if ( '/' !== new_url.substr( -1 ) ) { 295 new_url += '/'; 296 } 297 if ( current_page > 1 && ! $( 'body' ).hasClass( 'bp-user' ) ) { 298 new_url += 'page/' + current_page + '/'; 299 } 300 301 new_url += '?' + data; 302 303 window.history.pushState( { 'bblms_has_changes' : true, 'courses_html' : response.data.html, 'type' : $form.find( '[name="type"]' ).val() }, "", new_url ); 304 305 // update html. 306 $form.find( '.bs-dir-list' ).html( response.data.html ); 307 308 // update count. 309 $form.find( 'li.selected a span' ).text( response.data.count ); 310 311 if ( response.data.scopes ) { 312 for (var i in response.data.scopes) { 313 $form.find( 'li#courses-' + i + ' a span' ).text( response.data.scopes[i] ).show(); 314 } 315 } 316 $( '.courses-nav' ).find( '.bb-icon-loader' ).remove(); 317 318 // Scroll to course listing top. 319 $( 'html, body' ).animate( { 320 scrollTop: $form.offset().top - 150 321 }, 400 ); 322 } 323 } 324 ); 325 326 return false;
327 // $( '#bb-courses-directory-form' ).submit(); 328 }, 329 330 course_archive_js: function() { 331 332 $( document ).on( 333 'change', 334 '#bb-courses-directory-form input[type=checkbox]', 335 function ( e ) { 336 e.preventDefault(); 337 window.BBLMS.fetchCourses(); 338 } 339 ); 340 341 window.onpopstate = function(e) { 342 if ( ! e.state ) { 343 return; 344 } 345 346 var has_changes = e.state.hasOwnProperty( 'bblms_has_changes' ) ? e.state.bblms_has_changes : false; 347 if ( has_changes ) { 348 var $form = $( '#bb-courses-directory-form' ); 349 350 // update courses html. 351 $form.find( '.bs-dir-list' ).html( e.state.courses_html ); 352 353 // highlight correct nav. 354 $form.find( '[name="type"]' ).val( e.state.type ); 355 356 $form.find( '.component-navigation > li' ).each( 357 function(){ 358 $( this ).removeClass( 'selected' ); 359 var type = BBGetUrlParameter( $( this ).find( ' > a' ).attr( 'href' ), 'type' ); 360 if ( type === e.state.type ) { 361 $( this ).addClass( 'selected' ); 362 } 363 } 364 ); 365 } 366 }; 367 368 $( document ).on( 369 'click', 370 '#bb-course-list-grid-filters .grid-filters a:not(.active)', 371 function ( e ) { 372 e.preventDefault(); 373 374 if ( BBLMS.ajax_request ) { 375 BBLMS.ajax_request.abort(); 376 } 377 378 $( '#bb-course-list-grid-filters .grid-filters a' ).removeClass( 'active' ); 379 $( e.currentTarget ).addClass( 'active' ); 380 var view = $( e.currentTarget ).data( 'view' ); 381 var selector = $( '.ld-course-list-content' ); 382 if ( selector.hasClass( 'list-view' ) ) { 383 selector.removeClass( 'list-view' ); 384 } 385 386 if ( selector.hasClass( 'grid-view' ) ) { 387 selector.removeClass( 'grid-view' ); 388 } 389 390 selector.addClass( view + '-view' ); 391 392 BBLMS.ajax_request = $.ajax( 393 { 394 method : 'POST', 395 url : bs_data.ajaxurl, 396 nonce : bs_data.nonce_list_grid, 397 data : 'action=buddyboss_lms_save_view&option=bb_layout_view&object=' + $( this ).parent().attr( 'data-view' ) + '&type=' + view + '&nonce=' + bs_data.nonce_list_grid, 398 success : function ( response ) { 399 } 400 } 401 ); 402 403 } 404 ); 405 406 $( document ).ready( 407 function() { 408 if ( $( 'body #bb-course-list-grid-filters' ).length ) { 409 var active = ''; 410 if ($( '#bb-course-list-grid-filters .grid-filters .layout-grid-view' ).hasClass( 'active' )) { 411 active = 'grid-view'; 412 } else { 413 active = 'list-view'; 414 } 415 $( '.ld-course-list-content' ).addClass( active ); 416 } 417 } 418 ); 419 420 $( document ).on( 421 'change', 422 '#bb-courses-directory-form [name=\'orderby\'], #bb-courses-directory-form [name=\'filter-categories\'], #bb-courses-directory-form [name=\'filter-instructors\']', 423 function ( e ) { 424 e.preventDefault(); 425 window.BBLMS.fetchCourses( e.target ); 426 } 427 ); 428 429 $( document ).on( 430 'click', 431 '#bb-courses-directory-form .bs-sort-button', 432 function ( e ) { 433 e.preventDefault(); 434 e.currentTarget.classList.toggle( 'active' ); 435 $( '#bs-courses-order-by' ).toggleClass( 'open' ); 436 } 437 ); 438 439 $( document ).on( 440 'click', 441 '#bb-courses-directory-form .bb-lms-pagination a.page-numbers', 442 function ( e ) { 443 e.preventDefault(); 444 var page_number = 1; 445 var url_parts = $( this ).attr( 'href' ).split( '/' ); 446 if ( url_parts.length > 0 ) { 447 for ( var i = 0; i < url_parts.length; i++ ) { 448 if ( 'page' === url_parts[i] ) { 449 page_number = url_parts[ i + 1 ]; 450 break; 451 } 452 } 453 } 454 455 if ( 0 === $( this ).closest( 'form' ).find( '[name="current_page"]' ).length ) { 456 $( '<input>' ).attr( 457 { 458 type: 'hidden', 459 name: 'current_page' 460 } 461 ).appendTo( $( this ).closest( 'form' ) ); 462 } 463 $( this ).closest( 'form' ).find( '[name="current_page"]' ).val( page_number ); 464 window.BBLMS.fetchCoursesPagination( e.target ); 465 } 466 ); 467 468 $( document ).on( 469 'click', 470 '#bb-courses-directory-form .component-navigation a:not(.more-button)', 471 function ( e ) { 472 e.preventDefault(); 473 474 if ( BBLMS.ajax_request ) { 475 BBLMS.ajax_request.abort(); 476 } 477 478 $( this ).closest( '.component-navigation' ).find( '> li' ).removeClass( 'selected' ); 479 $( this ).closest( 'li' ).addClass( 'selected' ).append( '<i class="bb-icon-loader animate-spin"></i>' ); 480 481 var type = BBGetUrlParameter( $( this ).attr( 'href' ), 'type' ); 482 $( this ).closest( 'form' ).find( '[name="type"]' ).val( type ); 483 484 // resetting the page number if important, as sometimes 'all courses' can have more items than 'my courses'. 485 $( this ).closest( 'form' ).find( '[name="current_page"]' ).val( 1 ); 486 window.BBLMS.fetchCourses( e.target ); 487 } 488 ); 489 490 document.addEventListener( 491 'click', 492 function ( e ) { 493 var openFilterDropdown = $( '#course-order-dropdown' ); 494 var target = e.target; 495 if ( openFilterDropdown === target && openFilterDropdown.contains( target ) ) { 496 return false;
497 } 498 499 var dropdowns = $( '#bb-courses-directory-form .bs-dropdown' ); 500 var download_link = $( '#bb-courses-directory-form .bs-dropdown-link' ); 501 502 for ( var i = 0; i < download_link.length; i++ ) { 503 if ( download_link[i] !== target && ! download_link[i].contains( target ) ) { 504 download_link[i].classList.remove( 'active' ); 505 } 506 } 507 508 for ( var i = 0; i < dropdowns.length; i++ ) { 509 if ( dropdowns[i] != target.parentElement.nextElementSibling ) { 510 dropdowns[i].classList.remove( 'open' ); 511 } 512 } 513 } 514 ); 515 516 $( 'form.bb-courses-directory' ).on( 517 'submit', 518 function(e){ 519 e.preventDefault(); 520 521 if ( BBLMS.ajax_request ) { 522 BBLMS.ajax_request.abort(); 523 } 524 525 window.BBLMS.fetchCourses( e.target ); 526 return false; 527 } 528 ); 529 530 $( '#bb-courses-directory-form #bs_members_search' ).on( 531 'keypress' , 532 function(e){ 533 if ( e.which == 13 ) { 534 $( e.target ).closest( 'form.bb-courses-directory' ).submit(); 535 } 536 } 537 ); 538 539 }, 540 541 toggleTheme: function() { 542 543 $( document ).on( 544 'click', 545 '#bb-toggle-theme', 546 function ( e ) { 547 e.preventDefault(); 548 var color = ''; 549 if ( ! $( 'body' ).hasClass( 'bb-dark-theme' ) ) { 550 $.cookie( 'bbtheme', 'dark', { path: '/' } ); 551 $( 'body' ).addClass( 'bb-dark-theme' ); 552 color = 'dark'; 553 } else { 554 $.removeCookie( 'bbtheme', { path: '/' } ); 555 $( 'body' ).removeClass( 'bb-dark-theme' ); 556 } 557 558 if ( typeof( toggle_theme_ajax ) != 'undefined' && toggle_theme_ajax != null ) { 559 toggle_theme_ajax.abort(); 560 } 561 562 var data = { 563 'action': 'buddyboss_lms_toggle_theme_color', 564 'color': color 565 }; 566 567 // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php. 568 if ( typeof( toggle_theme_ajax ) != 'undefined' && toggle_theme_ajax != null ) { 569 toggle_theme_ajax = $.post( ajaxurl, data, function ( response ) {} ); 570 } 571 } 572 ); 573 }, 574 575 learnDashSidePanel: function() { 576 577 /* Resize elementor header */ 578 function elementorHeaderTriggerResize() { 579 if ( $( '.bb-buddypanel.bb-sfwd-aside .site-header--elementor' ).length > 0 ) { 580 setTimeout( 581 function () { 582 $( window ).trigger( 'resize' ); 583 }, 584 300 585 ); 586 setTimeout( 587 function () { 588 $( window ).trigger( 'resize' ); 589 }, 590 500 591 ); 592 } 593 } 594 595 $( document ).on( 596 'click', 597 '.header-maximize-link', 598 function ( e ) { 599 e.preventDefault(); 600 $( 'body' ).addClass( 'lms-side-panel-close' ); 601 $( '.lms-topic-sidebar-wrapper' ).addClass( 'lms-topic-sidebar-close' ); 602 $.cookie( 'lessonpanel', 'closed', { path: '/' } ); 603 elementorHeaderTriggerResize(); 604 } 605 ); 606 607 $( document ).on( 608 'click', 609 '.header-minimize-link', 610 function ( e ) { 611 e.preventDefault(); 612 $( 'body' ).removeClass( 'lms-side-panel-close' ); 613 $( '.lms-topic-sidebar-wrapper' ).removeClass( 'lms-topic-sidebar-close' ); 614 $.removeCookie( 'lessonpanel', { path: '/' } ); 615 elementorHeaderTriggerResize(); 616 } 617 ); 618 619 if ( $( window ).width() < 768 ) { 620 $( 'body' ).addClass( 'lms-side-panel-close' ); 621 $( '.lms-topic-sidebar-wrapper' ).addClass( 'lms-topic-sidebar-close show-in-mobile' ); 622 623 $( document ).on( 624 'click', 625 '.header-minimize-link', 626 function ( e ) { 627 e.preventDefault(); 628 $( 'body' ).addClass( 'lms-side-panel-close-sm' ); 629 } 630 ); 631 632 $( document ).click( 633 function(e) { 634 var container = $( '.header-minimize-link' ); 635 if ( ! container.is( e.target ) && container.has( e.target ).length === 0 ) { 636 $( 'body' ).removeClass( 'lms-side-panel-close-sm' ); 637 } 638 } 639 ); 640 } 641 642 $( window ).on( 643 'resize', 644 function () { 645 if ( $( window ).width() < 768 ) { 646 $( document ).click( 647 function(e) { 648 var container = $( '.header-minimize-link' ); 649 if ( ! container.is( e.target ) && container.has( e.target ).length === 0 ) { 650 $( 'body' ).removeClass( 'lms-side-panel-close-sm' ); 651 } 652 } 653 ); 654 } 655 } 656 ); 657 }, 658 659 lms_course_single_js: function() { 660 $( document ).on( 661 'click', 662 '.learndash-course-single-nav', 663 function ( e ) { 664 e.preventDefault(); 665 $( 'ul.learndash-course-single-main-nav' ).find( 'li.current.selected' ).removeClass( 'current' ).removeClass( 'selected' ); 666 667 var li = $( e.currentTarget ).closest( 'li' ); 668 li.addClass( 'current' ); 669 li.addClass( 'selected' ); 670 671 var currentTab = $( e.currentTarget ); 672 var tab_to_change = currentTab.data( 'tab' ); 673 674 var content_elems = $( '.learndash-course-single-tab-content' ); 675 $.each( 676 content_elems, 677 function ( elem ) { 678 var _this = $( this ); 679 if ( _this.data( 'tab' ) == tab_to_change ) { 680 _this.removeClass( 'hide' ); 681 } else { 682 _this.addClass( 'hide' ); 683 } 684 } 685 ); 686 687 } 688 ); 689 }, 690 691 lms_single_course: function() { 692 $( '.bb-course-video-overlay' ).magnificPopup( 693 { 694 fixedBgPos: true, 695 fixedContentPos: true, 696 items: { 697 src: '.bb_course_video_details', 698 type: 'inline' 699 }, 700 callbacks: { 701 open: function () { 702 // Pause the video if someone click on the close button of the magnificPopup. 703 $.magnificPopup.instance.close = function () { 704 if ($( '.mfp-container .mfp-content .bb_course_video_details video'.length )) { 705 $( 'video' ).trigger( 'pause' ); 706 $.magnificPopup.proto.close.call( this ); 707 } 708 }; 709 } 710 } 711 } 712 ); 713 714 function sideBarPosition() { 715 var courseBannerHeight = $( '.bb-learndash-banner' ).height(); 716 var courseBannerVideo = $( '.bb-thumbnail-preview .bb-preview-course-link-wrap' ); 717 if ( courseBannerVideo.length ) { 718 var thumbnailContainerHeight = courseBannerVideo.height(); 719 } else { 720 var thumbnailContainerHeight = 0; 721 } 722 var sidebarOffset = ( courseBannerHeight / 2 ) + ( thumbnailContainerHeight / 2 ); 723 if ( $( window ).width() > 820 ) { 724 $( '.bb-single-course-sidebar.bb-preview-wrap' ).css( { 'margin-top' : '-' + sidebarOffset + 'px' } ); 725 } 726 } 727 728 function courseBanner() { 729 var mainWidth = $( '#main' ).width(); 730 $( '.bb-learndash-banner .bb-course-banner-info.container' ).width( mainWidth ); 731 } 732 733 sideBarPosition(); 734 courseBanner(); 735 736 $( window ).on( 737 'resize', 738 function () { 739 courseBanner(); 740 sideBarPosition(); 741 } 742 ); 743 744 $( '.bb-toggle-panel' ).on( 745 'click', 746 function(e) { 747 e.preventDefault(); 748 749 setTimeout( 750 function(){ 751 courseBanner(); 752 }, 753 300 754 ); 755 setTimeout( 756 function(){ 757 courseBanner(); 758 }, 759 600 760 ); 761 } 762 ); 763 764 $( '.lms-topic-sidebar-wrapper .lms-toggle-lesson' ).on( 765 'click', 766 function() { 767 setTimeout( function(){ $( window ).trigger( 'resize' ); }, 300 ); 768 } 769 ); 770 }, 771 772 lms_user_profile_js: function() { 773 $( document ).on( 774 'click', 775 '.bb-lms-user-profile-tab', 776 function ( e ) { 777 e.preventDefault(); 778 $( 'ul.bb-lms-user-profile-tabs' ).find( 'li.current.selected' ).removeClass( 'current' ).removeClass( 'selected' ); 779 780 var li = $( e.currentTarget ).closest( 'li' ); 781 li.addClass( 'current' ); 782 li.addClass( 'selected' ); 783 784 var currentTab = $( e.currentTarget ); 785 var tab_to_change = currentTab.data( 'tab' ); 786 787 var content_elems = $( '.bb-lms-user-profile-tab-content' ); 788 $.each( 789 content_elems, 790 function ( elem ) { 791 var _this = $( this ); 792 if ( _this.data( 'tab' ) == tab_to_change ) { 793 _this.removeClass( 'hide' ); 794 } else { 795 _this.addClass( 'hide' ); 796 } 797 } 798 ); 799 800 } 801 ); 802 }, 803 804 quizDetails: function() { 805 806 if ( $( '#bb-lms-quiz-id' ).length ) { 807 var quiz_id = $( '#bb-lms-quiz-id' ).val(); 808 809 $( 'div.quiz_progress_container' ).insertBefore( $( '.wpProQuiz_results .wpProQuiz_resultTable' ) ); 810 811 $( '#wpProQuiz_' + quiz_id ).on( 812 'learndash-quiz-init', 813 function () { 814 // $( document ).find( 'input[name="startQuiz"]' ).click( function () { 815 // BBLMS.showQuizNavigation(); 816 // } ); 817 // 818 // $( document ).on( 'click', '.bb-lms-quiz-questions', function ( e ) { 819 // e.preventDefault(); 820 // var index = $( e.currentTarget ).data( 'index' ); 821 // if ( typeof index !== 'undefined' ) { 822 // $( '#wpProQuiz_' + quiz_id ).data( "wpProQuizFront" ).methode.showQuestion( index ); 823 // } 824 // } ); 825 } 826 ); 827 } 828 }, 829
830 ajaxCompleteProcess: function () { 831 $( document ).ajaxComplete( 832 function (event, request, settings) { 833 if (settings.data.indexOf( 'action=wp_pro_quiz_load_quiz_data' ) || settings.data.indexOf( 'action=wp_pro_quiz_completed_quiz' )) { 834 if (settings.data && settings.data != '') { 835 var splitted = settings.data.split( '&' ); 836 var action = ''; 837 for (var i in splitted) { 838 if (splitted[i].indexOf( 'action' ) != -1) { 839 action = splitted[i].split( '=' ); 840 action = typeof action[1] !== 'undefined' ? action[1] : ''; 841 break; 842 } 843 } 844 if (action != '' && action == 'wp_pro_quiz_load_quiz_data') { 845 if ($( '.wpProQuiz_resultTable' ).length) { 846 $( '.bb_avg_progress' ).show(); 847 848 var pathAvg = new ProgressBar.Path( 849 "#bb_avg_shape", 850 { 851 duration: 3000, 852 from: { 853 color: "#ECCBFF", 854 width: 8 855 }, 856 to: { 857 color: "#ECCBFF", 858 width: 8 859 }, 860 easing: "easeInOut", 861 step: function (state, shape) { 862 shape.path.setAttribute( "stroke", state.color ); 863 shape.path.setAttribute( "stroke-width", state.width ); 864 } 865 } 866 ); 867 868 var avarage = request.responseJSON.averageResult; 869 if (avarage > 0) { 870 avarage = -avarage / 100; 871 } else { 872 avarage = 0; 873 } 874 pathAvg.animate( avarage ); 875 } 876 } 877 if (action != '' && action == 'wp_pro_quiz_completed_quiz') { 878 if ($( '.wpProQuiz_resultTable' ).length) { 879 880 var data = decodeURIComponent( settings.data ); 881 var splitted = data.split( '&' ); 882 var result = ''; 883 for (var i in splitted) { 884 if (splitted[i].indexOf( 'results' ) != -1) { 885 result = splitted[i].split( '=' ); 886 result = typeof result[1] !== 'undefined' ? result[1] : ''; 887 result = JSON.parse( result ); 888 break; 889 } 890 } 891 892 if (typeof result.comp.result !== 'undefined') { 893 result = result.comp.result; 894 } 895 896 var path = new ProgressBar.Path( 897 "#quiz_shape_progress", 898 { 899 duration: 3000, 900 from: { 901 color: "#00A2FF", 902 width: 8 903 }, 904 to: { 905 color: "#7FE0FF", 906 width: 8 907 }, 908 easing: "easeInOut", 909 step: function (state, shape) { 910 shape.path.setAttribute( "stroke", state.color ); 911 shape.path.setAttribute( "stroke-width", state.width ); 912 } 913 } 914 ); 915 916 jQuery( '.bb_progressbar_label' ).text( result + '%' ); 917 jQuery( '.bb_progressbar_points' ).text( jQuery( '.wpProQuiz_points' ).text() ); 918 919 if (result > 0) { 920 result = -result / 100; 921 } 922 923 path.animate( result ); 924 } 925 } 926 } 927 } 928 } 929 ); 930 }, 931 932 quizUpload: function() { 933 function inputFileStyle() { 934 $( 'input.wpProQuiz_upload_essay[type=file]:not(.styled)' ).each( 935 function () { 936 var $fileInput = $( this ); 937 var $fileInputFor = $fileInput.attr( 'id' ); 938 $fileInput.addClass( 'styled' ); 939 $fileInput.after( '<label for="' + $fileInputFor + '">' + bs_data.translation.choose_a_file_label + '</label>' ); 940 } 941 ); 942 943 $( 'input.wpProQuiz_upload_essay[type=file]' ).change( 944 function ( e ) { 945 var $in = $( this ); 946 var $inval = $in.next().html( $in.val() ); 947 if ( $in.val().length === 0 ) { 948 $in.next().html( bs_data.translation.choose_a_file_label ); 949 } else { 950 $in.next().html( $in.val().replace( /C:\\fakepath\\/i, '' ) ); 951 } 952 } 953 ); 954 } 955 956 inputFileStyle(); 957 $( document ).ajaxComplete( 958 function() { 959 inputFileStyle(); 960 } 961 ); 962 }, 963 964 bbStickyLdSidebar: function () { 965 function ldSaidebarPosition() { 966 var bbHeaderHeight = $( '#masthead' ).outerHeight(); 967 968 if ( $( window ).width() > 820 && $( '.bb-ld-sticky-sidebar .ld-sidebar-widgets' ).length == 0 ) { 969 $( '.bb-ld-sticky-sidebar' ).stick_in_parent( {offset_top: bbHeaderHeight + 45} ); 970 971 var adminBarHeight = 0; 972 if ( $( 'body' ).hasClass( 'admin-bar' ) ) { 973 adminBarHeight = 32; 974 } 975 $( '.lms-topic-sidebar-data' ).css( {'max-height': 'calc(100vh - ' + ( bbHeaderHeight + adminBarHeight ) + 'px', 'top': ( bbHeaderHeight + adminBarHeight ) + 'px' } ); 976 /* Learndash single lesson/topic/quiz pages - header always sticky */ 977 /*if( !$('body').hasClass( 'sticky-header' ) ) { 978 if( $(window).scrollTop() >= $('#masthead').outerHeight() ) { 979 bbHeaderHeight = 0; 980 } else { 981 bbHeaderHeight = $('#masthead').outerHeight(); 982 } 983 $('.lms-topic-sidebar-data').css({'max-height': 'calc(100vh - '+ ( bbHeaderHeight + adminBarHeight ) +'px', 'top': ( bbHeaderHeight + adminBarHeight ) +'px' }); 984 }*/ 985 986 } else { 987 $( '.bb-ld-sticky-sidebar' ).trigger( "sticky_kit:detach" ); 988 // $('.lms-topic-sidebar-data').trigger("sticky_kit:detach"); 989 } 990 } 991 992 ldSaidebarPosition(); 993 994 $( window ).on( 995 'resize', 996 function () { 997 ldSaidebarPosition(); 998 } 999 ); 1000 1001 $(window).on('scroll', function () { 1002 if ( $( '#learndash-payment-button-dropdown' ).length ) { 1003 $( '#learndash-payment-button-dropdown' ).fadeOut( 'fast' ); 1004 $( '.learndash_checkout_buttons .learndash_checkout_button' ).removeClass( 'jq-dropdown-open' ).blur(); 1005 } 1006 }); 1007 1008 /* Learndash single lesson/topic/quiz pages - header always sticky */ 1009 /*$(window).on('scroll', function () { 1010 if( !$('body').hasClass( 'sticky-header' ) ) { 1011 if( $(window).scrollTop() >= $('#masthead').outerHeight() ) { 1012 bbHeaderHeight = 0; 1013 } else { 1014 bbHeaderHeight = $('#masthead').outerHeight(); 1015 } 1016 $('.lms-topic-sidebar-data').css({'max-height': 'calc(100vh - '+ ( bbHeaderHeight + adminBarHeight ) +'px', 'top': ( bbHeaderHeight + adminBarHeight ) +'px' }); 1017 } 1018 1019 });*/ 1020 1021 if ($( '.wpProQuiz_matrixSortString' ).length > 0) { 1022 $( 'html' ).addClass( 'quiz-sort' ); 1023 } 1024 }, 1025 1026 setElementorSpacing: function() { 1027 if ( $( '.elementor-location-header' ).length > 0 ) { 1028 var setHeight = $( '.elementor-location-header' ).outerHeight(); 1029 $( '.lms-topic-sidebar-wrapper, #learndash-page-content' ).css( {'min-height': 'calc(100vh - ' + setHeight + 'px)'} ); 1030 } 1031 }, 1032 1033 showQuizNavigation: function() { 1034 var question_list = $( '.wpProQuiz_list' ).find( '.wpProQuiz_listItem' ); 1035 var nav_wrapper = $( '#bb-lms-quiz-navigation' ); 1036 if ( question_list.length && nav_wrapper.length ) { 1037 var str = '<ul>'; 1038 for ( var i = 1; i <= question_list.length; i++ ) { 1039 str += '<li><a href="#" class="bb-lms-quiz-questions" data-index="' + ( i - 1 ) + '">' + i + '</a></li>'; 1040 } 1041 str += '</ul>'; 1042 nav_wrapper.html( str ); 1043 } 1044 }, 1045 1046 StyleInputQuestion: function() { 1047 function styleInputs() { 1048 $( '.wpProQuiz_questionInput:not([type="text"]):not([type="email"]):not([type="tel"]):not([type="date"])' ).each( 1049 function() { 1050 if ( ! $( this ).hasClass( 'bbstyled' ) ) { 1051 $( this ).addClass( 'bbstyled' ).after( '<span class="input-style"></span>' ); 1052 } 1053 } 1054 ); 1055 } 1056 1057 styleInputs(); 1058 1059 $( document ).ajaxComplete( 1060 function() { 1061 styleInputs(); 1062 } 1063 ); 1064 }, 1065 1066 singleLesson: function() { 1067 var lsPageContent = document.getElementById( 'learndash-page-content' ); 1068 if ( lsPageContent ) { 1069 $( '#learndash-page-content' ).scroll( 1070 function() { 1071 $( window ).trigger( 'resize' ); 1072 } 1073 ); 1074 } 1075 }, 1076 1077 singleTopic: function() { 1078 var lsPageContent = $( 'body.single-sfwd-topic .lms-topic-item.current' ); 1079 if ( lsPageContent.length ) { 1080 lsPageContent.closest( 'div' ).show(); 1081 lsPageContent.parents().closest( 'li' ).removeClass( 'lms-lesson-turnover' ); 1082 }
1083 // Remove comment system added by shortcodes. 1084 var learndash_pages = ['.sfwd-lessons-template-default', '.sfwd-topic-template-default', '.sfwd-quiz-template-default']; 1085 for (var i = 0; i < learndash_pages.length; i++) { 1086 if ($( learndash_pages[i] + ' #learndash-page-content #learndash-content #learndash-page-content .learndash_content_wrap #comments.comments-area' ).length > 0) { 1087 $( learndash_pages[i] + ' #learndash-page-content #learndash-content #learndash-page-content .learndash_content_wrap #comments.comments-area' ).remove(); 1088 } 1089 if ($( learndash_pages[i] + ' #learndash-page-content #learndash-content #learndash-page-content .learndash_content_wrap .ld-focus-comments' ).length > 0) { 1090 $( learndash_pages[i] + ' #learndash-page-content #learndash-content #learndash-page-content .learndash_content_wrap .ld-focus-comments' ).remove(); 1091 } 1092 } 1093 }, 1094 1095 singleQuiz: function() { 1096 var lsPageContent = $( 'body.single-sfwd-quiz .lms-quiz-item.current' ); 1097 if ( lsPageContent.length ) { 1098 lsPageContent.closest( 'div' ).show(); 1099 lsPageContent.parents().closest( 'li' ).removeClass( 'lms-lesson-turnover' ); 1100 } 1101 if ( $( window ).width() > 768 && $( '.wpProQuiz_quiz #bbpress-forums .bs-topic-sidebar-inner' ).length > 0 ) { 1102 // https://developers.learndash.com/snippet/hook-into-quiz-start-button-logic/ 1103 var triggerElements = [ 1104 '.wpProQuiz_content input.wpProQuiz_button[name="startQuiz"]', 1105 '.wpProQuiz_content .wpProQuiz_QuestionButton[value="Next"]', 1106 '.wpProQuiz_content .wpProQuiz_QuestionButton[value="Back"]' ]; 1107 triggerElements.forEach( 1108 function ( el ) { 1109 $( el ).click( 1110 function () { 1111 setTimeout( 1112 function () { 1113 // Trigger scroll to initiate sidebar stick_in_parent script. 1114 $( window ).trigger( 'scroll' ); 1115 }, 1116 0 1117 ); 1118 } 1119 ); 1120 } 1121 ); 1122 } 1123 }, 1124 1125 inforBarStatus: function () { 1126 if ( $( '.ld-course-status-segment' ).length ) { 1127 $( '.ld-course-status-segment' ).each( 1128 function () { 1129 if ( $( this ).find( '.ld-course-status-label' ).text().trim() == '' ) { 1130 $( this ).find( '.ld-course-status-label' ).addClass( 'no-label' ); 1131 } 1132 } 1133 ); 1134 } 1135 }, 1136 1137 }; 1138 1139 $( document ).ready( 1140 function () { 1141 window.BBLMS.ajax_request = null; 1142 window.BBLMS.init(); 1143 } 1144 ); 1145 1146} )( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.