Skip to content

Commit 6fcb6e4

Browse files
authored
Update script.js
1 parent 9081e3b commit 6fcb6e4

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

js/script.js

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
11
document.addEventListener("DOMContentLoaded", function () {
2-
const toggleContributorsLink = document.getElementById("toggleContributors");
3-
const contributorsList = document.getElementById("contributorsList");
4-
const maxVisibleContributors = 5;
5-
6-
// Only proceed if there are more than maxVisibleContributors
7-
if (toggleContributorsLink) {
8-
const contributors = Array.from(contributorsList.getElementsByClassName("contributor-item"));
9-
const totalContributors = contributors.length;
2+
const toggleContributorsLink = document.getElementById("toggleContributors");
3+
const contributorsList = document.getElementById("contributorsList");
4+
const maxVisibleContributors = 5;
105

11-
// Set the initial state to show only the first 5 contributors
12-
function toggleContributors() {
13-
const isShowingAll = toggleContributorsLink.textContent === "View Less";
14-
15-
// Show or hide contributors beyond the first 5
16-
contributors.forEach((contributor, index) => {
17-
if (isShowingAll || index < maxVisibleContributors) {
18-
contributor.classList.remove("d-none");
19-
} else {
20-
contributor.classList.add("d-none");
21-
}
22-
});
6+
if (toggleContributorsLink) {
7+
const contributors = Array.from(contributorsList.getElementsByClassName("contributor-item"));
8+
const totalContributors = contributors.length;
239

24-
// Toggle the link text based on the current state
25-
if (isShowingAll) {
26-
toggleContributorsLink.textContent = `+${totalContributors - maxVisibleContributors} more Contributors`;
10+
// Function to toggle contributors visibility
11+
function toggleContributors() {
12+
const isShowingAll = toggleContributorsLink.textContent === "View Less";
13+
14+
// Show or hide contributors based on the current state
15+
contributors.forEach((contributor, index) => {
16+
if (isShowingAll || index < maxVisibleContributors) {
17+
contributor.classList.remove("d-none");
2718
} else {
28-
toggleContributorsLink.textContent = "View Less";
19+
contributor.classList.add("d-none");
2920
}
21+
});
22+
23+
// Update the button text
24+
if (isShowingAll) {
25+
toggleContributorsLink.textContent = `+${totalContributors - maxVisibleContributors} more Contributors`;
26+
} else {
27+
toggleContributorsLink.textContent = "View Less";
3028
}
29+
}
3130

32-
// Initial call to ensure the first 5 contributors are shown
33-
toggleContributors();
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+
});
3437

35-
// Event listener for clicking the toggle link
36-
toggleContributorsLink.addEventListener("click", function (e) {
37-
e.preventDefault();
38-
toggleContributors(); // Toggle contributors and update link text
39-
});
40-
}
41-
});
38+
// Set the initial button text
39+
toggleContributorsLink.textContent = `+${totalContributors - maxVisibleContributors} more Contributors`;
40+
41+
// Add the click event listener
42+
toggleContributorsLink.addEventListener("click", function (e) {
43+
e.preventDefault();
44+
toggleContributors(); // Toggle visibility and update text
45+
});
46+
}
47+
});

0 commit comments

Comments
 (0)