From 14a9c5a9b29f6d98f060cede1a4430f1d2d8264b Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sat, 21 Dec 2019 11:37:25 -0500 Subject: [PATCH] [O] Combine index and title --- src/logic/navigator.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/logic/navigator.ts b/src/logic/navigator.ts index 53b6e0b..cbc7bad 100644 --- a/src/logic/navigator.ts +++ b/src/logic/navigator.ts @@ -1,16 +1,22 @@ + +export interface Index +{ + hash: string + title: string +} + export default class Navigator { - private activeIndex: string; + private activeIndex: Index; private updateCallback: (() => void) | undefined; - + /** * Update index * - * @param newIndex - * @param title + * @param index Hash and title * @param history Record in history or not (Default true) */ - updateIndex(newIndex: string, title: string, history?: boolean) + updateIndex(index: Index, history?: boolean) { // Call custom event if (this.updateCallback != null) this.updateCallback(); @@ -22,14 +28,14 @@ export default class Navigator if (history) { // Check url - let url = `/#${newIndex}`; + let url = `/#${index.hash}`; // Push history state - window.history.pushState({lastTab: newIndex}, '', url); + window.history.pushState({lastTab: index}, '', url); } // Update title - document.title = 'Veracross Analyzer - ' + title; + document.title = 'Veracross Analyzer - ' + index.title; // Scroll to top window.scrollTo(0, 0);