Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Initiatives by permalink #363

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/_includes/initiatives.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ <h2 class="h1 text-center text-lg-start">Explore our initiatives</h2>
class="nav-link {{ initiative.active }}"
id="pills-{{ initiative.slug }}-tab"
data-bs-toggle="pill"
data-bs-target="#pills-{{ initiative.slug }}"
data-bs-target="#initiatives-{{ initiative.slug }}"
type="button"
role="tab"
aria-controls="pills-{{ initiative.slug }}"
aria-controls="initiatives-{{ initiative.slug }}"
aria-selected="true"
>
{{ initiative.tag }}
Expand All @@ -35,10 +35,10 @@ <h2 class="h1 text-center text-lg-start">Explore our initiatives</h2>
<div class="tab-content" id="pills-tabContent">
{% for initiative in site.data.initiatives %}
<div
class="tab-pane fade {{ initiative.active }}"
id="pills-{{ initiative.slug }}"
class="tab-pane fade scroll-link {{ initiative.active }}"
id="initiatives-{{ initiative.slug }}"
role="tabpanel"
aria-labelledby="pills-{{ initiative.slug }}-tab"
aria-labelledby="initiatives-{{ initiative.slug }}-tab"
tabindex="0"
>
<div
Expand Down Expand Up @@ -116,3 +116,5 @@ <h4 class="small-caps text-white mb-3">Resources</h4>
</div>
{% endfor %}
</div>

<script src="/scripts/initiatives.js"></script>
3 changes: 2 additions & 1 deletion src/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"
crossorigin="anonymous"></script>
crossorigin="anonymous"
></script>
</body>
</html>
16 changes: 16 additions & 0 deletions src/scripts/initiatives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
window.addEventListener("load", () => {
const triggerTabList = document.querySelectorAll("#pills-tab button");
triggerTabList.forEach((triggerEl) => {
const tabTrigger = new bootstrap.Tab(triggerEl);

triggerEl.addEventListener("click", (event) => {
event.preventDefault();
tabTrigger.show();
});
});

if (window.location.hash.startsWith("#initiatives")) {
const triggerEl = document.querySelector("button[data-bs-target='" + window.location.hash + "']");
bootstrap.Tab.getInstance(triggerEl).show();
}
});
4 changes: 4 additions & 0 deletions src/stylesheets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ footer a:hover {
border-style: solid;
}

.scroll-link {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows the anchor link to scroll an extra 240px (roughly double the height of the top nav), so that the anchor scrolls to here
image

instead of here:
image

In this scenario, the Explore the intiatives is hidden by the sticky nav.

scroll-margin-top: 240px;
}

.black-on-white .nav-pills {
--bs-nav-pills-link-active-color: var(--bs-white);
--bs-nav-pills-link-active-bg: var(--bs-body-color);
Expand Down