2023-10-05 15:59:41 +02:00
|
|
|
import {AfterContentInit, Component, ContentChildren, Input, OnDestroy, QueryList} from '@angular/core';
|
|
|
|
import {SliderItemComponent} from "./slider-item.component";
|
|
|
|
import {SliderNavItemComponent} from "./slider-nav-item.component";
|
|
|
|
import {SliderContainerComponent} from "./slider-container.component";
|
|
|
|
import {LayoutService} from "../../dashboard/sharedComponents/sidebar/layout.service";
|
|
|
|
import {Subscriber} from "rxjs";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'slider-column',
|
|
|
|
template: `
|
|
|
|
<div class="uk-position-relative">
|
|
|
|
<ng-content></ng-content>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class SliderColumnComponent implements AfterContentInit, OnDestroy {
|
|
|
|
@Input()
|
|
|
|
type: 'slider' | 'nav' = null;
|
|
|
|
@Input()
|
2023-10-10 16:12:37 +02:00
|
|
|
animation = null;
|
2023-10-05 15:59:41 +02:00
|
|
|
@ContentChildren(SliderItemComponent) items: QueryList<SliderItemComponent>;
|
|
|
|
@ContentChildren(SliderNavItemComponent) navItems: QueryList<SliderNavItemComponent>;
|
|
|
|
public isMobile: boolean;
|
|
|
|
private subscriptions: any[] = [];
|
|
|
|
|
|
|
|
constructor(private layoutService: LayoutService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterContentInit() {
|
2023-10-10 16:12:37 +02:00
|
|
|
if (this.animation) {
|
|
|
|
this.slides.forEach(slide => {
|
|
|
|
slide.init(this.animation);
|
|
|
|
});
|
|
|
|
this.navItems.forEach(slide => {
|
|
|
|
slide.init(this.animation);
|
|
|
|
});
|
|
|
|
}
|
2023-10-05 15:59:41 +02:00
|
|
|
this.subscriptions.push(this.layoutService.isMobile.subscribe(isMobile => {
|
|
|
|
this.isMobile = isMobile;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
change(time: number) {
|
|
|
|
if (this.type === 'slider') {
|
|
|
|
let slides = this.slides;
|
|
|
|
for (let i = 0; i < slides.length; i++) {
|
|
|
|
slides[i].setActive(slides[i].start <= time && (!slides[i + 1] || slides[i + 1].start > time));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.type === 'nav') {
|
|
|
|
let slides = this.navItems;
|
|
|
|
for (let i = 0; i < slides.length; i++) {
|
2023-10-10 16:12:37 +02:00
|
|
|
slides.get(i).setActive(!this.isMobile || (slides.get(i).start <= time && (!slides.get(i + 1) || slides.get(i + 1).start > time)));
|
2023-10-05 15:59:41 +02:00
|
|
|
slides.get(i).active = slides.get(i).start <= time && (!slides.get(i + 1) || slides.get(i + 1).start > time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setContainer(container: SliderContainerComponent) {
|
|
|
|
if (this.type === 'nav') {
|
|
|
|
this.navItems.forEach(item => {
|
|
|
|
item.container = container;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get slides(): SliderItemComponent[] {
|
|
|
|
return this.items.filter(item => item.type === 'slide');
|
|
|
|
}
|
|
|
|
}
|