Skip to content

Commit

Permalink
feat: add Square thumbnails #76 - now you can choose between <img> or…
Browse files Browse the repository at this point in the history
… <a> images
  • Loading branch information
Ks89 committed Dec 12, 2017
1 parent 00c21da commit 4ae5916
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export class GalleryComponent implements OnInit {
size: {
width: '50px',
height: 'auto'
},
advanced: {
aTags: false
}
};

Expand Down
25 changes: 20 additions & 5 deletions angular-modal-gallery/src/components/gallery/gallery.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,27 @@

<ng-container *ngFor="let imgRow of imageGrid; let i = index">
<ng-container *ngFor="let imgCol of imgRow; let j = index">
<img *ngIf="imgCol && imgCol.img"
[src]="imgCol.thumb ? imgCol.thumb : imgCol.img"
class="image"

<ng-container *ngIf="!configPlainGallery.advanced?.aTags; else aTags">
<img *ngIf="imgCol && imgCol.img"
[src]="imgCol.thumb ? imgCol.thumb : imgCol.img"
class="image"
ksSize [sizeConfig]="{width: configPlainGallery.size.width, height: configPlainGallery.size.height}"
alt="{{getAltDescriptionByIndex(j)}}"
(click)="showModalGallery(j)"/>
</ng-container>

<!-- Add directive to set background with the image url as param to pass thumb or img-->
<!-- to do something like this <a style="background: url('path to image') 50% 50%/cover">.-->
<ng-template #aTags>
<a *ngIf="imgCol && imgCol.img"
href="#"
class="aTagImage"
ksATagBgImage [image]="imgCol" [style]="'50% 50%/cover'"
ksSize [sizeConfig]="{width: configPlainGallery.size.width, height: configPlainGallery.size.height}"
alt="{{getAltDescriptionByIndex(j)}}"
(click)="showModalGallery(j)"/>
(click)="showModalGallery(j)"></a>
</ng-template>

</ng-container>
</ng-container>

Expand Down
9 changes: 8 additions & 1 deletion angular-modal-gallery/src/components/gallery/gallery.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
The MIT License (MIT)
Copyright (c) 2017 Stefano Cappa (Ks89)
Copyright (c) 2016 vimalavinisha
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -38,4 +37,12 @@
margin-right: 2px;
cursor: pointer;
}

.aTagImage  {
//width: 50px;
//height: auto;
margin-left: 2px;
margin-right: 2px;
cursor: pointer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
The MIT License (MIT)
Copyright (c) 2017 Stefano Cappa (Ks89)
Copyright (c) 2016 vimalavinisha (only for version 1)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
The MIT License (MIT)
Copyright (c) 2017 Stefano Cappa (Ks89)
Copyright (c) 2016 vimalavinisha
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 26 additions & 0 deletions angular-modal-gallery/src/directives/a-tag-bg-image.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Directive, ElementRef, Input, OnChanges, OnInit, Renderer2, SimpleChanges } from '@angular/core';
import { Image } from '../interfaces/image.class';

@Directive({
selector: '[ksATagBgImage]'
})
export class ATagBgImageDirective implements OnInit, OnChanges {

@Input() image: Image;
@Input() style: string;

constructor(private renderer: Renderer2, private el: ElementRef) {
}

ngOnInit() {
this.applyStyle();
}

ngOnChanges(changes: SimpleChanges) {
this.applyStyle();
}

private applyStyle() {
this.renderer.setStyle(this.el.nativeElement, 'background', `url('${this.image.thumb ? this.image.thumb : this.image.img}') ${this.style}`);
}
}
4 changes: 3 additions & 1 deletion angular-modal-gallery/src/directives/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import { KeyboardNavigationDirective } from './keyboard-navigation.directive';
import { ScrollStopDirective } from './scroll-stop.directive';
import { WrapDirective } from './wrap.directive';
import { DirectionDirective } from './direction.directive';
import { ATagBgImageDirective } from './a-tag-bg-image.directive';

