|
|
@ -1,4 +1,4 @@ |
|
|
|
import { Component, OnInit } from '@angular/core' |
|
|
|
import { Component, OnInit, ViewChild, ElementRef, Renderer2 } from '@angular/core' |
|
|
|
import { Router, NavigationEnd } from '@angular/router' |
|
|
|
import { ApisService } from '../services/apis.service' |
|
|
|
import { environment } from '../../environments/environment' |
|
|
@ -10,17 +10,23 @@ import { environment } from '../../environments/environment' |
|
|
|
}) |
|
|
|
export class HomeComponent implements OnInit { |
|
|
|
|
|
|
|
@ViewChild('scrollContent') scrollContent: ElementRef |
|
|
|
|
|
|
|
public basePath = `${environment.BASE_PATH}` |
|
|
|
|
|
|
|
public homeItems: any = [] |
|
|
|
public section: string = 'portfolio' |
|
|
|
public paused: boolean = false |
|
|
|
private scrollPos: number = 0 |
|
|
|
|
|
|
|
constructor( |
|
|
|
private apisService: ApisService, |
|
|
|
private router: Router) |
|
|
|
{ } |
|
|
|
private router: Router, |
|
|
|
private renderer: Renderer2 |
|
|
|
) { } |
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
|
|
|
this.apisService.getPortfolio(this.section, true).toPromise().then((response) => { |
|
|
|
this.homeItems = response.items |
|
|
|
|
|
|
@ -41,6 +47,27 @@ export class HomeComponent implements OnInit { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
ngAfterViewInit() { |
|
|
|
setInterval( () => { |
|
|
|
if(!this.paused) { |
|
|
|
const scrollWidth = 300 |
|
|
|
const scrollPos = parseInt(this.scrollContent.nativeElement.style.marginLeft) || 0 |
|
|
|
/* |
|
|
|
switch(dir) { |
|
|
|
case 'prev': |
|
|
|
this.scrollPos = scrollPos + scrollWidth >= 0 ? 0 : scrollPos + scrollWidth |
|
|
|
break; |
|
|
|
case 'next':*/ |
|
|
|
this.scrollPos = scrollPos - scrollWidth <= -(this.scrollContent.nativeElement.offsetWidth - document.body.clientWidth) ? |
|
|
|
-(this.scrollContent.nativeElement.offsetWidth - document.body.clientWidth) : scrollPos - scrollWidth |
|
|
|
/* |
|
|
|
break; |
|
|
|
}*/ |
|
|
|
this.scrollContent.nativeElement.style.marginLeft = this.scrollPos + 'px' |
|
|
|
} |
|
|
|
},2000) |
|
|
|
} |
|
|
|
|
|
|
|
showDetails(id): void { |
|
|
|
const section = this.section == 'exhibitions' ? 'exhibitions' : 'works' |
|
|
|
this.router.navigate([`/detail/${section}/${id}`]) |
|
|
@ -50,4 +77,25 @@ export class HomeComponent implements OnInit { |
|
|
|
this.homeItems.filter(item => item.id == id)[0].loading = false |
|
|
|
} |
|
|
|
|
|
|
|
scroll(dir): void { |
|
|
|
const scrollWidth = document.body.clientWidth / 3 |
|
|
|
const scrollPos = parseInt(this.scrollContent.nativeElement.style.marginLeft) || 0 |
|
|
|
this.paused = true |
|
|
|
|
|
|
|
switch(dir) { |
|
|
|
case 'prev': |
|
|
|
this.scrollPos = scrollPos + scrollWidth >= 0 ? 0 : scrollPos + scrollWidth |
|
|
|
break; |
|
|
|
case 'next': |
|
|
|
this.scrollPos = scrollPos - scrollWidth <= -(this.scrollContent.nativeElement.offsetWidth - document.body.clientWidth) ? |
|
|
|
-(this.scrollContent.nativeElement.offsetWidth - document.body.clientWidth) : scrollPos - scrollWidth |
|
|
|
break; |
|
|
|
} |
|
|
|
this.scrollContent.nativeElement.style.marginLeft = this.scrollPos + 'px' |
|
|
|
|
|
|
|
setTimeout ( () => { |
|
|
|
this.paused = false |
|
|
|
}, 2000) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|