← All changes
|
assets/src/apps/js/frontend/single-curriculum/scrolltoitem.js
+47
-47
4.3.8
→
4.4.10
View file →
| @@ -1,47 +1,47 @@ | ||
| 1 | -import lpModalOverlay from '../../utils/lp-modal-overlay'; | |
| 2 | - | |
| 3 | -const $ = jQuery; | |
| 4 | - | |
| 5 | -const scrollToItemCurrent = { | |
| 6 | - init() { | |
| 7 | - this.scrollToItemViewing = function() { | |
| 8 | - const elItemViewing = $( '.viewing-course-item' ); | |
| 9 | - if ( elItemViewing.length ) { | |
| 10 | - const elCourseCurriculumn = $( '#learn-press-course-curriculum' ); | |
| 11 | - const heightCourseItemContentHeader = $( '#popup-sidebar' ).outerHeight(); | |
| 12 | - const heightSectionTitle = $( '.section-title' ).outerHeight(); | |
| 13 | - const heightSectionHeader = $( '.section-header' ).outerHeight(); | |
| 14 | - const regex = new RegExp( '^viewing-course-item-([0-9].*)' ); | |
| 15 | - const classList = elItemViewing.attr( 'class' ); | |
| 16 | - const classArr = classList.split( /\s+/ ); | |
| 17 | - let idItem = 0; | |
| 18 | - | |
| 19 | - $.each( classArr, function( i, className ) { | |
| 20 | - const compare = regex.exec( className ); | |
| 21 | - | |
| 22 | - if ( compare ) { | |
| 23 | - idItem = compare[ 1 ]; | |
| 24 | - return false; | |
| 25 | - } | |
| 26 | - } ); | |
| 27 | - | |
| 28 | - if ( 0 === idItem ) { | |
| 29 | - return; | |
| 30 | - } | |
| 31 | - | |
| 32 | - const elItemCurrent = $( '.course-item-' + idItem ); | |
| 33 | - elItemCurrent.addClass( 'current' ); | |
| 34 | - const offSetTop = elItemCurrent.offset().top; | |
| 35 | - const offset = elItemCurrent.offset().top - elCourseCurriculumn.offset().top + | |
| 36 | - elCourseCurriculumn.scrollTop(); | |
| 37 | - | |
| 38 | - elCourseCurriculumn.animate( { | |
| 39 | - scrollTop: LP.Hook.applyFilters( 'scroll-item-current', offset - heightSectionHeader ), | |
| 40 | - }, 800 ); | |
| 41 | - } | |
| 42 | - }; | |
| 43 | - this.scrollToItemViewing(); | |
| 44 | - }, | |
| 45 | -}; | |
| 46 | - | |
| 47 | -export default scrollToItemCurrent; | |
| 1 | +import lpModalOverlay from '../../utils/lp-modal-overlay'; | |
| 2 | + | |
| 3 | +const $ = jQuery; | |
| 4 | + | |
| 5 | +const scrollToItemCurrent = { | |
| 6 | + init() { | |
| 7 | + this.scrollToItemViewing = function() { | |
| 8 | + const elItemViewing = $( '.viewing-course-item' ); | |
| 9 | + if ( elItemViewing.length ) { | |
| 10 | + const elCourseCurriculumn = $( '#learn-press-course-curriculum' ); | |
| 11 | + const heightCourseItemContentHeader = $( '#popup-sidebar' ).outerHeight(); | |
| 12 | + const heightSectionTitle = $( '.section-title' ).outerHeight(); | |
| 13 | + const heightSectionHeader = $( '.section-header' ).outerHeight(); | |
| 14 | + const regex = new RegExp( '^viewing-course-item-([0-9].*)' ); | |
| 15 | + const classList = elItemViewing.attr( 'class' ); | |
| 16 | + const classArr = classList.split( /\s+/ ); | |
| 17 | + let idItem = 0; | |
| 18 | + | |
| 19 | + $.each( classArr, function( i, className ) { | |
| 20 | + const compare = regex.exec( className ); | |
| 21 | + | |
| 22 | + if ( compare ) { | |
| 23 | + idItem = compare[ 1 ]; | |
| 24 | + return false; | |
| 25 | + } | |
| 26 | + } ); | |
| 27 | + | |
| 28 | + if ( 0 === idItem ) { | |
| 29 | + return; | |
| 30 | + } | |
| 31 | + | |
| 32 | + const elItemCurrent = $( '.course-item-' + idItem ); | |
| 33 | + elItemCurrent.addClass( 'current' ); | |
| 34 | + const offSetTop = elItemCurrent.offset().top; | |
| 35 | + const offset = elItemCurrent.offset().top - elCourseCurriculumn.offset().top + | |
| 36 | + elCourseCurriculumn.scrollTop(); | |
| 37 | + | |
| 38 | + elCourseCurriculumn.animate( { | |
| 39 | + scrollTop: LP.Hook.applyFilters( 'scroll-item-current', offset - heightSectionHeader ), | |
| 40 | + }, 800 ); | |
| 41 | + } | |
| 42 | + }; | |
| 43 | + this.scrollToItemViewing(); | |
| 44 | + }, | |
| 45 | +}; | |
| 46 | + | |
| 47 | +export default scrollToItemCurrent; | |