openaire-library/utils/full-page-slider/full-page-slider.component.ts

111 lines
3.9 KiB
TypeScript

import {AfterContentInit, Component, ContentChildren, Input, OnInit, QueryList} from "@angular/core";
import {SlideComponent} from "./slide.component";
import {BehaviorSubject, Observable} from 'rxjs';
@Component({
selector: 'fp-slider',
template: `
<div class="menu">
<img class="logo" *ngIf="logoURL" [src]="logoURL">
<a *ngIf="stateValue > 1" class="previous" (click)="onClick(stateValue - 1)">
<svg xmlns="http://www.w3.org/2000/svg" width="17.155" height="17.155" viewBox="0 0 17.155 17.155">
<g id="Group_3053" data-name="Group 3053" transform="translate(0)">
<path id="arrow-down-left2"
d="M10.405,11.834,2.022,3.451V7.076A1.011,1.011,0,0,1,0,7.076V1.011A1.009,1.009,0,0,1,1.011,0H7.076a1.011,1.011,0,1,1,0,2.022H3.451l8.383,8.383a1.011,1.011,0,1,1-1.429,1.429h0Z"
transform="translate(8.578 0) rotate(45)" fill="#e95420"/>
</g>
</svg>
</a>
<nav>
<ul>
<li *ngFor="let slide of slides.toArray();let i=index" [class.uk-active]="i === (stateValue - 1)">
<a (click)="onClick(i + 1)"></a>
</li>
</ul>
</nav>
<a *ngIf="stateValue < slides.length" class="next" (click)="onClick(stateValue + 1)">
<svg xmlns="http://www.w3.org/2000/svg" width="17.155" height="17.155" viewBox="0 0 17.155 17.155">
<g id="Group_2442" data-name="Group 2442" transform="translate(-1221 -675)">
<path id="arrow-down-left2"
d="M14.405,4.3,6.022,12.68V9.055A1.011,1.011,0,0,0,4,9.055V15.12a1.009,1.009,0,0,0,1.011,1.01h6.065a1.011,1.011,0,1,0,0-2.022H7.451l8.383-8.383A1.011,1.011,0,0,0,14.405,4.3h0Z"
transform="translate(1215.343 683.578) rotate(-45)" fill="#e95420"/>
</g>
</svg>
</a>
</div>
<div [ngClass]="topBar" class="top-bar"></div>
<section (wheel)="onWheel($event)">
<ng-content></ng-content>
</section>
<bottom *ngIf="hasFooter && state.value === slides.length" class="bottom-bar uk-animation-slide-bottom"
[shortView]="true" [ngClass]="footerClass"
[showOpenaire]="true" [darkBackground]="false"></bottom>
`,
styleUrls: ['full-page-slider.component.css']
})
export class FullPageSliderComponent implements AfterContentInit {
@ContentChildren(SlideComponent) slides: QueryList<SlideComponent>;
@Input()
public initSlide = 1;
@Input()
public logoURL;
@Input() topBar: string = null;
@Input() hasFooter: boolean = null;
@Input() footerClass: string;
public animate: boolean = false;
public state: BehaviorSubject<number> = new BehaviorSubject<number>(0);
ngAfterContentInit() {
this.state.next(this.initSlide);
this.setSlides(this.state.value);
}
setSlides(state = 1) {
this.slides.forEach((slide, index) => {
slide.state = state;
slide.y = -50 + (index + 1) * 200 - state * 200;
});
}
onWheel(event) {
if (!this.animate) {
this.animate = true;
if (event.deltaY > 0 && (this.state.value < this.slides.length)) {
this.state.next(+this.state.value + 1);
this.setSlides(this.state.value);
setTimeout(() => {
this.animate = false;
}, 500);
} else if (event.deltaY < 0 && (this.state.value !== 1)) {
this.state.next(this.state.value - 1);
this.setSlides(this.state.value);
setTimeout(() => {
this.animate = false;
}, 500);
} else {
this.animate = false;
}
}
}
public onClick(index: number) {
if (!this.animate) {
this.animate = true;
this.state.next(index);
this.setSlides(this.state.value);
setTimeout(() => {
this.animate = false;
}, 500);
}
}
public get stateValue() {
return this.state.value;
}
public get stateAsObservable(): Observable<number> {
return this.state.asObservable();
}
}