@@ -3,15 +3,25 @@ document.addEventListener("DOMContentLoaded", function () {
3
3
const contributorsList = document . getElementById ( "contributorsList" ) ;
4
4
const maxVisibleContributors = 5 ;
5
5
6
- if ( toggleContributorsLink ) {
6
+ if ( toggleContributorsLink && contributorsList ) {
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
+
10
20
// Function to toggle contributors visibility
11
21
function toggleContributors ( ) {
12
22
const isShowingAll = toggleContributorsLink . textContent === "View Less" ;
13
-
14
- // Show or hide contributors based on the current state
23
+
24
+ // Toggle visibility
15
25
contributors . forEach ( ( contributor , index ) => {
16
26
if ( isShowingAll || index < maxVisibleContributors ) {
17
27
contributor . classList . remove ( "d-none" ) ;
@@ -21,27 +31,15 @@ document.addEventListener("DOMContentLoaded", function () {
21
31
} ) ;
22
32
23
33
// Update the button text
24
- if ( isShowingAll ) {
25
- toggleContributorsLink . textContent = `+${ totalContributors - maxVisibleContributors } more Contributors` ;
26
- } else {
27
- toggleContributorsLink . textContent = "View Less" ;
28
- }
34
+ toggleContributorsLink . textContent = isShowingAll
35
+ ? `+${ totalContributors - maxVisibleContributors } more Contributors`
36
+ : "View Less" ;
29
37
}
30
38
31
- // Initialize the state (start with showing only the first 5)
32
- contributors . forEach ( ( contributor , index ) => {
33
- if ( index >= maxVisibleContributors ) {
34
- contributor . classList . add ( "d-none" ) ;
35
- }
36
- } ) ;
37
-
38
- // Set the initial button text
39
- toggleContributorsLink . textContent = `+${ totalContributors - maxVisibleContributors } more Contributors` ;
40
-
41
39
// Add the click event listener
42
40
toggleContributorsLink . addEventListener ( "click" , function ( e ) {
43
41
e . preventDefault ( ) ;
44
- toggleContributors ( ) ; // Toggle visibility and update text
42
+ toggleContributors ( ) ;
45
43
} ) ;
46
44
}
47
45
} ) ;
0 commit comments