Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix browser native back button behavior #1269

Merged
merged 7 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
- Liquid: Make project-level collections available for Liquid syntax
- Upgraded gems: nokogiri, rails, rexml
- Bugs fixes:
- [entity]:
- [future tense verb] [bug fix]
- Navigation: Restore functionality of native browser back/forward buttons
- Bug tracker items:
- [item]
- New integrations:
Expand Down
20 changes: 15 additions & 5 deletions app/assets/javascripts/shared/behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,21 @@
}

// Update address bar with current tab param
$('[data-bs-toggle~=tab]').on('shown.bs.tab', function (e) {
let currentTab = $(e.target).attr('href').substring(1);
searchParams.set('tab', currentTab);
history.pushState(null, null, `?${searchParams.toString()}`);
});
$('[data-bs-toggle~=tab]')
.unbind()
MattBudz marked this conversation as resolved.
Show resolved Hide resolved
.on('shown.bs.tab', function (e) {
let currentTab = $(e.target).attr('href').substring(1);
searchParams.set('tab', currentTab);
history.pushState(null, null, `?${searchParams.toString()}`);
});

// Allows users to navigate using the native browser back/forward buttons
// even when we manipulate the browser history with pushState()
$(window)
.unbind()
MattBudz marked this conversation as resolved.
Show resolved Hide resolved
.on('popstate', function () {
location.reload();
});
}

document.addEventListener('turbolinks:load', function () {
Expand Down
Loading