1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/gallery/lightbox/photo/photo.lightbox.gallery.component.ts

77 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-03-31 03:30:30 +08:00
import {Component, ElementRef, Input, OnChanges} from '@angular/core';
import {GridPhoto} from '../../grid/GridPhoto';
2016-05-13 20:27:00 +08:00
@Component({
selector: 'gallery-lightbox-photo',
styleUrls: ['./photo.lightbox.gallery.component.css'],
templateUrl: './photo.lightbox.gallery.component.html'
2016-05-13 20:27:00 +08:00
})
export class GalleryLightboxPhotoComponent implements OnChanges {
@Input() gridPhoto: GridPhoto;
2018-05-04 06:23:48 +08:00
@Input() loadImage = false;
@Input() windowAspect = 1;
2016-05-13 20:27:00 +08:00
2018-03-31 03:30:30 +08:00
public imageSize = {width: 'auto', height: '100'};
2016-05-13 20:27:00 +08:00
2018-05-04 06:23:48 +08:00
imageLoaded = false;
public imageLoadFinished = false;
2016-05-13 20:27:00 +08:00
constructor(public elementRef: ElementRef) {
}
ngOnChanges() {
2016-05-13 20:27:00 +08:00
this.imageLoaded = false;
2017-07-28 06:04:19 +08:00
this.imageLoadFinished = false;
this.setImageSize();
}
2018-03-31 03:30:30 +08:00
onImageError() {
2018-05-04 06:23:48 +08:00
// TODO:handle error
2018-03-31 03:30:30 +08:00
this.imageLoadFinished = true;
console.error('cant load image');
}
2016-05-13 20:27:00 +08:00
onImageLoad() {
2017-07-28 06:04:19 +08:00
this.imageLoadFinished = true;
this.imageLoaded = true;
}
2018-03-31 03:30:30 +08:00
public thumbnailPath(): string {
2018-05-04 06:23:48 +08:00
if (this.gridPhoto.isThumbnailAvailable() === true) {
2018-03-31 03:30:30 +08:00
return this.gridPhoto.getThumbnailPath();
2018-05-04 06:23:48 +08:00
}
2018-03-31 03:30:30 +08:00
2018-05-04 06:23:48 +08:00
if (this.gridPhoto.isReplacementThumbnailAvailable() === true) {
2018-03-31 03:30:30 +08:00
return this.gridPhoto.getReplacementThumbnailPath();
2018-05-04 06:23:48 +08:00
}
2018-03-31 03:30:30 +08:00
return null;
}
public showThumbnail(): boolean {
2018-05-04 06:23:48 +08:00
return this.gridPhoto /*&& !this.imageLoaded*/ &&
(this.gridPhoto.isThumbnailAvailable() || this.gridPhoto.isReplacementThumbnailAvailable());
}
2018-03-31 03:30:30 +08:00
private setImageSize() {
if (!this.gridPhoto) {
return;
}
2018-03-31 03:30:30 +08:00
const photoAspect = this.gridPhoto.photo.metadata.size.width / this.gridPhoto.photo.metadata.size.height;
if (photoAspect < this.windowAspect) {
this.imageSize.height = '100';
this.imageSize.width = null;
} else {
this.imageSize.height = null;
this.imageSize.width = '100';
}
}
2016-05-13 20:27:00 +08:00
}