Fix scrolling with hash in url
This commit is contained in:
parent
c7763eddd1
commit
64e0f8cf12
|
@ -35,6 +35,8 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
|
||||||
|
|
||||||
serverConfig: ServerConfig
|
serverConfig: ServerConfig
|
||||||
|
|
||||||
|
private lastScrollHash: string
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private viewportScroller: ViewportScroller,
|
private viewportScroller: ViewportScroller,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
|
@ -74,7 +76,11 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewChecked () {
|
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 () {
|
openContactModal () {
|
||||||
|
|
|
@ -8,11 +8,17 @@ import { ViewportScroller } from '@angular/common'
|
||||||
})
|
})
|
||||||
|
|
||||||
export class AboutPeertubeComponent implements AfterViewChecked {
|
export class AboutPeertubeComponent implements AfterViewChecked {
|
||||||
|
private lastScrollHash: string
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private viewportScroller: ViewportScroller
|
private viewportScroller: ViewportScroller
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngAfterViewChecked () {
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
|
||||||
userVideoQuotaUsedDaily = 0
|
userVideoQuotaUsedDaily = 0
|
||||||
userVideoQuotaDailyPercentage = 15
|
userVideoQuotaDailyPercentage = 15
|
||||||
|
|
||||||
|
private lastScrollHash: string
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private viewportScroller: ViewportScroller,
|
private viewportScroller: ViewportScroller,
|
||||||
private userService: UserService,
|
private userService: UserService,
|
||||||
|
@ -64,7 +66,11 @@ export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewChecked () {
|
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) {
|
onAvatarChange (formData: FormData) {
|
||||||
|
|
|
@ -123,6 +123,7 @@ export class AppComponent implements OnInit, AfterViewInit {
|
||||||
const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll))
|
const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll))
|
||||||
|
|
||||||
scrollEvent.subscribe(e => {
|
scrollEvent.subscribe(e => {
|
||||||
|
console.log(e)
|
||||||
if (e.position) {
|
if (e.position) {
|
||||||
return this.viewportScroller.scrollToPosition(e.position)
|
return this.viewportScroller.scrollToPosition(e.position)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue