From d82c9eec93ca2d3f27dd9b5d88bd9947da981ffc Mon Sep 17 00:00:00 2001 From: Braun Patrik Date: Mon, 4 Jul 2016 22:10:30 +0200 Subject: [PATCH] lightbox next, prev button bugfix --- .../lightbox/lightbox.gallery.component.ts | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/frontend/app/gallery/lightbox/lightbox.gallery.component.ts b/frontend/app/gallery/lightbox/lightbox.gallery.component.ts index e0aafd9..e355916 100644 --- a/frontend/app/gallery/lightbox/lightbox.gallery.component.ts +++ b/frontend/app/gallery/lightbox/lightbox.gallery.component.ts @@ -36,18 +36,12 @@ export class GalleryLightboxComponent { let pcList = this.gridPhotoQL.toArray(); for (let i = 0; i < pcList.length; i++) { if (pcList[i] === this.activePhoto && i + 1 < pcList.length) { - this.activePhoto = pcList[i + 1]; - this.navigation.hasPrev = true; - - this.navigation.hasNext = i + 2 < pcList.length; - + this.showPhoto(pcList[i + 1]); + if (i + 3 === pcList.length) { this.onLastElement.emit({}); //trigger to render more photos if there are } - this.photoDimension = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.photo); - - return; } } @@ -57,29 +51,35 @@ export class GalleryLightboxComponent { let pcList = this.gridPhotoQL.toArray(); for (let i = 0; i < pcList.length; i++) { if (pcList[i] === this.activePhoto && i > 0) { - this.activePhoto = pcList[i - 1]; - this.navigation.hasNext = true; - this.navigation.hasPrev = i - 1 > 0; - - this.photoDimension = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.photo); - - + this.showPhoto(pcList[i - 1]); 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) { let selectedPhoto = this.findPhotoComponent(photo); if (selectedPhoto === null) { throw new Error("Can't find Photo"); } + this.showPhoto(selectedPhoto); this.dom.setStyle(this.dom.query('body'), 'overflow', 'hidden'); - this.activePhoto = selectedPhoto; - this.photoDimension = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.photo); - } public hide() { @@ -98,14 +98,12 @@ export class GalleryLightboxComponent { private findPhotoComponent(photo) { let galleryPhotoComponents = this.gridPhotoQL.toArray(); - let selectedPhoto:GalleryPhotoComponent = null; for (let i = 0; i < galleryPhotoComponents.length; i++) { if (galleryPhotoComponents[i].gridPhoto.photo == photo) { - selectedPhoto = galleryPhotoComponents[i]; - break; + return galleryPhotoComponents[i]; } } - return selectedPhoto; + return null; }