|
1 | 1 | 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; |
10 | 5 |
|
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; |
23 | 9 |
|
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"); |
27 | 18 | } else {
|
28 |
| - toggleContributorsLink.textContent = "View Less"; |
| 19 | + contributor.classList.add("d-none"); |
29 | 20 | }
|
| 21 | + }); |
| 22 | + |
| 23 | + // Update the button text |
| 24 | + if (isShowingAll) { |
| 25 | + toggleContributorsLink.textContent = `+${totalContributors - maxVisibleContributors} more Contributors`; |
| 26 | + } else { |
| 27 | + toggleContributorsLink.textContent = "View Less"; |
30 | 28 | }
|
| 29 | + } |
31 | 30 |
|
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 | + }); |
34 | 37 |
|
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