Prevent adding new history entries when switching tabs. (#1617)

Affects issues:
- Close #1318
This commit is contained in:
FluxCapacitor 2020-10-19 14:49:38 -04:00 committed by GitHub
parent d0491a0dec
commit 5ab0e8ffdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,13 +51,26 @@ for (let tab of tabs) {
window.addEventListener('hashchange', openPage); window.addEventListener('hashchange', openPage);
//Sidebar navigation tabs
$('#accordionSidebar .nav-item a').click(event => {
if(history.replaceState) {
event.preventDefault();
history.replaceState(undefined, undefined, '#' + event.currentTarget.href.split('#')[1]);
openPage();
}
});
// Persistent Bootstrap tabs // Persistent Bootstrap tabs
$('.nav-tabs a.nav-link').click(event => { $('.nav-tabs a.nav-link').click(event => {
const uriHash = (window.location.hash).split("&"); const uriHash = (window.location.hash).split("&");
if (!uriHash) return; if (!uriHash) return;
const currentTab = uriHash[0]; const currentTab = uriHash[0];
const originalTargetId = event.currentTarget.href.split('#')[1]; const originalTargetId = event.currentTarget.href.split('#')[1];
window.location.hash = currentTab + '&' + originalTargetId; if(history.replaceState) {
event.preventDefault();
history.replaceState(undefined, undefined, currentTab + '&' + originalTargetId);
openPage();
} else window.location.hash = currentTab + '&' + originalTargetId;
}); });
let oldWidth = null; let oldWidth = null;