2018-05-04 06:23:48 +08:00
|
|
|
import {
|
|
|
|
ChangeDetectorRef,
|
|
|
|
Component,
|
|
|
|
ElementRef,
|
|
|
|
EventEmitter,
|
|
|
|
HostListener,
|
|
|
|
OnDestroy,
|
|
|
|
OnInit,
|
|
|
|
Output,
|
|
|
|
QueryList,
|
|
|
|
ViewChild
|
|
|
|
} from '@angular/core';
|
2018-03-31 03:30:30 +08:00
|
|
|
import {PhotoDTO} from '../../../../common/entities/PhotoDTO';
|
|
|
|
import {GalleryPhotoComponent} from '../grid/photo/photo.grid.gallery.component';
|
|
|
|
import {Dimension} from '../../model/IRenderable';
|
|
|
|
import {FullScreenService} from '../fullscreen.service';
|
|
|
|
import {OverlayService} from '../overlay.service';
|
|
|
|
import {animate, AnimationBuilder, AnimationPlayer, style} from '@angular/animations';
|
2018-11-18 02:32:31 +08:00
|
|
|
import {GalleryLightboxMediaComponent} from './media/media.lightbox.gallery.component';
|
2018-05-23 08:27:07 +08:00
|
|
|
import {Observable, Subscription, timer} from 'rxjs';
|
2018-05-04 06:23:48 +08:00
|
|
|
import {filter} from 'rxjs/operators';
|
2018-05-27 08:49:55 +08:00
|
|
|
import {ActivatedRoute, Params, Router} from '@angular/router';
|
|
|
|
import {PageHelper} from '../../model/page.helper';
|
|
|
|
import {QueryService} from '../../model/query.service';
|
2018-11-05 02:28:32 +08:00
|
|
|
import {MediaDTO} from '../../../../common/entities/MediaDTO';
|
2018-05-27 08:49:55 +08:00
|
|
|
|
|
|
|
export enum LightboxStates {
|
2018-05-29 02:03:12 +08:00
|
|
|
Open = 1,
|
|
|
|
Closing = 2,
|
|
|
|
Closed = 3
|
2018-05-27 08:49:55 +08:00
|
|
|
}
|
2016-05-01 00:01:54 +08:00
|
|
|
|
|
|
|
@Component({
|
2018-05-04 06:23:48 +08:00
|
|
|
selector: 'app-gallery-lightbox',
|
2018-11-12 02:22:46 +08:00
|
|
|
styleUrls: ['./lightbox.gallery.component.css', './inputrange.css'],
|
2017-07-11 04:00:22 +08:00
|
|
|
templateUrl: './lightbox.gallery.component.html'
|
2016-05-01 00:01:54 +08:00
|
|
|
})
|
2018-05-04 06:23:48 +08:00
|
|
|
export class GalleryLightboxComponent implements OnDestroy, OnInit {
|
2017-07-18 00:30:16 +08:00
|
|
|
|
2018-11-18 02:32:31 +08:00
|
|
|
@ViewChild('photo') mediaElement: GalleryLightboxMediaComponent;
|
2018-03-31 03:30:30 +08:00
|
|
|
@ViewChild('lightbox') lightboxElement: ElementRef;
|
2016-05-01 00:01:54 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
public navigation = {hasPrev: true, hasNext: true};
|
|
|
|
public blackCanvasOpacity: any = 0;
|
2016-07-04 22:58:10 +08:00
|
|
|
|
2017-07-20 04:40:27 +08:00
|
|
|
private activePhotoId: number = null;
|
2017-06-11 04:32:56 +08:00
|
|
|
public activePhoto: GalleryPhotoComponent;
|
|
|
|
private gridPhotoQL: QueryList<GalleryPhotoComponent>;
|
2016-05-01 00:01:54 +08:00
|
|
|
|
2018-05-27 08:49:55 +08:00
|
|
|
public status: LightboxStates = LightboxStates.Closed;
|
|
|
|
private subscription: {
|
|
|
|
photosChange: Subscription,
|
|
|
|
route: Subscription
|
|
|
|
} = {
|
|
|
|
photosChange: null,
|
|
|
|
route: null
|
|
|
|
};
|
2017-07-12 02:23:25 +08:00
|
|
|
private timer: Observable<number>;
|
|
|
|
private timerSub: Subscription;
|
2018-05-04 06:23:48 +08:00
|
|
|
public playBackState = 0;
|
2017-07-12 02:23:25 +08:00
|
|
|
public controllersDimmed = true;
|
|
|
|
public controllersVisible = true;
|
2017-07-10 04:00:42 +08:00
|
|
|
|
|
|
|
public infoPanelVisible = false;
|
|
|
|
public infoPanelWidth = 0;
|
2017-07-17 02:49:12 +08:00
|
|
|
public animating = false;
|
2018-05-04 06:23:48 +08:00
|
|
|
startPhotoDimension: Dimension = <Dimension>{top: 0, left: 0, width: 0, height: 0};
|
|
|
|
iPvisibilityTimer = null;
|
|
|
|
visibilityTimer = null;
|
2018-05-27 08:49:55 +08:00
|
|
|
delayedPhotoShow: string = null;
|
2016-05-01 03:36:24 +08:00
|
|
|
|
2016-07-06 18:53:49 +08:00
|
|
|
|
2017-07-11 04:00:22 +08:00
|
|
|
constructor(public fullScreenService: FullScreenService,
|
2018-05-27 08:49:55 +08:00
|
|
|
private changeDetector: ChangeDetectorRef,
|
|
|
|
private overlayService: OverlayService,
|
|
|
|
private _builder: AnimationBuilder,
|
|
|
|
private router: Router,
|
|
|
|
private queryService: QueryService,
|
|
|
|
private route: ActivatedRoute) {
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-01 00:33:07 +08:00
|
|
|
|
2017-07-12 02:23:25 +08:00
|
|
|
ngOnInit(): void {
|
2018-05-04 06:23:48 +08:00
|
|
|
this.timer = timer(1000, 2000);
|
2018-05-27 08:49:55 +08:00
|
|
|
this.subscription.route = this.route.queryParams.subscribe((params: Params) => {
|
|
|
|
if (params[QueryService.PHOTO_PARAM] && params[QueryService.PHOTO_PARAM] !== '') {
|
|
|
|
if (!this.gridPhotoQL) {
|
|
|
|
return this.delayedPhotoShow = params[QueryService.PHOTO_PARAM];
|
|
|
|
}
|
|
|
|
this.onNavigateTo(params[QueryService.PHOTO_PARAM]);
|
|
|
|
} else if (this.status === LightboxStates.Open) {
|
|
|
|
this.delayedPhotoShow = null;
|
|
|
|
this.hideLigthbox();
|
|
|
|
}
|
|
|
|
});
|
2017-07-12 02:23:25 +08:00
|
|
|
}
|
2016-05-01 03:36:24 +08:00
|
|
|
|
2017-07-10 04:00:42 +08:00
|
|
|
ngOnDestroy(): void {
|
2017-07-12 02:23:25 +08:00
|
|
|
this.pause();
|
2018-05-27 08:49:55 +08:00
|
|
|
if (this.subscription.photosChange != null) {
|
|
|
|
this.subscription.photosChange.unsubscribe();
|
|
|
|
}
|
|
|
|
if (this.subscription.route != null) {
|
|
|
|
this.subscription.route.unsubscribe();
|
2017-07-10 04:00:42 +08:00
|
|
|
}
|
2017-07-20 04:40:27 +08:00
|
|
|
|
|
|
|
if (this.visibilityTimer != null) {
|
|
|
|
clearTimeout(this.visibilityTimer);
|
|
|
|
}
|
|
|
|
if (this.iPvisibilityTimer != null) {
|
|
|
|
clearTimeout(this.iPvisibilityTimer);
|
|
|
|
}
|
2017-07-10 04:00:42 +08:00
|
|
|
}
|
|
|
|
|
2018-05-27 08:49:55 +08:00
|
|
|
onNavigateTo(photoName: string) {
|
2018-11-05 02:28:32 +08:00
|
|
|
if (this.activePhoto && this.activePhoto.gridPhoto.media.name === photoName) {
|
2018-05-27 08:49:55 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-11-05 02:28:32 +08:00
|
|
|
const photo = this.gridPhotoQL.find(i => i.gridPhoto.media.name === photoName);
|
2018-05-27 08:49:55 +08:00
|
|
|
if (!photo) {
|
|
|
|
return this.delayedPhotoShow = photoName;
|
|
|
|
}
|
|
|
|
if (this.status === LightboxStates.Closed) {
|
2018-11-05 02:28:32 +08:00
|
|
|
this.showLigthbox(photo.gridPhoto.media);
|
2018-05-27 08:49:55 +08:00
|
|
|
} else {
|
|
|
|
this.showPhoto(this.gridPhotoQL.toArray().indexOf(photo));
|
|
|
|
}
|
|
|
|
this.delayedPhotoShow = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
setGridPhotoQL(value: QueryList<GalleryPhotoComponent>) {
|
|
|
|
if (this.subscription.photosChange != null) {
|
|
|
|
this.subscription.photosChange.unsubscribe();
|
|
|
|
}
|
|
|
|
this.gridPhotoQL = value;
|
|
|
|
this.subscription.photosChange = this.gridPhotoQL.changes.subscribe(() => {
|
|
|
|
if (this.activePhotoId != null && this.gridPhotoQL.length > this.activePhotoId) {
|
|
|
|
this.updateActivePhoto(this.activePhotoId);
|
|
|
|
}
|
|
|
|
if (this.delayedPhotoShow) {
|
|
|
|
this.onNavigateTo(this.delayedPhotoShow);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.delayedPhotoShow) {
|
|
|
|
this.onNavigateTo(this.delayedPhotoShow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 04:00:42 +08:00
|
|
|
//noinspection JSUnusedGlobalSymbols
|
2017-06-11 04:32:56 +08:00
|
|
|
@HostListener('window:resize', ['$event'])
|
|
|
|
onResize() {
|
|
|
|
if (this.activePhoto) {
|
2017-07-11 04:00:22 +08:00
|
|
|
this.animateLightbox();
|
2017-06-11 04:32:56 +08:00
|
|
|
this.updateActivePhoto(this.activePhotoId);
|
2016-05-01 00:01:54 +08:00
|
|
|
}
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-01 00:01:54 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
public nextImage() {
|
|
|
|
if (this.activePhotoId + 1 < this.gridPhotoQL.length) {
|
2018-05-27 08:49:55 +08:00
|
|
|
this.navigateToPhoto(this.activePhotoId + 1);
|
|
|
|
/*if (this.activePhotoId + 3 >= this.gridPhotoQL.length) {
|
2018-05-04 06:23:48 +08:00
|
|
|
this.onLastElement.emit({}); // trigger to render more photos if there are
|
2018-05-27 08:49:55 +08:00
|
|
|
}*/
|
2017-06-11 04:32:56 +08:00
|
|
|
return;
|
2016-05-13 05:00:38 +08:00
|
|
|
}
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-13 05:00:38 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
public prevImage() {
|
2017-07-12 02:23:25 +08:00
|
|
|
this.pause();
|
2017-06-11 04:32:56 +08:00
|
|
|
if (this.activePhotoId > 0) {
|
2018-05-27 08:49:55 +08:00
|
|
|
this.navigateToPhoto(this.activePhotoId - 1);
|
2017-06-11 04:32:56 +08:00
|
|
|
return;
|
2016-05-13 05:00:38 +08:00
|
|
|
}
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-13 05:00:38 +08:00
|
|
|
|
|
|
|
|
2018-05-27 08:49:55 +08:00
|
|
|
private navigateToPhoto(photoIndex: number) {
|
|
|
|
this.router.navigate([],
|
2018-11-05 02:28:32 +08:00
|
|
|
{queryParams: this.queryService.getParams(this.gridPhotoQL.toArray()[photoIndex].gridPhoto.media)});
|
2018-05-27 08:49:55 +08:00
|
|
|
/*
|
|
|
|
this.activePhoto = null;
|
|
|
|
this.changeDetector.detectChanges();
|
|
|
|
this.updateActivePhoto(photoIndex, resize);*/
|
|
|
|
}
|
|
|
|
|
2017-07-11 04:00:22 +08:00
|
|
|
private showPhoto(photoIndex: number, resize: boolean = true) {
|
2017-06-11 04:32:56 +08:00
|
|
|
this.activePhoto = null;
|
|
|
|
this.changeDetector.detectChanges();
|
2017-07-11 04:00:22 +08:00
|
|
|
this.updateActivePhoto(photoIndex, resize);
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
|
|
|
|
2018-11-05 02:28:32 +08:00
|
|
|
public showLigthbox(photo: MediaDTO) {
|
2017-07-12 02:23:25 +08:00
|
|
|
this.controllersVisible = true;
|
|
|
|
this.showControls();
|
2018-05-27 08:49:55 +08:00
|
|
|
this.status = LightboxStates.Open;
|
2018-05-04 06:23:48 +08:00
|
|
|
const selectedPhoto = this.findPhotoComponent(photo);
|
2017-06-11 04:32:56 +08:00
|
|
|
if (selectedPhoto === null) {
|
2018-03-31 03:30:30 +08:00
|
|
|
throw new Error('Can\'t find Photo');
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
|
|
|
|
2017-07-11 04:00:22 +08:00
|
|
|
const lightboxDimension = selectedPhoto.getDimension();
|
2018-05-27 08:49:55 +08:00
|
|
|
lightboxDimension.top -= PageHelper.ScrollY;
|
2017-07-16 05:54:17 +08:00
|
|
|
this.animating = true;
|
2018-11-05 02:28:32 +08:00
|
|
|
this.animatePhoto(selectedPhoto.getDimension(), this.calcLightBoxPhotoDimension(selectedPhoto.gridPhoto.media)).onDone(() => {
|
2017-07-16 05:54:17 +08:00
|
|
|
this.animating = false;
|
|
|
|
});
|
2017-07-11 04:00:22 +08:00
|
|
|
this.animateLightbox(
|
|
|
|
lightboxDimension,
|
|
|
|
<Dimension>{
|
2017-06-11 04:32:56 +08:00
|
|
|
top: 0,
|
|
|
|
left: 0,
|
2017-07-17 02:49:12 +08:00
|
|
|
width: this.getPhotoFrameWidth(),
|
|
|
|
height: this.getPhotoFrameHeight()
|
2017-07-11 04:00:22 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this.blackCanvasOpacity = 0;
|
|
|
|
this.startPhotoDimension = selectedPhoto.getDimension();
|
2018-05-04 06:23:48 +08:00
|
|
|
// disable scroll
|
2017-07-11 04:00:22 +08:00
|
|
|
this.overlayService.showOverlay();
|
|
|
|
this.blackCanvasOpacity = 1.0;
|
|
|
|
this.showPhoto(this.gridPhotoQL.toArray().indexOf(selectedPhoto), false);
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
|
|
|
|
2018-05-04 06:23:48 +08:00
|
|
|
//noinspection JSUnusedGlobalSymbols
|
|
|
|
@HostListener('window:keydown', ['$event'])
|
|
|
|
onKeyPress(e: KeyboardEvent) {
|
2018-05-27 08:49:55 +08:00
|
|
|
if (this.status !== LightboxStates.Open) {
|
2018-05-04 06:23:48 +08:00
|
|
|
return;
|
2018-03-31 03:30:30 +08:00
|
|
|
}
|
2018-05-04 06:23:48 +08:00
|
|
|
const event: KeyboardEvent = window.event ? <any>window.event : e;
|
2018-10-22 06:24:17 +08:00
|
|
|
switch (event.key) {
|
|
|
|
case 'ArrowLeft':
|
2018-05-04 06:23:48 +08:00
|
|
|
if (this.activePhotoId > 0) {
|
|
|
|
this.prevImage();
|
|
|
|
}
|
|
|
|
break;
|
2018-10-22 06:24:17 +08:00
|
|
|
case 'ArrowRight':
|
2018-05-04 06:23:48 +08:00
|
|
|
if (this.activePhotoId < this.gridPhotoQL.length - 1) {
|
|
|
|
this.nextImage();
|
|
|
|
}
|
|
|
|
break;
|
2018-10-22 06:24:17 +08:00
|
|
|
case 'Escape': // escape
|
2018-05-04 06:23:48 +08:00
|
|
|
this.hide();
|
|
|
|
break;
|
2018-11-12 02:22:46 +08:00
|
|
|
case ' ': // space
|
|
|
|
if (this.activePhoto && this.activePhoto.gridPhoto.isVideo()) {
|
2018-11-18 02:32:31 +08:00
|
|
|
this.mediaElement.playPause();
|
2018-11-12 02:22:46 +08:00
|
|
|
}
|
|
|
|
break;
|
2018-03-31 03:30:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
public hide() {
|
2018-05-27 08:49:55 +08:00
|
|
|
this.router.navigate([],
|
|
|
|
{queryParams: this.queryService.getParams()});
|
|
|
|
}
|
|
|
|
|
|
|
|
private hideLigthbox() {
|
2017-07-12 02:23:25 +08:00
|
|
|
this.controllersVisible = false;
|
2018-05-27 08:49:55 +08:00
|
|
|
this.status = LightboxStates.Closing;
|
2017-06-11 04:32:56 +08:00
|
|
|
this.fullScreenService.exitFullScreen();
|
2017-07-13 00:31:19 +08:00
|
|
|
this.pause();
|
2017-06-11 04:32:56 +08:00
|
|
|
|
2017-07-16 05:54:17 +08:00
|
|
|
this.animating = true;
|
2017-07-11 04:00:22 +08:00
|
|
|
const lightboxDimension = this.activePhoto.getDimension();
|
2018-05-27 08:49:55 +08:00
|
|
|
lightboxDimension.top -= PageHelper.ScrollY;
|
2017-06-11 04:32:56 +08:00
|
|
|
this.blackCanvasOpacity = 0;
|
2017-07-11 04:00:22 +08:00
|
|
|
|
2018-11-05 02:28:32 +08:00
|
|
|
this.animatePhoto(this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.media), this.activePhoto.getDimension());
|
2017-07-11 04:00:22 +08:00
|
|
|
this.animateLightbox(<Dimension>{
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
2017-07-17 02:49:12 +08:00
|
|
|
width: this.getPhotoFrameWidth(),
|
|
|
|
height: this.getPhotoFrameHeight()
|
2017-07-16 05:54:17 +08:00
|
|
|
}, lightboxDimension).onDone(() => {
|
2018-05-27 08:49:55 +08:00
|
|
|
this.status = LightboxStates.Closed;
|
2017-06-11 04:32:56 +08:00
|
|
|
this.activePhoto = null;
|
2017-07-20 04:40:27 +08:00
|
|
|
this.activePhotoId = null;
|
2017-06-11 04:32:56 +08:00
|
|
|
this.overlayService.hideOverlay();
|
2017-07-16 05:54:17 +08:00
|
|
|
});
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
|
2017-07-11 04:41:30 +08:00
|
|
|
this.hideInfoPanel(false);
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
|
|
|
|
2017-07-16 05:54:17 +08:00
|
|
|
|
|
|
|
animatePhoto(from: Dimension, to: Dimension = from): AnimationPlayer {
|
|
|
|
const elem = this._builder.build([
|
2017-07-11 04:00:22 +08:00
|
|
|
style(<any>Dimension.toString(from)),
|
|
|
|
animate(300,
|
|
|
|
style(<any>Dimension.toString(to)))
|
|
|
|
])
|
2018-11-18 02:32:31 +08:00
|
|
|
.create(this.mediaElement.elementRef.nativeElement);
|
2017-07-16 05:54:17 +08:00
|
|
|
elem.play();
|
|
|
|
return elem;
|
2017-07-11 04:00:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
animateLightbox(from: Dimension = <Dimension>{
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
2017-07-17 02:49:12 +08:00
|
|
|
width: this.getPhotoFrameWidth(),
|
|
|
|
height: this.getPhotoFrameHeight()
|
2017-07-16 05:54:17 +08:00
|
|
|
}, to: Dimension = from): AnimationPlayer {
|
|
|
|
const elem = this._builder.build([
|
2017-07-11 04:00:22 +08:00
|
|
|
style(<any>Dimension.toString(from)),
|
|
|
|
animate(300,
|
|
|
|
style(<any>Dimension.toString(to)))
|
|
|
|
])
|
2017-07-16 05:54:17 +08:00
|
|
|
.create(this.lightboxElement.nativeElement);
|
|
|
|
elem.play();
|
|
|
|
return elem;
|
2017-07-11 04:00:22 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
|
2017-07-10 04:00:42 +08:00
|
|
|
public toggleInfoPanel() {
|
|
|
|
|
|
|
|
|
2018-05-04 06:23:48 +08:00
|
|
|
if (this.infoPanelWidth !== 400) {
|
2017-07-10 04:00:42 +08:00
|
|
|
this.showInfoPanel();
|
|
|
|
} else {
|
|
|
|
this.hideInfoPanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-04 06:23:48 +08:00
|
|
|
hideInfoPanel(_animate: boolean = true) {
|
|
|
|
this.iPvisibilityTimer = setTimeout(() => {
|
|
|
|
this.iPvisibilityTimer = null;
|
|
|
|
this.infoPanelVisible = false;
|
|
|
|
}, 1000);
|
|
|
|
|
2018-11-05 02:28:32 +08:00
|
|
|
const starPhotoPos = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.media);
|
2018-05-04 06:23:48 +08:00
|
|
|
this.infoPanelWidth = 0;
|
2018-11-05 02:28:32 +08:00
|
|
|
const endPhotoPos = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.media);
|
2018-05-04 06:23:48 +08:00
|
|
|
if (_animate) {
|
|
|
|
this.animatePhoto(starPhotoPos, endPhotoPos);
|
|
|
|
}
|
|
|
|
if (_animate) {
|
|
|
|
this.animateLightbox(<Dimension>{
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
2018-05-14 10:10:56 +08:00
|
|
|
width: Math.max(this.getPhotoFrameWidth() - 400, 0),
|
2018-05-04 06:23:48 +08:00
|
|
|
height: this.getPhotoFrameHeight()
|
|
|
|
},
|
|
|
|
<Dimension>{
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
width: this.getPhotoFrameWidth(),
|
|
|
|
height: this.getPhotoFrameHeight()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public play() {
|
|
|
|
this.pause();
|
|
|
|
this.timerSub = this.timer.pipe(filter(t => t % 2 === 0)).subscribe(() => {
|
2018-11-18 02:32:31 +08:00
|
|
|
if (this.mediaElement.imageLoadFinished === false) {
|
2018-05-04 06:23:48 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-11-12 02:22:46 +08:00
|
|
|
// do not skip video if its playing
|
|
|
|
if (this.activePhoto && this.activePhoto.gridPhoto.isVideo() &&
|
2018-11-18 02:32:31 +08:00
|
|
|
!this.mediaElement.Paused) {
|
2018-11-12 02:22:46 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-05-04 06:23:48 +08:00
|
|
|
if (this.navigation.hasNext) {
|
|
|
|
this.nextImage();
|
|
|
|
} else {
|
2018-05-27 08:49:55 +08:00
|
|
|
this.navigateToPhoto(0);
|
2018-05-04 06:23:48 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.playBackState = 1;
|
|
|
|
}
|
|
|
|
|
2017-07-10 04:00:42 +08:00
|
|
|
showInfoPanel() {
|
|
|
|
this.infoPanelVisible = true;
|
2017-07-11 04:00:22 +08:00
|
|
|
|
2018-11-05 02:28:32 +08:00
|
|
|
const starPhotoPos = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.media);
|
2017-07-11 04:00:22 +08:00
|
|
|
this.infoPanelWidth = 400;
|
2018-11-05 02:28:32 +08:00
|
|
|
const endPhotoPos = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.media);
|
2017-07-11 04:00:22 +08:00
|
|
|
this.animatePhoto(starPhotoPos, endPhotoPos);
|
|
|
|
this.animateLightbox(<Dimension>{
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
2017-07-17 02:49:12 +08:00
|
|
|
width: this.getPhotoFrameWidth() + 400,
|
|
|
|
height: this.getPhotoFrameHeight()
|
2017-07-11 04:00:22 +08:00
|
|
|
},
|
|
|
|
<Dimension>{
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
2017-07-17 02:49:12 +08:00
|
|
|
width: this.getPhotoFrameWidth(),
|
|
|
|
height: this.getPhotoFrameHeight()
|
2017-07-11 04:00:22 +08:00
|
|
|
});
|
2017-07-10 04:00:42 +08:00
|
|
|
if (this.iPvisibilityTimer != null) {
|
|
|
|
clearTimeout(this.iPvisibilityTimer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-04 06:23:48 +08:00
|
|
|
public fastForward() {
|
|
|
|
this.pause();
|
|
|
|
this.timerSub = this.timer.subscribe(() => {
|
2018-11-18 02:32:31 +08:00
|
|
|
if (this.mediaElement.imageLoadFinished === false) {
|
2018-05-04 06:23:48 +08:00
|
|
|
return;
|
2018-11-12 02:22:46 +08:00
|
|
|
}
|
|
|
|
if (this.activePhoto && this.activePhoto.gridPhoto.isVideo() &&
|
2018-11-18 02:32:31 +08:00
|
|
|
!this.mediaElement.Paused) {
|
2018-11-12 02:22:46 +08:00
|
|
|
return;
|
2018-05-04 06:23:48 +08:00
|
|
|
}
|
|
|
|
if (this.navigation.hasNext) {
|
|
|
|
this.nextImage();
|
|
|
|
} else {
|
2018-05-27 08:49:55 +08:00
|
|
|
this.navigateToPhoto(0);
|
2018-05-04 06:23:48 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.playBackState = 2;
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-01 00:01:54 +08:00
|
|
|
|
2016-05-01 03:36:24 +08:00
|
|
|
|
2018-05-14 10:10:56 +08:00
|
|
|
public getPhotoFrameWidth(): number {
|
2017-07-10 04:00:42 +08:00
|
|
|
return Math.max(window.innerWidth - this.infoPanelWidth, 0);
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-07-06 18:53:49 +08:00
|
|
|
|
2018-05-14 10:10:56 +08:00
|
|
|
public getPhotoFrameHeight(): number {
|
2017-06-11 04:32:56 +08:00
|
|
|
return window.innerHeight;
|
|
|
|
}
|
2016-12-30 18:58:04 +08:00
|
|
|
|
2018-05-14 10:10:56 +08:00
|
|
|
public getWindowAspectRatio(): number {
|
|
|
|
return Math.round(this.getPhotoFrameWidth() / this.getPhotoFrameHeight() * 100) / 100;
|
|
|
|
}
|
|
|
|
|
2018-05-04 06:23:48 +08:00
|
|
|
private updateActivePhoto(photoIndex: number, resize: boolean = true) {
|
|
|
|
const pcList = this.gridPhotoQL.toArray();
|
2016-12-30 18:58:04 +08:00
|
|
|
|
2018-05-04 06:23:48 +08:00
|
|
|
|
|
|
|
if (photoIndex < 0 || photoIndex > this.gridPhotoQL.length) {
|
2018-11-05 02:28:32 +08:00
|
|
|
throw new Error('Can\'t find the media');
|
2018-05-04 06:23:48 +08:00
|
|
|
}
|
|
|
|
this.activePhotoId = photoIndex;
|
|
|
|
this.activePhoto = pcList[photoIndex];
|
|
|
|
|
|
|
|
if (resize) {
|
2018-11-05 02:28:32 +08:00
|
|
|
this.animatePhoto(this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.media));
|
2018-05-04 06:23:48 +08:00
|
|
|
}
|
|
|
|
this.navigation.hasPrev = photoIndex > 0;
|
|
|
|
this.navigation.hasNext = photoIndex + 1 < pcList.length;
|
|
|
|
|
|
|
|
const to = this.activePhoto.getDimension();
|
|
|
|
|
|
|
|
// if target image out of screen -> scroll to there
|
2018-05-27 08:49:55 +08:00
|
|
|
if (PageHelper.ScrollY > to.top || PageHelper.ScrollY + this.getPhotoFrameHeight() < to.top) {
|
|
|
|
PageHelper.ScrollY = to.top;
|
2016-05-01 03:36:24 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2017-07-12 02:23:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
@HostListener('mousemove')
|
2018-05-27 08:49:55 +08:00
|
|
|
onMouseMove() {
|
2017-07-12 02:23:25 +08:00
|
|
|
this.showControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
private showControls() {
|
|
|
|
this.controllersDimmed = true;
|
|
|
|
if (this.visibilityTimer != null) {
|
|
|
|
clearTimeout(this.visibilityTimer);
|
|
|
|
}
|
|
|
|
this.visibilityTimer = setTimeout(this.hideControls, 2000);
|
|
|
|
}
|
|
|
|
|
|
|
|
private hideControls = () => {
|
|
|
|
|
|
|
|
this.controllersDimmed = false;
|
|
|
|
};
|
|
|
|
|
2017-07-17 02:49:12 +08:00
|
|
|
|
2017-07-12 02:23:25 +08:00
|
|
|
public pause() {
|
|
|
|
if (this.timerSub != null) {
|
|
|
|
this.timerSub.unsubscribe();
|
|
|
|
}
|
|
|
|
this.playBackState = 0;
|
|
|
|
}
|
|
|
|
|
2018-11-05 02:28:32 +08:00
|
|
|
private findPhotoComponent(media: MediaDTO): GalleryPhotoComponent {
|
2018-05-04 06:23:48 +08:00
|
|
|
const galleryPhotoComponents = this.gridPhotoQL.toArray();
|
|
|
|
for (let i = 0; i < galleryPhotoComponents.length; i++) {
|
2018-11-05 02:28:32 +08:00
|
|
|
if (galleryPhotoComponents[i].gridPhoto.media === media) {
|
2018-05-04 06:23:48 +08:00
|
|
|
return galleryPhotoComponents[i];
|
2017-07-12 02:23:25 +08:00
|
|
|
}
|
2018-05-04 06:23:48 +08:00
|
|
|
}
|
|
|
|
return null;
|
2017-07-12 02:23:25 +08:00
|
|
|
}
|
|
|
|
|
2018-11-05 02:28:32 +08:00
|
|
|
private calcLightBoxPhotoDimension(photo: MediaDTO): Dimension {
|
2018-05-04 06:23:48 +08:00
|
|
|
let width = 0;
|
|
|
|
let height = 0;
|
|
|
|
const photoAspect = photo.metadata.size.width / photo.metadata.size.height;
|
|
|
|
const windowAspect = this.getPhotoFrameWidth() / this.getPhotoFrameHeight();
|
|
|
|
if (photoAspect < windowAspect) {
|
|
|
|
width = Math.round(photo.metadata.size.width * (this.getPhotoFrameHeight() / photo.metadata.size.height));
|
|
|
|
height = this.getPhotoFrameHeight();
|
|
|
|
} else {
|
|
|
|
width = this.getPhotoFrameWidth();
|
|
|
|
height = Math.round(photo.metadata.size.height * (this.getPhotoFrameWidth() / photo.metadata.size.width));
|
|
|
|
}
|
|
|
|
const top = (this.getPhotoFrameHeight() / 2 - height / 2);
|
|
|
|
const left = (this.getPhotoFrameWidth() / 2 - width / 2);
|
|
|
|
|
|
|
|
return <Dimension>{top: top, left: left, width: width, height: height};
|
2017-07-12 02:23:25 +08:00
|
|
|
}
|
2018-05-27 08:49:55 +08:00
|
|
|
|
|
|
|
public isVisible(): boolean {
|
|
|
|
return this.status !== LightboxStates.Closed;
|
|
|
|
}
|
2016-05-01 00:01:54 +08:00
|
|
|
}
|
|
|
|
|