2020-06-16 19:07:32 +02:00
|
|
|
import {AfterContentInit, Component, ContentChildren, Input, OnInit, QueryList} from "@angular/core";
|
2020-06-15 21:02:44 +02:00
|
|
|
import {SlideComponent} from "./slide.component";
|
2020-09-15 15:53:18 +02:00
|
|
|
import {BehaviorSubject, Observable} from 'rxjs';
|
2020-06-15 21:02:44 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'fp-slider',
|
|
|
|
template: `
|
2020-06-16 21:59:51 +02:00
|
|
|
<div class="menu">
|
|
|
|
<img class="logo" *ngIf="logoURL" [src]="logoURL">
|
2020-09-15 15:53:18 +02:00
|
|
|
<a *ngIf="stateValue > 1" class="previous" (click)="onClick(stateValue - 1)">
|
2020-10-13 22:26:48 +02:00
|
|
|
<icon name="arrow_up"></icon>
|
2020-06-16 21:59:51 +02:00
|
|
|
</a>
|
|
|
|
<nav>
|
|
|
|
<ul>
|
2020-09-15 15:53:18 +02:00
|
|
|
<li *ngFor="let slide of slides.toArray();let i=index" [class.uk-active]="i === (stateValue - 1)">
|
2020-06-16 21:59:51 +02:00
|
|
|
<a (click)="onClick(i + 1)"></a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
2020-09-15 15:53:18 +02:00
|
|
|
<a *ngIf="stateValue < slides.length" class="next" (click)="onClick(stateValue + 1)">
|
2020-10-13 22:26:48 +02:00
|
|
|
<icon name="arrow_down"></icon>
|
2020-06-16 21:59:51 +02:00
|
|
|
</a>
|
|
|
|
</div>
|
2020-09-14 17:08:34 +02:00
|
|
|
<div [ngClass]="topBar" class="top-bar"></div>
|
2020-09-16 11:29:39 +02:00
|
|
|
<section (wheel)="onWheel($event)" [class.has-footer]="hasFooter && state.value === slides.length">
|
2020-06-17 16:31:31 +02:00
|
|
|
<ng-content></ng-content>
|
2020-09-15 15:53:18 +02:00
|
|
|
</section>
|
|
|
|
<bottom *ngIf="hasFooter && state.value === slides.length" class="bottom-bar uk-animation-slide-bottom"
|
|
|
|
[shortView]="true" [ngClass]="footerClass"
|
|
|
|
[showOpenaire]="true" [darkBackground]="false"></bottom>
|
|
|
|
`,
|
2020-06-15 21:02:44 +02:00
|
|
|
styleUrls: ['full-page-slider.component.css']
|
|
|
|
})
|
|
|
|
export class FullPageSliderComponent implements AfterContentInit {
|
|
|
|
|
|
|
|
@ContentChildren(SlideComponent) slides: QueryList<SlideComponent>;
|
2020-06-16 19:07:32 +02:00
|
|
|
@Input()
|
|
|
|
public initSlide = 1;
|
2020-06-16 21:59:51 +02:00
|
|
|
@Input()
|
|
|
|
public logoURL;
|
2020-09-14 17:08:34 +02:00
|
|
|
@Input() topBar: string = null;
|
2020-09-15 15:53:18 +02:00
|
|
|
@Input() hasFooter: boolean = null;
|
|
|
|
@Input() footerClass: string;
|
2020-06-15 21:02:44 +02:00
|
|
|
public animate: boolean = false;
|
2020-09-15 15:53:18 +02:00
|
|
|
public state: BehaviorSubject<number> = new BehaviorSubject<number>(0);
|
2020-06-15 21:02:44 +02:00
|
|
|
|
|
|
|
ngAfterContentInit() {
|
2020-09-15 15:53:18 +02:00
|
|
|
this.state.next(this.initSlide);
|
|
|
|
this.setSlides(this.state.value);
|
2020-06-15 21:02:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setSlides(state = 1) {
|
|
|
|
this.slides.forEach((slide, index) => {
|
|
|
|
slide.state = state;
|
2020-06-17 16:31:31 +02:00
|
|
|
slide.y = -50 + (index + 1) * 200 - state * 200;
|
2020-06-15 21:02:44 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onWheel(event) {
|
|
|
|
if (!this.animate) {
|
|
|
|
this.animate = true;
|
2020-09-15 15:53:18 +02:00
|
|
|
if (event.deltaY > 0 && (this.state.value < this.slides.length)) {
|
|
|
|
this.state.next(+this.state.value + 1);
|
|
|
|
this.setSlides(this.state.value);
|
2020-06-15 21:02:44 +02:00
|
|
|
setTimeout(() => {
|
|
|
|
this.animate = false;
|
2020-06-16 21:59:51 +02:00
|
|
|
}, 500);
|
2020-09-15 15:53:18 +02:00
|
|
|
} else if (event.deltaY < 0 && (this.state.value !== 1)) {
|
|
|
|
this.state.next(this.state.value - 1);
|
|
|
|
this.setSlides(this.state.value);
|
2020-06-15 21:02:44 +02:00
|
|
|
setTimeout(() => {
|
|
|
|
this.animate = false;
|
2020-06-16 21:59:51 +02:00
|
|
|
}, 500);
|
2020-06-15 21:02:44 +02:00
|
|
|
} else {
|
|
|
|
this.animate = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-16 21:59:51 +02:00
|
|
|
|
|
|
|
public onClick(index: number) {
|
|
|
|
if (!this.animate) {
|
|
|
|
this.animate = true;
|
2020-09-15 15:53:18 +02:00
|
|
|
this.state.next(index);
|
|
|
|
this.setSlides(this.state.value);
|
2020-06-16 21:59:51 +02:00
|
|
|
setTimeout(() => {
|
|
|
|
this.animate = false;
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
}
|
2020-09-15 15:53:18 +02:00
|
|
|
|
|
|
|
public get stateValue() {
|
|
|
|
return this.state.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get stateAsObservable(): Observable<number> {
|
|
|
|
return this.state.asObservable();
|
|
|
|
}
|
2020-06-15 21:02:44 +02:00
|
|
|
}
|