[+] Create constructor

This commit is contained in:
Hykilpikonna
2019-12-21 11:52:16 -05:00
parent e6cfa30ed4
commit 4d7b41bf2a
+24
View File
@@ -11,6 +11,30 @@ export default class Navigator
private activeIndex: Index;
private updateCallback?: () => void;
constructor()
{
// Set history state
let url = '/' + window.location.hash;
if (url == '/' || url == '') url = '/#overall';
window.history.replaceState({lastTab: url.substring(1)}, '', url);
// Update initial index after loading is done
// TODO: Test this
//pWaitFor(() => this.courses.length > 1 && App.instance.loading != '').then(() =>
this.updateIndex(url.substring(2), false);
// Create history state listener
window.onpopstate = (e: any) =>
{
if (e.state)
{
// Restore previous tab
console.log(`onPopState: Current: ${this.activeIndex}, Previous: ${e.state.lastTab}`);
this.updateIndex(e.state.lastTab, false);
}
};
}
/**
* Update index
*