aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/menu/menu.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/menu/menu.component.ts')
-rw-r--r--client/src/app/menu/menu.component.ts14
1 files changed, 6 insertions, 8 deletions
diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts
index 48ed91973..97a3b6d24 100644
--- a/client/src/app/menu/menu.component.ts
+++ b/client/src/app/menu/menu.component.ts
@@ -1,8 +1,10 @@
1import { ViewportScroller } from '@angular/common'
1import { HotkeysService } from 'angular2-hotkeys' 2import { HotkeysService } from 'angular2-hotkeys'
2import * as debug from 'debug' 3import * as debug from 'debug'
3import { switchMap } from 'rxjs/operators' 4import { switchMap } from 'rxjs/operators'
4import { Component, OnInit, ViewChild } from '@angular/core' 5import { Component, OnInit, ViewChild } from '@angular/core'
5import { Router } from '@angular/router' 6import { Router } from '@angular/router'
7import { scrollToTop } from '@app/helpers'
6import { AuthService, AuthStatus, AuthUser, MenuService, RedirectService, ScreenService, ServerService, UserService } from '@app/core' 8import { AuthService, AuthStatus, AuthUser, MenuService, RedirectService, ScreenService, ServerService, UserService } from '@app/core'
7import { LanguageChooserComponent } from '@app/menu/language-chooser.component' 9import { LanguageChooserComponent } from '@app/menu/language-chooser.component'
8import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component' 10import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component'
@@ -39,6 +41,7 @@ export class MenuComponent implements OnInit {
39 } 41 }
40 42
41 constructor ( 43 constructor (
44 private viewportScroller: ViewportScroller,
42 private authService: AuthService, 45 private authService: AuthService,
43 private userService: UserService, 46 private userService: UserService,
44 private serverService: ServerService, 47 private serverService: ServerService,
@@ -199,23 +202,18 @@ export class MenuComponent implements OnInit {
199 return this.languages.find(lang => lang.id === localeId).label 202 return this.languages.find(lang => lang.id === localeId).label
200 } 203 }
201 204
202 onSameUrlRestoreScrollPosition (link: HTMLAnchorElement) { 205 onActiveLinkScrollToAnchor (link: HTMLAnchorElement) {
203 const linkURL = link.getAttribute('href') 206 const linkURL = link.getAttribute('href')
204 const linkHash = link.getAttribute('fragment') 207 const linkHash = link.getAttribute('fragment')
205 208
206 // On same url without fragment restore top scroll position 209 // On same url without fragment restore top scroll position
207 if (!linkHash && this.router.url.includes(linkURL)) { 210 if (!linkHash && this.router.url.includes(linkURL)) {
208 window.scrollTo({ 211 scrollToTop('smooth')
209 left: 0,
210 top: 0,
211 behavior: 'smooth'
212 })
213 } 212 }
214 213
215 // On same url with fragment restore anchor scroll position 214 // On same url with fragment restore anchor scroll position
216 if (linkHash && this.router.url === linkURL) { 215 if (linkHash && this.router.url === linkURL) {
217 const anchor = document.getElementById(link.getAttribute('fragment')) 216 this.viewportScroller.scrollToAnchor(linkHash)
218 anchor.scrollIntoView({ behavior: 'smooth', inline: 'nearest' })
219 } 217 }
220 218
221 if (this.screenService.isInSmallView()) { 219 if (this.screenService.isInSmallView()) {