Added URL fragment support for tabs
This commit is contained in:
10
www/main.js
10
www/main.js
@ -44,6 +44,12 @@ function switchTab(tabID, playAnimation=true) {
|
||||
tabID = tabID.id.split('button-')[1];
|
||||
}
|
||||
|
||||
if (currentTab == tabID) { return; }
|
||||
|
||||
console.log(`Switching from ${currentTab} to ${tabID}...`);
|
||||
currentTab = tabID;
|
||||
location.hash = `#${tabID}`;
|
||||
|
||||
let tabTransitionTime = Number(getComputedStyle(document.body).getPropertyValue('--tab-transition-time').slice(0, -2));
|
||||
let tabs = document.getElementsByTagName('main')[0].children;
|
||||
let tab = document.getElementById(`tab-${tabID}`);
|
||||
@ -94,6 +100,10 @@ function switchTab(tabID, playAnimation=true) {
|
||||
button.classList.add('buttonHighlight');
|
||||
}
|
||||
|
||||
window.addEventListener('hashchange', (e) => {
|
||||
switchTab(location.hash.slice(1));
|
||||
});
|
||||
|
||||
window.addEventListener('load', (e) => {
|
||||
switchTab('home', false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user