Skip to content

Commit 7488473

Browse files
authored
Create script.js
1 parent f45b477 commit 7488473

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

js/script.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
document.addEventListener("DOMContentLoaded", function () {
2+
const contributorsList = document.querySelector("#contributorsList");
3+
const toggleContributorsLink = document.getElementById("toggleContributors");
4+
const maxVisibleContributors = 5;
5+
6+
const contributors = Array.from(contributorsList.getElementsByClassName("contributor-item"));
7+
const totalContributors = contributors.length;
8+
9+
// Function to toggle between showing more or fewer contributors
10+
function toggleContributors() {
11+
const isShowingAll = toggleContributorsLink.textContent === "View Less";
12+
13+
contributors.forEach((contributor, index) => {
14+
if (isShowingAll || index < maxVisibleContributors) {
15+
contributor.classList.remove("d-none");
16+
} else {
17+
contributor.classList.add("d-none");
18+
}
19+
});
20+
21+
if (isShowingAll) {
22+
toggleContributorsLink.textContent = `+${totalContributors - maxVisibleContributors} more Contributors`;
23+
} else {
24+
toggleContributorsLink.textContent = "View Less";
25+
}
26+
}
27+
28+
if (toggleContributorsLink) {
29+
toggleContributorsLink.addEventListener("click", function (e) {
30+
e.preventDefault();
31+
toggleContributors();
32+
});
33+
}
34+
});

0 commit comments

Comments
 (0)