diff --git a/app/assets/javascripts/lectures_admin.js b/app/assets/javascripts/lectures_admin.js index 6231f2e38..9839ab2c4 100644 --- a/app/assets/javascripts/lectures_admin.js +++ b/app/assets/javascripts/lectures_admin.js @@ -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 @@ -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"); @@ -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(); +});