Skip to content

Commit

Permalink
Merge pull request #1269 from dradis/navigation/fix-back-button-behavior
Browse files Browse the repository at this point in the history
Fix browser native back button behavior
  • Loading branch information
MattBudz authored Jun 26, 2024
2 parents 6093383 + 489b982 commit 8f1ed61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
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
17 changes: 12 additions & 5 deletions app/assets/javascripts/shared/behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,18 @@
}

// 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()}`);
});
$(parentElement)
.find('[data-bs-toggle~=tab]')
.on('shown.bs.tab', function (e) {
let currentTab = $(e.target).attr('href').substring(1);
searchParams.set('tab', currentTab);
let urlWithTab = `?${searchParams.toString()}`;
history.pushState(
{ turbolinks: true, url: urlWithTab },
'',
urlWithTab
);
});
}

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

0 comments on commit 8f1ed61

Please sign in to comment.