[O] Combine index and title
This commit is contained in:
+13
-7
@@ -1,16 +1,22 @@
|
|||||||
|
|
||||||
|
export interface Index
|
||||||
|
{
|
||||||
|
hash: string
|
||||||
|
title: string
|
||||||
|
}
|
||||||
|
|
||||||
export default class Navigator
|
export default class Navigator
|
||||||
{
|
{
|
||||||
private activeIndex: string;
|
private activeIndex: Index;
|
||||||
private updateCallback: (() => void) | undefined;
|
private updateCallback: (() => void) | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update index
|
* Update index
|
||||||
*
|
*
|
||||||
* @param newIndex
|
* @param index Hash and title
|
||||||
* @param title
|
|
||||||
* @param history Record in history or not (Default true)
|
* @param history Record in history or not (Default true)
|
||||||
*/
|
*/
|
||||||
updateIndex(newIndex: string, title: string, history?: boolean)
|
updateIndex(index: Index, history?: boolean)
|
||||||
{
|
{
|
||||||
// Call custom event
|
// Call custom event
|
||||||
if (this.updateCallback != null) this.updateCallback();
|
if (this.updateCallback != null) this.updateCallback();
|
||||||
@@ -22,14 +28,14 @@ export default class Navigator
|
|||||||
if (history)
|
if (history)
|
||||||
{
|
{
|
||||||
// Check url
|
// Check url
|
||||||
let url = `/#${newIndex}`;
|
let url = `/#${index.hash}`;
|
||||||
|
|
||||||
// Push history state
|
// Push history state
|
||||||
window.history.pushState({lastTab: newIndex}, '', url);
|
window.history.pushState({lastTab: index}, '', url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update title
|
// Update title
|
||||||
document.title = 'Veracross Analyzer - ' + title;
|
document.title = 'Veracross Analyzer - ' + index.title;
|
||||||
|
|
||||||
// Scroll to top
|
// Scroll to top
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user