| @@ -1,65 +1,65 @@ | ||
| 1 | -/** | |
| 2 | - * Handle click tab call API | |
| 3 | - * | |
| 4 | - * @since 4.2.8.2 | |
| 5 | - * @version 1.0.0 | |
| 6 | - */ | |
| 7 | -const profileQuizTab = () => { | |
| 8 | - const handleClickTab = ( e, target ) => { | |
| 9 | - if ( target.closest( 'span' ) ) { | |
| 10 | - const elParent = target.closest( '#profile-content-quizzes' ); | |
| 11 | - if ( ! elParent ) { | |
| 12 | - return; | |
| 13 | - } | |
| 14 | - | |
| 15 | - const elLPTarget = target.closest( '.lp-target' ); | |
| 16 | - if ( ! elLPTarget ) { | |
| 17 | - return; | |
| 18 | - } | |
| 19 | - | |
| 20 | - window.lpAJAXG.showHideLoading( elLPTarget, 1 ); | |
| 21 | - const dataSendJson = elLPTarget?.dataset?.send || {}; | |
| 22 | - const dataSend = JSON.parse( dataSendJson ); | |
| 23 | - | |
| 24 | - const elTabChoice = target?.dataset?.filter || 'all'; | |
| 25 | - | |
| 26 | - const liActive = elParent.querySelector( 'li.active' ); | |
| 27 | - if ( liActive.classList.contains( elTabChoice ) ) { | |
| 28 | - return; | |
| 29 | - } | |
| 30 | - | |
| 31 | - liActive.classList.remove( 'active' ); | |
| 32 | - const liTarget = target.closest( 'li' ); | |
| 33 | - liTarget.classList.add( 'active' ); | |
| 34 | - | |
| 35 | - dataSend.args.type = elTabChoice; | |
| 36 | - | |
| 37 | - // Load list courses by AJAX. | |
| 38 | - const callBack = { | |
| 39 | - success: ( response ) => { | |
| 40 | - const { data, message, status } = response; | |
| 41 | - | |
| 42 | - if ( 'success' === status ) { | |
| 43 | - elLPTarget.innerHTML = data.content || ''; | |
| 44 | - } | |
| 45 | - }, | |
| 46 | - error: ( error ) => { | |
| 47 | - console.log( error ); | |
| 48 | - }, | |
| 49 | - completed: () => { | |
| 50 | - window.lpAJAXG.showHideLoading( elLPTarget, 0 ); | |
| 51 | - }, | |
| 52 | - }; | |
| 53 | - | |
| 54 | - window.lpAJAXG.fetchAJAX( dataSend, callBack ); | |
| 55 | - } | |
| 56 | - }; | |
| 57 | - | |
| 58 | - document.addEventListener( 'click', ( e ) => { | |
| 59 | - const target = e.target; | |
| 60 | - | |
| 61 | - handleClickTab( e, target ); | |
| 62 | - } ); | |
| 63 | -}; | |
| 64 | - | |
| 65 | -export default profileQuizTab; | |
| 1 | +/** | |
| 2 | + * Handle click tab call API | |
| 3 | + * | |
| 4 | + * @since 4.2.8.2 | |
| 5 | + * @version 1.0.0 | |
| 6 | + */ | |
| 7 | +const profileQuizTab = () => { | |
| 8 | + const handleClickTab = ( e, target ) => { | |
| 9 | + if ( target.closest( 'span' ) ) { | |
| 10 | + const elParent = target.closest( '#profile-content-quizzes' ); | |
| 11 | + if ( ! elParent ) { | |
| 12 | + return; | |
| 13 | + } | |
| 14 | + | |
| 15 | + const elLPTarget = target.closest( '.lp-target' ); | |
| 16 | + if ( ! elLPTarget ) { | |
| 17 | + return; | |
| 18 | + } | |
| 19 | + | |
| 20 | + window.lpAJAXG.showHideLoading( elLPTarget, 1 ); | |
| 21 | + const dataSendJson = elLPTarget?.dataset?.send || {}; | |
| 22 | + const dataSend = JSON.parse( dataSendJson ); | |
| 23 | + | |
| 24 | + const elTabChoice = target?.dataset?.filter || 'all'; | |
| 25 | + | |
| 26 | + const liActive = elParent.querySelector( 'li.active' ); | |
| 27 | + if ( liActive.classList.contains( elTabChoice ) ) { | |
| 28 | + return; | |
| 29 | + } | |
| 30 | + | |
| 31 | + liActive.classList.remove( 'active' ); | |
| 32 | + const liTarget = target.closest( 'li' ); | |
| 33 | + liTarget.classList.add( 'active' ); | |
| 34 | + | |
| 35 | + dataSend.args.type = elTabChoice; | |
| 36 | + | |
| 37 | + // Load list courses by AJAX. | |
| 38 | + const callBack = { | |
| 39 | + success: ( response ) => { | |
| 40 | + const { data, message, status } = response; | |
| 41 | + | |
| 42 | + if ( 'success' === status ) { | |
| 43 | + elLPTarget.innerHTML = data.content || ''; | |
| 44 | + } | |
| 45 | + }, | |
| 46 | + error: ( error ) => { | |
| 47 | + console.log( error ); | |
| 48 | + }, | |
| 49 | + completed: () => { | |
| 50 | + window.lpAJAXG.showHideLoading( elLPTarget, 0 ); | |
| 51 | + }, | |
| 52 | + }; | |
| 53 | + | |
| 54 | + window.lpAJAXG.fetchAJAX( dataSend, callBack ); | |
| 55 | + } | |
| 56 | + }; | |
| 57 | + | |
| 58 | + document.addEventListener( 'click', ( e ) => { | |
| 59 | + const target = e.target; | |
| 60 | + | |
| 61 | + handleClickTab( e, target ); | |
| 62 | + } ); | |
| 63 | +}; | |
| 64 | + | |
| 65 | +export default profileQuizTab; | |