/**
* Array of all directives.
*/
export const DIRECTIVES = [
ClickOutsideDirective, SizeDirective, KeyboardNavigationDirective,
ScrollStopDirective, WrapDirective, DirectionDirective
ScrollStopDirective, WrapDirective, DirectionDirective,
ATagBgImageDirective
];
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface PlainGalleryConfig {
strategy: PlainGalleryStrategy;
layout: PlainGalleryLayout;
size: Size;
advanced?: AdvancedConfig;
}

export class PlainGalleryLayout {
Expand Down Expand Up @@ -51,3 +52,7 @@ export interface BreakConfig {
iconClass: string;
wrap: boolean;
}

export interface AdvancedConfig {
aTags: boolean;
}
6 changes: 6 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ <h3>Z1bis - row plain gallery layout space around (limit 2)</h3>
<ks-modal-gallery [modalImages]="images"
[plainGalleryConfig]="plainGalleryRowSpaceAround"></ks-modal-gallery>
</section>
<section>
<h3>Z1tris - row plain gallery layout with a tags (limit 2)</h3>
<br>
<ks-modal-gallery [modalImages]="images"
[plainGalleryConfig]="plainGalleryRowATags"></ks-modal-gallery>
</section>
<section>
<h3>Z2 - column plain gallery layout (limit 3)</h3>
<br>
Expand Down
35 changes: 15 additions & 20 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,8 @@
import { Component } from '@angular/core';

import {
AccessibilityConfig,
Action,
ButtonEvent,
ButtonsConfig,
ButtonsStrategy,
ButtonType,
Description,
DescriptionStrategy,
DotsConfig,
Image,
ImageModalEvent,
PreviewConfig,
PlainGalleryConfig,
LineLayout,
PlainGalleryStrategy,
GridLayout
AccessibilityConfig, Action, ButtonEvent, ButtonsConfig, ButtonsStrategy, ButtonType, Description, DescriptionStrategy, DotsConfig, GridLayout,
Image, ImageModalEvent, LineLayout, PlainGalleryConfig, PlainGalleryStrategy, PreviewConfig
} from 'angular-modal-gallery';

@Component({
Expand All @@ -55,24 +41,33 @@ export class AppComponent {

plainGalleryRow: PlainGalleryConfig = {
strategy: PlainGalleryStrategy.ROW,
layout: new LineLayout({length: 2, iconClass: '', wrap: true}, 'flex-start'),
layout: new LineLayout({length: 2, iconClass: '', wrap: true}, 'flex-start'),
size: {
width: '80px',
height: '80px'
}
};
plainGalleryRowSpaceAround: PlainGalleryConfig = {
strategy: PlainGalleryStrategy.ROW,
layout: new LineLayout({length: 2, iconClass: '', wrap: true}, 'space-around'),
layout: new LineLayout({length: 2, iconClass: '', wrap: true}, 'space-around'),
size: {
width: '50px',
height: '50px'
}
};
plainGalleryRowATags: PlainGalleryConfig = {
strategy: PlainGalleryStrategy.ROW,
layout: new LineLayout({length: 2, iconClass: '', wrap: true}, 'flex-start'),
size: {
width: '50px',
height: '50px'
},
advanced: {aTags: true}
};

plainGalleryColumn: PlainGalleryConfig = {
strategy: PlainGalleryStrategy.COLUMN,
layout: new LineLayout({length: 3, iconClass: '', wrap: true}, 'flex-start'),
layout: new LineLayout({length: 3, iconClass: '', wrap: true}, 'flex-start'),
size: {
width: '50px',
height: '50px'
Expand All @@ -81,7 +76,7 @@ export class AppComponent {

plainGalleryGrid: PlainGalleryConfig = {
strategy: PlainGalleryStrategy.GRID,
layout: new GridLayout({length: 3, iconClass: '', wrap: true}),
layout: new GridLayout({length: 3, iconClass: '', wrap: true}),
size: {
width: '80px',
height: '80px'
Expand Down

0 comments on commit 4ae5916

Please sign in to comment.