Skip to content

Commit

Permalink
Fix broken browser navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed May 27, 2024
1 parent 75d6074 commit c18c46e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/assets/javascripts/lectures_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*
* This is necessary to be able to share the URL with a specific tab open.
* It also allows to stay on the same tab after a page reload
* (which is done when an edit action is canceled).
* (which is done when an edit action is saved/canceled,
* also see the lectures controller update action).
*
* Find out more details in this guide:
* https://webdesign.tutsplus.com/how-to-add-deep-linking-to-the-bootstrap-4-tabs-component--cms-31180t
Expand All @@ -14,9 +15,11 @@ function configureUrlHashesForBootstrapTabs() {
const hash = $(this).attr("href");
const urlWithoutHash = location.href.split("#")[0];
const newUrl = `${urlWithoutHash}${hash}`;
history.replaceState(null, null, newUrl);
history.pushState(null, "", newUrl);
});
}

function navigateToActiveNavTab() {
if (location.hash) {
const hrefXPathIdentifier = `button[href="${location.hash}"]`;
$(`#lecture-nav-pills ${hrefXPathIdentifier}`).tab("show");
Expand All @@ -29,9 +32,14 @@ function configureUrlHashesForBootstrapTabs() {
$(document).on("ready turbolinks:load", function () {
initBootstrapPopovers();
configureUrlHashesForBootstrapTabs();
navigateToActiveNavTab();

// Reinitialize the masonry grid system when the lecture content is shown
$("#lecture-nav-content").on("focus click", () => {
initMasonryGridSystem();
});
});

$(window).on("hashchange", function () {
navigateToActiveNavTab();
});

0 comments on commit c18c46e

Please sign in to comment.