[+] Create navigator class

This commit is contained in:
Hykilpikonna
2019-12-21 11:34:09 -05:00
parent a2f6a30ad1
commit 55432e5c33
+37
View File
@@ -0,0 +1,37 @@
export default class Navigator
{
private activeIndex: string;
private updateCallback: (() => void) | undefined;
/**
* Update index
*
* @param newIndex
* @param title
* @param history Record in history or not (Default true)
*/
updateIndex(newIndex: string, title: string, history?: boolean)
{
// Call custom event
if (this.updateCallback != null) this.updateCallback();
// Null case
if (history == null) history = true;
// Record history or not
if (history)
{
// Check url
let url = `/#${newIndex}`;
// Push history state
window.history.pushState({lastTab: newIndex}, '', url);
}
// Update title
document.title = 'Veracross Analyzer - ' + title;
// Scroll to top
window.scrollTo(0, 0);
}
}