From 27f4347df287ffa228873c995a99a029d8bbaeea Mon Sep 17 00:00:00 2001 From: Rasmus Selsmark Date: Sun, 20 Aug 2023 16:43:39 +0200 Subject: [PATCH] =?UTF-8?q?S=C3=A6t=20navigation=20url=20for=20specifikke?= =?UTF-8?q?=20faneblade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- members/static/members/js/tab.js | 10 +++++++--- members/templates/members/activities.html | 6 +++--- members/views/ActivitySignup.py | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/members/static/members/js/tab.js b/members/static/members/js/tab.js index 86e5b693..b337d04e 100644 --- a/members/static/members/js/tab.js +++ b/members/static/members/js/tab.js @@ -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 @@ -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); + } } diff --git a/members/templates/members/activities.html b/members/templates/members/activities.html index be347182..1735bbe2 100644 --- a/members/templates/members/activities.html +++ b/members/templates/members/activities.html @@ -15,11 +15,11 @@

Aktiviteter i Coding Pirates

diff --git a/members/views/ActivitySignup.py b/members/views/ActivitySignup.py index 8470a051..3cf63305 100644 --- a/members/views/ActivitySignup.py +++ b/members/views/ActivitySignup.py @@ -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: