| 1 |
/** |
| 2 |
* Toogle form Comment for Lesson. |
| 3 |
* |
| 4 |
* @author Nhamdv. |
| 5 |
*/ |
| 6 |
|
| 7 |
export const commentForm = () => { |
| 8 |
const btn = document.querySelector( '.lp-lesson-comment-btn' ); |
| 9 |
|
| 10 |
if ( ! btn ) { |
| 11 |
return; |
| 12 |
} |
| 13 |
|
| 14 |
const btnOpen = btn.textContent; |
| 15 |
const btnClose = btn.dataset.close; |
| 16 |
const hashComment = window.location.hash; |
| 17 |
|
| 18 |
if ( hashComment.includes( 'comment' ) ) { |
| 19 |
btn.parentNode.classList.add( 'open-comments' ); |
| 20 |
} |
| 21 |
|
| 22 |
const toogleText = ( btn, btnParent ) => { |
| 23 |
if ( btnParent.classList.contains( 'open-comments' ) ) { |
| 24 |
btn.textContent = btnClose; |
| 25 |
} else { |
| 26 |
btn.textContent = btnOpen; |
| 27 |
} |
| 28 |
}; |
| 29 |
|
| 30 |
toogleText( btn, btn.parentNode ); |
| 31 |
|
| 32 |
btn.addEventListener( 'click', ( e ) => { |
| 33 |
e.preventDefault(); |
| 34 |
|
| 35 |
btn.parentNode.classList.toggle( 'open-comments' ); |
| 36 |
toogleText( btn, btn.parentNode ); |
| 37 |
} ); |
| 38 |
|
| 39 |
// Use for Rest API. |
| 40 |
// const toogle = $( '#learn-press-item-comments-toggle' ); |
| 41 |
|
| 42 |
// toogle.on( 'change', async function() { |
| 43 |
// if ( ! toogle[ 0 ].checked ) { |
| 44 |
// return; |
| 45 |
// } |
| 46 |
|
| 47 |
// const response = await wp.apiFetch( { |
| 48 |
// path: 'lp/v1/courses/339/item-comments/50', |
| 49 |
// } ); |
| 50 |
|
| 51 |
// $( '.learn-press-comments' ).html( response.comments ); |
| 52 |
// } ); |
| 53 |
}; |
| 54 |
|