1
|
import {AfterContentInit, Component, ContentChildren, Input, OnInit, QueryList} from "@angular/core";
|
2
|
import {SlideComponent} from "./slide.component";
|
3
|
import {BehaviorSubject, Observable} from 'rxjs';
|
4
|
|
5
|
@Component({
|
6
|
selector: 'fp-slider',
|
7
|
template: `
|
8
|
<div class="menu">
|
9
|
<img class="logo" *ngIf="logoURL" [src]="logoURL">
|
10
|
<a *ngIf="stateValue > 1" class="previous" (click)="onClick(stateValue - 1)">
|
11
|
<icon name="arrow_up"></icon>
|
12
|
</a>
|
13
|
<nav>
|
14
|
<ul>
|
15
|
<li *ngFor="let slide of slides.toArray();let i=index" [class.uk-active]="i === (stateValue - 1)">
|
16
|
<a (click)="onClick(i + 1)"></a>
|
17
|
</li>
|
18
|
</ul>
|
19
|
</nav>
|
20
|
<a *ngIf="stateValue < slides.length" class="next" (click)="onClick(stateValue + 1)">
|
21
|
<icon name="arrow_down"></icon>
|
22
|
</a>
|
23
|
</div>
|
24
|
<div [ngClass]="topBar" class="top-bar"></div>
|
25
|
<section (wheel)="onWheel($event)" [class.has-footer]="hasFooter && state.value === slides.length">
|
26
|
<ng-content></ng-content>
|
27
|
</section>
|
28
|
<bottom *ngIf="hasFooter && state.value === slides.length" class="bottom-bar uk-animation-slide-bottom"
|
29
|
[shortView]="true" [ngClass]="footerClass"
|
30
|
[showOpenaire]="true" [darkBackground]="false"></bottom>
|
31
|
`,
|
32
|
styleUrls: ['full-page-slider.component.css']
|
33
|
})
|
34
|
export class FullPageSliderComponent implements AfterContentInit {
|
35
|
|
36
|
@ContentChildren(SlideComponent) slides: QueryList<SlideComponent>;
|
37
|
@Input()
|
38
|
public initSlide = 1;
|
39
|
@Input()
|
40
|
public logoURL;
|
41
|
@Input() topBar: string = null;
|
42
|
@Input() hasFooter: boolean = null;
|
43
|
@Input() footerClass: string;
|
44
|
public animate: boolean = false;
|
45
|
public state: BehaviorSubject<number> = new BehaviorSubject<number>(0);
|
46
|
|
47
|
ngAfterContentInit() {
|
48
|
this.state.next(this.initSlide);
|
49
|
this.setSlides(this.state.value);
|
50
|
}
|
51
|
|
52
|
setSlides(state = 1) {
|
53
|
this.slides.forEach((slide, index) => {
|
54
|
slide.state = state;
|
55
|
slide.y = -50 + (index + 1) * 200 - state * 200;
|
56
|
});
|
57
|
}
|
58
|
|
59
|
onWheel(event) {
|
60
|
if (!this.animate) {
|
61
|
this.animate = true;
|
62
|
if (event.deltaY > 0 && (this.state.value < this.slides.length)) {
|
63
|
this.state.next(+this.state.value + 1);
|
64
|
this.setSlides(this.state.value);
|
65
|
setTimeout(() => {
|
66
|
this.animate = false;
|
67
|
}, 500);
|
68
|
} else if (event.deltaY < 0 && (this.state.value !== 1)) {
|
69
|
this.state.next(this.state.value - 1);
|
70
|
this.setSlides(this.state.value);
|
71
|
setTimeout(() => {
|
72
|
this.animate = false;
|
73
|
}, 500);
|
74
|
} else {
|
75
|
this.animate = false;
|
76
|
}
|
77
|
}
|
78
|
}
|
79
|
|
80
|
public onClick(index: number) {
|
81
|
if (!this.animate) {
|
82
|
this.animate = true;
|
83
|
this.state.next(index);
|
84
|
this.setSlides(this.state.value);
|
85
|
setTimeout(() => {
|
86
|
this.animate = false;
|
87
|
}, 500);
|
88
|
}
|
89
|
}
|
90
|
|
91
|
public get stateValue() {
|
92
|
return this.state.value;
|
93
|
}
|
94
|
|
95
|
public get stateAsObservable(): Observable<number> {
|
96
|
return this.state.asObservable();
|
97
|
}
|
98
|
}
|