@@ -7,31 +7,23 @@ document.addEventListener("DOMContentLoaded", function () {
77 const contributors = Array . from ( contributorsList . getElementsByClassName ( "contributor-item" ) ) ;
88 const totalContributors = contributors . length ;
99
10- // Initialize: Set the correct state for the button and list
11- const initState = toggleContributorsLink . textContent . includes ( "more" ) ;
12- if ( initState ) {
13- contributors . forEach ( ( contributor , index ) => {
14- if ( index >= maxVisibleContributors ) {
15- contributor . classList . add ( "d-none" ) ;
16- }
17- } ) ;
18- }
19-
2010 // Function to toggle contributors visibility
2111 function toggleContributors ( ) {
22- const isShowingAll = toggleContributorsLink . textContent === "View Less" ;
12+ const isExpanded = toggleContributorsLink . textContent . includes ( "View Less" ) ;
2313
2414 // Toggle visibility
2515 contributors . forEach ( ( contributor , index ) => {
26- if ( isShowingAll || index < maxVisibleContributors ) {
27- contributor . classList . remove ( "d-none" ) ;
28- } else {
29- contributor . classList . add ( "d-none" ) ;
16+ if ( index >= maxVisibleContributors ) {
17+ if ( isExpanded ) {
18+ contributor . classList . add ( "d-none" ) ;
19+ } else {
20+ contributor . classList . remove ( "d-none" ) ;
21+ }
3022 }
3123 } ) ;
3224
33- // Update the button text
34- toggleContributorsLink . textContent = isShowingAll
25+ // Update the link text
26+ toggleContributorsLink . textContent = isExpanded
3527 ? `+${ totalContributors - maxVisibleContributors } more Contributors`
3628 : "View Less" ;
3729 }
@@ -41,5 +33,8 @@ document.addEventListener("DOMContentLoaded", function () {
4133 e . preventDefault ( ) ;
4234 toggleContributors ( ) ;
4335 } ) ;
36+
37+ // Initial state setup (if necessary)
38+ toggleContributors ( ) ; // Ensure initial DOM state matches the button state
4439 }
4540} ) ;
0 commit comments