@@ -7,31 +7,23 @@ document.addEventListener("DOMContentLoaded", function () {
7
7
const contributors = Array . from ( contributorsList . getElementsByClassName ( "contributor-item" ) ) ;
8
8
const totalContributors = contributors . length ;
9
9
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
-
20
10
// Function to toggle contributors visibility
21
11
function toggleContributors ( ) {
22
- const isShowingAll = toggleContributorsLink . textContent === "View Less" ;
12
+ const isExpanded = toggleContributorsLink . textContent . includes ( "View Less" ) ;
23
13
24
14
// Toggle visibility
25
15
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
+ }
30
22
}
31
23
} ) ;
32
24
33
- // Update the button text
34
- toggleContributorsLink . textContent = isShowingAll
25
+ // Update the link text
26
+ toggleContributorsLink . textContent = isExpanded
35
27
? `+${ totalContributors - maxVisibleContributors } more Contributors`
36
28
: "View Less" ;
37
29
}
@@ -41,5 +33,8 @@ document.addEventListener("DOMContentLoaded", function () {
41
33
e . preventDefault ( ) ;
42
34
toggleContributors ( ) ;
43
35
} ) ;
36
+
37
+ // Initial state setup (if necessary)
38
+ toggleContributors ( ) ; // Ensure initial DOM state matches the button state
44
39
}
45
40
} ) ;
0 commit comments