diff options
author | Kimsible <1877318+kimsible@users.noreply.github.com> | 2020-11-17 14:04:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-17 14:04:44 +0100 |
commit | f3081d6401b63da41b03376f9f952bf1cca8303d (patch) | |
tree | 90ec91babde1544ca0a3423b031c9e10dfcac596 /client/src/app/menu/menu.component.ts | |
parent | 901c36d5f44e02436da5f5c2899666329ff2eb5b (diff) | |
download | PeerTube-f3081d6401b63da41b03376f9f952bf1cca8303d.tar.gz PeerTube-f3081d6401b63da41b03376f9f952bf1cca8303d.tar.zst PeerTube-f3081d6401b63da41b03376f9f952bf1cca8303d.zip |
small refactor + clipboard copy on anchor click in instance page (#3318)
* Refacto scrollTo top and anchors
* Add on click clipboard copy and notifier to anchors about/instance page
* Fix margin top anchor middle title about page
* Use viewportscroller for scrolltoanchor
* Add to Link copied notification on instance page
Co-authored-by: kimsible <kimsible@users.noreply.github.com>
Diffstat (limited to 'client/src/app/menu/menu.component.ts')
-rw-r--r-- | client/src/app/menu/menu.component.ts | 14 |
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 @@ | |||
1 | import { ViewportScroller } from '@angular/common' | ||
1 | import { HotkeysService } from 'angular2-hotkeys' | 2 | import { HotkeysService } from 'angular2-hotkeys' |
2 | import * as debug from 'debug' | 3 | import * as debug from 'debug' |
3 | import { switchMap } from 'rxjs/operators' | 4 | import { switchMap } from 'rxjs/operators' |
4 | import { Component, OnInit, ViewChild } from '@angular/core' | 5 | import { Component, OnInit, ViewChild } from '@angular/core' |
5 | import { Router } from '@angular/router' | 6 | import { Router } from '@angular/router' |
7 | import { scrollToTop } from '@app/helpers' | ||
6 | import { AuthService, AuthStatus, AuthUser, MenuService, RedirectService, ScreenService, ServerService, UserService } from '@app/core' | 8 | import { AuthService, AuthStatus, AuthUser, MenuService, RedirectService, ScreenService, ServerService, UserService } from '@app/core' |
7 | import { LanguageChooserComponent } from '@app/menu/language-chooser.component' | 9 | import { LanguageChooserComponent } from '@app/menu/language-chooser.component' |
8 | import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component' | 10 | import { 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()) { |