mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
improving thumbnail loading
This commit is contained in:
parent
1de7dabe52
commit
12c8c912f1
@ -18,10 +18,30 @@ export class GridPhoto {
|
|||||||
return Utils.findClosest(renderSize, Config.Client.thumbnailSizes);
|
return Utils.findClosest(renderSize, Config.Client.thumbnailSizes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getReplacementThumbnailSize() {
|
||||||
|
let size = this.getThumbnailSize();
|
||||||
|
for (let i = 0; i < this.photo.readyThumbnails.length; i++) {
|
||||||
|
if (this.photo.readyThumbnails[i] < size) {
|
||||||
|
return this.photo.readyThumbnails[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
isReplacementThumbnailAvailable() {
|
||||||
|
return this.getReplacementThumbnailSize() !== null;
|
||||||
|
}
|
||||||
|
|
||||||
isThumbnailAvailable() {
|
isThumbnailAvailable() {
|
||||||
return this.photo.readyThumbnails.indexOf(this.getThumbnailSize()) != -1;
|
return this.photo.readyThumbnails.indexOf(this.getThumbnailSize()) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getReplacementThumbnailPath() {
|
||||||
|
let size = this.getReplacementThumbnailSize();
|
||||||
|
return Utils.concatUrls("/api/gallery/content/", this.photo.directory.path, this.photo.directory.name, this.photo.name, "thumbnail", size.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
getThumbnailPath() {
|
getThumbnailPath() {
|
||||||
let size = this.getThumbnailSize();
|
let size = this.getThumbnailSize();
|
||||||
return Utils.concatUrls("/api/gallery/content/", this.photo.directory.path, this.photo.directory.name, this.photo.name, "thumbnail", size.toString());
|
return Utils.concatUrls("/api/gallery/content/", this.photo.directory.path, this.photo.directory.name, this.photo.name, "thumbnail", size.toString());
|
||||||
|
@ -22,7 +22,7 @@ export class GalleryPhotoComponent implements IRenderable, AfterViewInit {
|
|||||||
|
|
||||||
|
|
||||||
image = {
|
image = {
|
||||||
src: "#",
|
src: '',
|
||||||
show: false
|
show: false
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -51,6 +51,22 @@ export class GalleryPhotoComponent implements IRenderable, AfterViewInit {
|
|||||||
this.image.src = this.gridPhoto.getThumbnailPath();
|
this.image.src = this.gridPhoto.getThumbnailPath();
|
||||||
this.image.show = true;
|
this.image.show = true;
|
||||||
this.loading.show = false;
|
this.loading.show = false;
|
||||||
|
} else if (this.gridPhoto.isReplacementThumbnailAvailable()) {
|
||||||
|
|
||||||
|
this.image.src = this.gridPhoto.getReplacementThumbnailPath();
|
||||||
|
this.image.show = true;
|
||||||
|
this.loading.show = false;
|
||||||
|
this.thumbnailService.loadImage(this.gridPhoto,
|
||||||
|
()=> { //onLoadStarted
|
||||||
|
},
|
||||||
|
()=> {//onLoaded
|
||||||
|
this.image.src = this.gridPhoto.getThumbnailPath();
|
||||||
|
},
|
||||||
|
(error)=> {//onError
|
||||||
|
//TODO: handle error
|
||||||
|
console.error("something bad happened");
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.loading.show = true;
|
this.loading.show = true;
|
||||||
this.thumbnailService.loadImage(this.gridPhoto,
|
this.thumbnailService.loadImage(this.gridPhoto,
|
||||||
|
Loading…
Reference in New Issue
Block a user