aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video/infinite-scroller.directive.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-03-14 14:05:36 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-03-18 11:17:59 +0100
commitbce47964f6241ae56f61089d144b29eb9b5da6d3 (patch)
treecad0a5ef17bc7851d483969453f7b8c2e6edad57 /client/src/app/shared/video/infinite-scroller.directive.ts
parent2a10aab3d7634a252a2acc946974df903e6025be (diff)
downloadPeerTube-bce47964f6241ae56f61089d144b29eb9b5da6d3.tar.gz
PeerTube-bce47964f6241ae56f61089d144b29eb9b5da6d3.tar.zst
PeerTube-bce47964f6241ae56f61089d144b29eb9b5da6d3.zip
Add video channel view
Diffstat (limited to 'client/src/app/shared/video/infinite-scroller.directive.ts')
-rw-r--r--client/src/app/shared/video/infinite-scroller.directive.ts23
1 files changed, 18 insertions, 5 deletions
diff --git a/client/src/app/shared/video/infinite-scroller.directive.ts b/client/src/app/shared/video/infinite-scroller.directive.ts
index 186597a3a..a9e75007c 100644
--- a/client/src/app/shared/video/infinite-scroller.directive.ts
+++ b/client/src/app/shared/video/infinite-scroller.directive.ts
@@ -1,5 +1,5 @@
1import { distinct, distinctUntilChanged, filter, map, share, startWith, throttleTime } from 'rxjs/operators' 1import { distinct, distinctUntilChanged, filter, map, share, startWith, throttleTime } from 'rxjs/operators'
2import { Directive, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core' 2import { Directive, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'
3import { fromEvent, Subscription } from 'rxjs' 3import { fromEvent, Subscription } from 'rxjs'
4 4
5@Directive({ 5@Directive({
@@ -11,7 +11,7 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy {
11 @Input() firstLoadedPage = 1 11 @Input() firstLoadedPage = 1
12 @Input() percentLimit = 70 12 @Input() percentLimit = 70
13 @Input() autoInit = false 13 @Input() autoInit = false
14 @Input() container = document.body 14 @Input() onItself = false
15 15
16 @Output() nearOfBottom = new EventEmitter<void>() 16 @Output() nearOfBottom = new EventEmitter<void>()
17 @Output() nearOfTop = new EventEmitter<void>() 17 @Output() nearOfTop = new EventEmitter<void>()
@@ -24,8 +24,9 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy {
24 private scrollUpSub: Subscription 24 private scrollUpSub: Subscription
25 private pageChangeSub: Subscription 25 private pageChangeSub: Subscription
26 private middleScreen: number 26 private middleScreen: number
27 private container: HTMLElement
27 28
28 constructor () { 29 constructor (private el: ElementRef) {
29 this.decimalLimit = this.percentLimit / 100 30 this.decimalLimit = this.percentLimit / 100
30 } 31 }
31 32
@@ -40,16 +41,20 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy {
40 } 41 }
41 42
42 initialize () { 43 initialize () {
44 if (this.onItself) {
45 this.container = this.el.nativeElement
46 }
47
43 this.middleScreen = window.innerHeight / 2 48 this.middleScreen = window.innerHeight / 2
44 49
45 // Emit the last value 50 // Emit the last value
46 const throttleOptions = { leading: true, trailing: true } 51 const throttleOptions = { leading: true, trailing: true }
47 52
48 const scrollObservable = fromEvent(window, 'scroll') 53 const scrollObservable = fromEvent(this.container || window, 'scroll')
49 .pipe( 54 .pipe(
50 startWith(null), 55 startWith(null),
51 throttleTime(200, undefined, throttleOptions), 56 throttleTime(200, undefined, throttleOptions),
52 map(() => ({ current: window.scrollY, maximumScroll: this.container.clientHeight - window.innerHeight })), 57 map(() => this.getScrollInfo()),
53 distinctUntilChanged((o1, o2) => o1.current === o2.current), 58 distinctUntilChanged((o1, o2) => o1.current === o2.current),
54 share() 59 share()
55 ) 60 )
@@ -102,4 +107,12 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy {
102 // Offset page 107 // Offset page
103 return page + (this.firstLoadedPage - 1) 108 return page + (this.firstLoadedPage - 1)
104 } 109 }
110
111 private getScrollInfo () {
112 if (this.container) {
113 return { current: this.container.scrollTop, maximumScroll: this.container.scrollHeight }
114 }
115
116 return { current: window.scrollY, maximumScroll: document.body.clientHeight - window.innerHeight }
117 }
105} 118}