1
0
Fork 0

Fix scrolling with hash in url

This commit is contained in:
Chocobozzz 2020-06-16 09:56:24 +02:00
parent c7763eddd1
commit 64e0f8cf12
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 22 additions and 3 deletions

View file

@ -35,6 +35,8 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
serverConfig: ServerConfig
private lastScrollHash: string
constructor (
private viewportScroller: ViewportScroller,
private route: ActivatedRoute,
@ -74,7 +76,11 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
}
ngAfterViewChecked () {
if (window.location.hash) this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
if (window.location.hash && window.location.hash !== this.lastScrollHash) {
this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
this.lastScrollHash = window.location.hash
}
}
openContactModal () {

View file

@ -8,11 +8,17 @@ import { ViewportScroller } from '@angular/common'
})
export class AboutPeertubeComponent implements AfterViewChecked {
private lastScrollHash: string
constructor (
private viewportScroller: ViewportScroller
) {}
ngAfterViewChecked () {
if (window.location.hash) this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
if (window.location.hash && window.location.hash !== this.lastScrollHash) {
this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
this.lastScrollHash = window.location.hash
}
}
}

View file

@ -23,6 +23,8 @@ export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
userVideoQuotaUsedDaily = 0
userVideoQuotaDailyPercentage = 15
private lastScrollHash: string
constructor (
private viewportScroller: ViewportScroller,
private userService: UserService,
@ -64,7 +66,11 @@ export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
}
ngAfterViewChecked () {
if (window.location.hash) this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
if (window.location.hash && window.location.hash !== this.lastScrollHash) {
this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
this.lastScrollHash = window.location.hash
}
}
onAvatarChange (formData: FormData) {

View file

@ -123,6 +123,7 @@ export class AppComponent implements OnInit, AfterViewInit {
const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll))
scrollEvent.subscribe(e => {
console.log(e)
if (e.position) {
return this.viewportScroller.scrollToPosition(e.position)
}