lightbox next, prev button bugfix
This commit is contained in:
parent
a7a8e42490
commit
d82c9eec93
@ -36,18 +36,12 @@ export class GalleryLightboxComponent {
|
|||||||
let pcList = this.gridPhotoQL.toArray();
|
let pcList = this.gridPhotoQL.toArray();
|
||||||
for (let i = 0; i < pcList.length; i++) {
|
for (let i = 0; i < pcList.length; i++) {
|
||||||
if (pcList[i] === this.activePhoto && i + 1 < pcList.length) {
|
if (pcList[i] === this.activePhoto && i + 1 < pcList.length) {
|
||||||
this.activePhoto = pcList[i + 1];
|
this.showPhoto(pcList[i + 1]);
|
||||||
this.navigation.hasPrev = true;
|
|
||||||
|
|
||||||
this.navigation.hasNext = i + 2 < pcList.length;
|
|
||||||
|
|
||||||
if (i + 3 === pcList.length) {
|
if (i + 3 === pcList.length) {
|
||||||
this.onLastElement.emit({}); //trigger to render more photos if there are
|
this.onLastElement.emit({}); //trigger to render more photos if there are
|
||||||
}
|
}
|
||||||
|
|
||||||
this.photoDimension = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.photo);
|
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,29 +51,35 @@ export class GalleryLightboxComponent {
|
|||||||
let pcList = this.gridPhotoQL.toArray();
|
let pcList = this.gridPhotoQL.toArray();
|
||||||
for (let i = 0; i < pcList.length; i++) {
|
for (let i = 0; i < pcList.length; i++) {
|
||||||
if (pcList[i] === this.activePhoto && i > 0) {
|
if (pcList[i] === this.activePhoto && i > 0) {
|
||||||
this.activePhoto = pcList[i - 1];
|
this.showPhoto(pcList[i - 1]);
|
||||||
this.navigation.hasNext = true;
|
|
||||||
this.navigation.hasPrev = i - 1 > 0;
|
|
||||||
|
|
||||||
this.photoDimension = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.photo);
|
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private showPhoto(photoComponent:GalleryPhotoComponent) {
|
||||||
|
let pcList = this.gridPhotoQL.toArray();
|
||||||
|
|
||||||
|
let index = pcList.indexOf(photoComponent);
|
||||||
|
if (index == -1) {
|
||||||
|
throw new Error("Can't find the photo");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.navigation.hasPrev = index > 0;
|
||||||
|
this.navigation.hasNext = index + 1 < pcList.length;
|
||||||
|
this.activePhoto = photoComponent;
|
||||||
|
this.photoDimension = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.photo);
|
||||||
|
}
|
||||||
|
|
||||||
public show(photo:Photo) {
|
public show(photo:Photo) {
|
||||||
let selectedPhoto = this.findPhotoComponent(photo);
|
let selectedPhoto = this.findPhotoComponent(photo);
|
||||||
if (selectedPhoto === null) {
|
if (selectedPhoto === null) {
|
||||||
throw new Error("Can't find Photo");
|
throw new Error("Can't find Photo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.showPhoto(selectedPhoto);
|
||||||
this.dom.setStyle(this.dom.query('body'), 'overflow', 'hidden');
|
this.dom.setStyle(this.dom.query('body'), 'overflow', 'hidden');
|
||||||
this.activePhoto = selectedPhoto;
|
|
||||||
this.photoDimension = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.photo);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public hide() {
|
public hide() {
|
||||||
@ -98,14 +98,12 @@ export class GalleryLightboxComponent {
|
|||||||
|
|
||||||
private findPhotoComponent(photo) {
|
private findPhotoComponent(photo) {
|
||||||
let galleryPhotoComponents = this.gridPhotoQL.toArray();
|
let galleryPhotoComponents = this.gridPhotoQL.toArray();
|
||||||
let selectedPhoto:GalleryPhotoComponent = null;
|
|
||||||
for (let i = 0; i < galleryPhotoComponents.length; i++) {
|
for (let i = 0; i < galleryPhotoComponents.length; i++) {
|
||||||
if (galleryPhotoComponents[i].gridPhoto.photo == photo) {
|
if (galleryPhotoComponents[i].gridPhoto.photo == photo) {
|
||||||
selectedPhoto = galleryPhotoComponents[i];
|
return galleryPhotoComponents[i];
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return selectedPhoto;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user