Skip to content

Commit 2e2e10e

Browse files
authored
Update script.js
1 parent a7181fb commit 2e2e10e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

js/script.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ document.addEventListener("DOMContentLoaded", function () {
77
const contributors = Array.from(contributorsList.getElementsByClassName("contributor-item"));
88
const totalContributors = contributors.length;
99

10-
// Function to toggle contributors visibility
10+
// Function to toggle visibility of contributors
1111
function toggleContributors() {
1212
const isExpanded = toggleContributorsLink.textContent.includes("View Less");
1313

1414
// Toggle visibility
1515
contributors.forEach((contributor, index) => {
1616
if (index >= maxVisibleContributors) {
1717
if (isExpanded) {
18-
contributor.classList.add("d-none");
18+
contributor.classList.add("d-none"); // Hide beyond maxVisibleContributors
1919
} else {
20-
contributor.classList.remove("d-none");
20+
contributor.classList.remove("d-none"); // Show all contributors
2121
}
2222
}
2323
});
@@ -28,13 +28,20 @@ document.addEventListener("DOMContentLoaded", function () {
2828
: "View Less";
2929
}
3030

31-
// Add the click event listener
31+
// Initial setup to ensure only the first 5 contributors are visible
32+
contributors.forEach((contributor, index) => {
33+
if (index >= maxVisibleContributors) {
34+
contributor.classList.add("d-none"); // Hide contributors beyond maxVisibleContributors
35+
}
36+
});
37+
38+
// Set the initial link text
39+
toggleContributorsLink.textContent = `+${totalContributors - maxVisibleContributors} more Contributors`;
40+
41+
// Add click event listener
3242
toggleContributorsLink.addEventListener("click", function (e) {
3343
e.preventDefault();
3444
toggleContributors();
3545
});
36-
37-
// Initial state setup (if necessary)
38-
toggleContributors(); // Ensure initial DOM state matches the button state
3946
}
4047
});

0 commit comments

Comments
 (0)