2017-03-26 04:59:30 +08:00
|
|
|
import {Component, Input, OnChanges} from "@angular/core";
|
2016-05-13 20:27:00 +08:00
|
|
|
import {GridPhoto} from "../../grid/GridPhoto";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'gallery-lightbox-photo',
|
|
|
|
styleUrls: ['app/gallery/lightbox/photo/photo.lightbox.gallery.component.css'],
|
|
|
|
templateUrl: 'app/gallery/lightbox/photo/photo.lightbox.gallery.component.html'
|
|
|
|
})
|
|
|
|
export class GalleryLightboxPhotoComponent implements OnChanges {
|
|
|
|
|
2017-03-26 04:59:30 +08:00
|
|
|
@Input() gridPhoto: GridPhoto;
|
2016-05-13 20:27:00 +08:00
|
|
|
|
|
|
|
public imageSize = {width: "auto", height: "100"};
|
|
|
|
|
2017-03-26 04:59:30 +08:00
|
|
|
imageLoaded: boolean = false;
|
2016-05-13 20:27:00 +08:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges() {
|
2016-07-04 22:58:10 +08:00
|
|
|
|
|
|
|
this.imageLoaded = false;
|
2016-05-13 20:27:00 +08:00
|
|
|
this.setImageSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
private setImageSize() {
|
|
|
|
if (!this.gridPhoto) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.gridPhoto.photo.metadata.size.height > this.gridPhoto.photo.metadata.size.width) {
|
|
|
|
this.imageSize.height = "100";
|
|
|
|
this.imageSize.width = null;
|
|
|
|
} else {
|
|
|
|
this.imageSize.height = null;
|
|
|
|
this.imageSize.width = "100";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 22:58:10 +08:00
|
|
|
|
|
|
|
onImageLoad() {
|
|
|
|
this.imageLoaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
onImageError() {
|
|
|
|
//TODO:handle error
|
|
|
|
console.error("cant load image");
|
|
|
|
}
|
|
|
|
|
2017-03-26 04:59:30 +08:00
|
|
|
public showThumbnail(): boolean {
|
2016-07-04 22:58:10 +08:00
|
|
|
return this.gridPhoto && !this.imageLoaded &&
|
|
|
|
(this.gridPhoto.isThumbnailAvailable() || this.gridPhoto.isReplacementThumbnailAvailable());
|
|
|
|
}
|
|
|
|
|
2017-03-26 04:59:30 +08:00
|
|
|
public thumbnailPath(): string {
|
2016-07-04 22:58:10 +08:00
|
|
|
if (this.gridPhoto.isThumbnailAvailable() === true)
|
|
|
|
return this.gridPhoto.getThumbnailPath();
|
|
|
|
|
|
|
|
if (this.gridPhoto.isReplacementThumbnailAvailable() === true)
|
|
|
|
return this.gridPhoto.getReplacementThumbnailPath();
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2016-05-13 20:27:00 +08:00
|
|
|
}
|
|
|
|
|