1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

implementing lightbox image navigation

This commit is contained in:
Braun Patrik 2016-05-12 23:00:38 +02:00
parent 33347dfd0c
commit 61ba450e04
5 changed files with 117 additions and 27 deletions

View File

@ -52,6 +52,11 @@ export class GalleryMWs {
return next(); return next();
} }
//check if thumbnail already exist
if (fs.existsSync(fullImagePath) === false) {
return next(new Error(ErrorCodes.GENERAL_ERROR, "no such file :" + fullImagePath));
}
req.resultPipe = fullImagePath; req.resultPipe = fullImagePath;
return next(); return next();
} }

View File

@ -19,7 +19,7 @@ export class GalleryRouter {
private addDirectoryList() { private addDirectoryList() {
this.app.get(["/api/gallery/content/:directory(*)", "/api/gallery/", "/api/gallery//"], this.app.get(["/api/gallery/content/:directory(*)", "/api/gallery/", "/api/gallery//"],
// AuthenticationMWs.authenticate, AuthenticationMWs.authenticate,
GalleryMWs.listDirectory, GalleryMWs.listDirectory,
RenderingMWs.renderResult RenderingMWs.renderResult
); );

View File

@ -21,12 +21,42 @@
height: 100%; /* Full height */ height: 100%; /* Full height */
background-color: black; background-color: black;
} }
img {
width: 100%; .imgContainer img {
height: 100%; position: absolute;
} }
.imgContainer{ .imgContainer{
justify-content: center; /* add to align horizontal */ justify-content: center; /* add to align horizontal */
align-items: center; /* add to align vertical */ align-items: center; /* add to align vertical */
}
.navigation-arrow {
font-size: x-large;
width: 50%;
height: 100%;
position: static;
display: inline-block;
padding: 15px;
color: white;
opacity: 0.4;
}
.navigation-arrow span {
top: 50%;
}
.navigation-arrow:hover {
opacity: 1.0;
}
#navigation-arrow-container {
width: 100%;
height: 100%;
left: 0;
position: fixed;;
}
#rightArrow {
float: right;
text-align: right;
} }

View File

@ -1,15 +1,27 @@
<div <div
[hidden]="!activePhoto" [hidden]="!activePhoto"
(click)="hide()"> >
<div class="blackCanvas" <div class="blackCanvas" #blackCanvas>
#blackCanvas>
</div> </div>
<div class="lightbox" <div class="lightbox" #lightbox>
#lightbox> <div #imgContainer class="imgContainer">
<div class="imgContainer"> <img *ngIf="activePhoto"
<img #thImage [src]="getThumbnailPath()" /> [style.width.%]="imageSize.width"
<img #image [src]="getPhotoPath()" style="position:absolute;"/> [style.height.%]="imageSize.height"
</div> [src]="activePhoto.gridPhoto.getThumbnailPath()"/>
</div>
</div> <img *ngIf="activePhoto"
[style.width.%]="imageSize.width"
[style.height.%]="imageSize.height"
[src]="activePhoto.gridPhoto.getPhotoPath()"/>
</div>
<div id="navigation-arrow-container">
<div class="navigation-arrow" id="leftArrow" (click)="prevImage()"><span
class="glyphicon glyphicon-chevron-left"></span></div>
<div class="navigation-arrow" id="rightArrow" (click)="nextImage()"><span
class="glyphicon glyphicon-chevron-right"></span></div>
</div>
</div>
</div>

View File

@ -16,9 +16,10 @@ export class GalleryLightboxComponent {
@ViewChild('lightbox') lightBoxDiv:ElementRef; @ViewChild('lightbox') lightBoxDiv:ElementRef;
@ViewChild('blackCanvas') blackCanvasDiv:ElementRef; @ViewChild('blackCanvas') blackCanvasDiv:ElementRef;
@ViewChild('thImage') thIMageImg:ElementRef; @ViewChild('imgContainer') imgContainer:ElementRef;
@ViewChild('image') imageImg:ElementRef;
public imageSize = {width: "auto", height: "100"};
private activePhoto:GalleryPhotoComponent = null; private activePhoto:GalleryPhotoComponent = null;
public gridPhotoQL:QueryList<GalleryPhotoComponent>; public gridPhotoQL:QueryList<GalleryPhotoComponent>;
@ -31,6 +32,54 @@ export class GalleryLightboxComponent {
} }
public nextImage() {
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];
let toImage = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.photo).toStyle();
this.forceAnimateFrom(toImage,
{},
this.imgContainer.nativeElement);
this.setImageSize();
return;
}
}
}
public prevImage() {
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];
let toImage = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.photo).toStyle();
this.forceAnimateFrom(toImage,
{},
this.imgContainer.nativeElement);
this.setImageSize();
return;
}
}
}
private setImageSize() {
if (this.activePhoto.gridPhoto.photo.metadata.size.height > this.activePhoto.gridPhoto.photo.metadata.size.width) {
this.imageSize.height = "100";
this.imageSize.width = null;
} else {
this.imageSize.height = null;
this.imageSize.width = "100";
}
}
public show(photo:Photo) { public show(photo:Photo) {
let selectedPhoto = this.findPhotoComponenet(photo); let selectedPhoto = this.findPhotoComponenet(photo);
if (selectedPhoto === null) { if (selectedPhoto === null) {
@ -39,6 +88,7 @@ export class GalleryLightboxComponent {
this.dom.setStyle(this.dom.query('body'), 'overflow', 'hidden'); this.dom.setStyle(this.dom.query('body'), 'overflow', 'hidden');
this.activePhoto = selectedPhoto; this.activePhoto = selectedPhoto;
this.setImageSize();
let from = this.activePhoto.getDimension(); let from = this.activePhoto.getDimension();
@ -50,11 +100,7 @@ export class GalleryLightboxComponent {
this.forceAnimateFrom(fromImage, this.forceAnimateFrom(fromImage,
toImage, toImage,
this.thIMageImg.nativeElement); this.imgContainer.nativeElement);
this.forceAnimateFrom(fromImage,
toImage,
this.imageImg.nativeElement);
this.forceAnimateFrom(from.toStyle(), this.forceAnimateFrom(from.toStyle(),
{height: "100%", width: "100%", "top": "0px", "left": "0px"}, {height: "100%", width: "100%", "top": "0px", "left": "0px"},
@ -94,11 +140,8 @@ export class GalleryLightboxComponent {
this.forceAnimateTo(fromImage, this.forceAnimateTo(fromImage,
toImage, toImage,
this.thIMageImg.nativeElement); this.imgContainer.nativeElement);
this.forceAnimateTo(fromImage,
toImage,
this.imageImg.nativeElement);
} }