Skip to content

Commit

Permalink
Sæt navigation url for specifikke faneblade
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmusselsmark committed Aug 20, 2023
1 parent f5317e6 commit 27f4347
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions members/static/members/js/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ document.addEventListener("DOMContentLoaded", function(event) {
const urlFragment = window.location.hash.substring(1); // Remove the '#' char

// Default to the first list item as active if the ID is not provided or doesn't match any item
const activeIndex = tabButtons.findIndex(button => button.id === urlFragment);
// we use custom attribute data-navigation to set the "navigation url" for tab
const activeIndex = tabButtons.findIndex(button => button.dataset.navigation === urlFragment);
const defaultIndex = activeIndex !== -1 ? activeIndex : 0;

// Default to first as active
Expand All @@ -38,6 +39,9 @@ function toggleActive(sections, buttons, activeIndex) {
sections[activeIndex].hidden = false;

// set url to include the tab identifier. we overwrite url, since tabs doesn't work otherwise
const newUrl = window.location.pathname + `#${buttons[activeIndex].id}`;
window.history.replaceState({}, "", newUrl);
// we use custom attribute data-navigation to set the url for tab
if (buttons[activeIndex].dataset.navigation) {
const newUrl = window.location.pathname + `#${buttons[activeIndex].dataset.navigation}`;
window.history.replaceState({}, "", newUrl);
}
}
6 changes: 3 additions & 3 deletions members/templates/members/activities.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ <h2>Aktiviteter i Coding Pirates</h2>
<div class="tabs" id="tab-menu">
<ul>
{% if family %}
<li id="tab-invitationer">Invitationer</li>
<li id="tab-invitationer" data-navigation="invitationer">Invitationer</li>
{% endif %}
<li id="tab-aktiviteter">Nuværende og kommende aktiviteter</li>
<li id="tab-aktiviteter" data-navigation="aktiviteter">Nuværende og kommende aktiviteter</li>
{% if family %}
<li id="tab-tilmeldte-aktiviteter">Tilmeldte aktiviteter</li>
<li id="tab-tilmeldte-aktiviteter" data-navigation="tilmeldte-aktiviteter">Tilmeldte aktiviteter</li>
{% endif %}
</ul>

Expand Down
2 changes: 1 addition & 1 deletion members/views/ActivitySignup.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def ActivitySignup(request, activity_id, person_id=None):
participant.save()

# return user to list of activities where they are participating
return_link_url = f'{reverse("activities")}#tab-tilmeldte-aktiviteter'
return_link_url = f'{reverse("activities")}#tilmeldte-aktiviteter'

# Make payment if activity costs
if activity.price_in_dkk is not None and activity.price_in_dkk > 0:
Expand Down

0 comments on commit 27f4347

Please sign in to comment.