Skip to content

Commit

Permalink
Merge pull request #6508 from smithellis/2111-browser-navigation-disa…
Browse files Browse the repository at this point in the history
…bled

Fix browser back navigation on revision list pages
  • Loading branch information
akatsoulas authored Feb 14, 2025
2 parents 6d3e580 + b66de4e commit 0e513e6
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions kitsune/sumo/static/sumo/js/wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ import collapsibleAccordionInit from "sumo/js/protocol-details-init";
updateRevisionList();
}

function updateRevisionList(query) {
function updateRevisionList(query, pushState = true) {
if (query === undefined) {
query = $form.serialize();
}
Expand All @@ -680,12 +680,24 @@ import collapsibleAccordionInit from "sumo/js/protocol-details-init";
$('.loading').hide();
$('#revisions-fragment').html(data).css('opacity', 1);

// Update URL without triggering page reload
const newUrl = window.location.pathname + query;
window.history.pushState({}, '', newUrl);
// Only update URL if pushState is true
if (pushState) {
const newUrl = window.location.pathname + query;
window.history.pushState({query: query}, '', newUrl);
}
});
}

// Handle browser back/forward buttons
window.addEventListener('popstate', function(event) {
if (event.state && event.state.query) {
updateRevisionList(event.state.query, false);
} else {
// Handle the initial state
updateRevisionList(window.location.search, false);
}
});

// Handle filter changes
var timeout;
$form.on('input change', 'input, select', function () {
Expand Down Expand Up @@ -721,7 +733,6 @@ import collapsibleAccordionInit from "sumo/js/protocol-details-init";
});
}


init();

function makeWikiCollapsable() {
Expand Down

0 comments on commit 0e513e6

Please sign in to comment.