@autotaxatiepartners/ngx-gallery 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +13 -0
- package/.eslintrc.json +51 -0
- package/.travis.yml +38 -0
- package/CHANGELOG.md +16 -0
- package/LICENSE +22 -0
- package/README.md +296 -0
- package/angular.json +108 -0
- package/package.json +71 -0
- package/projects/gallery/.eslintrc.json +55 -0
- package/projects/gallery/README.md +24 -0
- package/projects/gallery/karma.conf.js +52 -0
- package/projects/gallery/ng-package.json +7 -0
- package/projects/gallery/package.json +32 -0
- package/projects/gallery/src/lib/ngx-gallery-action/ngx-gallery-action.component.html +4 -0
- package/projects/gallery/src/lib/ngx-gallery-action/ngx-gallery-action.component.scss +21 -0
- package/projects/gallery/src/lib/ngx-gallery-action/ngx-gallery-action.component.spec.ts +25 -0
- package/projects/gallery/src/lib/ngx-gallery-action/ngx-gallery-action.component.ts +28 -0
- package/projects/gallery/src/lib/ngx-gallery-action.ts +23 -0
- package/projects/gallery/src/lib/ngx-gallery-animation.ts +6 -0
- package/projects/gallery/src/lib/ngx-gallery-arrows/ngx-gallery-arrows.component.html +12 -0
- package/projects/gallery/src/lib/ngx-gallery-arrows/ngx-gallery-arrows.component.scss +45 -0
- package/projects/gallery/src/lib/ngx-gallery-arrows/ngx-gallery-arrows.component.spec.ts +25 -0
- package/projects/gallery/src/lib/ngx-gallery-arrows/ngx-gallery-arrows.component.ts +28 -0
- package/projects/gallery/src/lib/ngx-gallery-bullets/ngx-gallery-bullets.component.html +4 -0
- package/projects/gallery/src/lib/ngx-gallery-bullets/ngx-gallery-bullets.component.scss +26 -0
- package/projects/gallery/src/lib/ngx-gallery-bullets/ngx-gallery-bullets.component.spec.ts +25 -0
- package/projects/gallery/src/lib/ngx-gallery-bullets/ngx-gallery-bullets.component.ts +25 -0
- package/projects/gallery/src/lib/ngx-gallery-image/ngx-gallery-image.component.html +49 -0
- package/projects/gallery/src/lib/ngx-gallery-image/ngx-gallery-image.component.scss +106 -0
- package/projects/gallery/src/lib/ngx-gallery-image/ngx-gallery-image.component.spec.ts +35 -0
- package/projects/gallery/src/lib/ngx-gallery-image/ngx-gallery-image.component.ts +395 -0
- package/projects/gallery/src/lib/ngx-gallery-image-size.ts +4 -0
- package/projects/gallery/src/lib/ngx-gallery-image.ts +31 -0
- package/projects/gallery/src/lib/ngx-gallery-layout.ts +4 -0
- package/projects/gallery/src/lib/ngx-gallery-options.ts +255 -0
- package/projects/gallery/src/lib/ngx-gallery-order.ts +5 -0
- package/projects/gallery/src/lib/ngx-gallery-ordered-image.ts +19 -0
- package/projects/gallery/src/lib/ngx-gallery-preview/ngx-gallery-preview.component.html +66 -0
- package/projects/gallery/src/lib/ngx-gallery-preview/ngx-gallery-preview.component.scss +121 -0
- package/projects/gallery/src/lib/ngx-gallery-preview/ngx-gallery-preview.component.spec.ts +34 -0
- package/projects/gallery/src/lib/ngx-gallery-preview/ngx-gallery-preview.component.ts +486 -0
- package/projects/gallery/src/lib/ngx-gallery-thumbnails/ngx-gallery-thumbnails.component.html +44 -0
- package/projects/gallery/src/lib/ngx-gallery-thumbnails/ngx-gallery-thumbnails.component.scss +87 -0
- package/projects/gallery/src/lib/ngx-gallery-thumbnails/ngx-gallery-thumbnails.component.spec.ts +31 -0
- package/projects/gallery/src/lib/ngx-gallery-thumbnails/ngx-gallery-thumbnails.component.ts +297 -0
- package/projects/gallery/src/lib/ngx-gallery.component.html +53 -0
- package/projects/gallery/src/lib/ngx-gallery.component.scss +78 -0
- package/projects/gallery/src/lib/ngx-gallery.component.spec.ts +37 -0
- package/projects/gallery/src/lib/ngx-gallery.component.ts +337 -0
- package/projects/gallery/src/lib/ngx-gallery.module.ts +29 -0
- package/projects/gallery/src/lib/ngx-gallery.service.spec.ts +18 -0
- package/projects/gallery/src/lib/ngx-gallery.service.ts +71 -0
- package/projects/gallery/src/public-api.ts +20 -0
- package/projects/gallery/src/test.ts +17 -0
- package/projects/gallery/tsconfig.lib.json +14 -0
- package/projects/gallery/tsconfig.lib.prod.json +9 -0
- package/projects/gallery/tsconfig.spec.json +16 -0
- package/projects/gallery-app/.browserslistrc +12 -0
- package/projects/gallery-app/.eslintrc.json +40 -0
- package/projects/gallery-app/e2e/protractor.conf.js +32 -0
- package/projects/gallery-app/e2e/src/app.e2e-spec.ts +23 -0
- package/projects/gallery-app/e2e/src/app.po.ts +11 -0
- package/projects/gallery-app/e2e/tsconfig.json +13 -0
- package/projects/gallery-app/karma.conf.js +32 -0
- package/projects/gallery-app/src/app/app-routing.module.ts +11 -0
- package/projects/gallery-app/src/app/app.component.html +4 -0
- package/projects/gallery-app/src/app/app.component.scss +9 -0
- package/projects/gallery-app/src/app/app.component.spec.ts +35 -0
- package/projects/gallery-app/src/app/app.component.ts +76 -0
- package/projects/gallery-app/src/app/app.module.ts +21 -0
- package/projects/gallery-app/src/assets/.gitkeep +0 -0
- package/projects/gallery-app/src/assets/img/gallery/1-big.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/1-medium.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/1-small.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/2-big.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/2-medium.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/2-small.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/3-big.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/3-medium.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/3-small.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/4-big.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/4-medium.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/4-small.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/5-big.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/5-medium.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/5-small.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/6-big.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/6-medium.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/6-small.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/7-big.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/7-medium.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/7-small.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/8-big.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/8-medium.jpeg +0 -0
- package/projects/gallery-app/src/assets/img/gallery/8-small.jpeg +0 -0
- package/projects/gallery-app/src/environments/environment.prod.ts +3 -0
- package/projects/gallery-app/src/environments/environment.ts +16 -0
- package/projects/gallery-app/src/favicon.ico +0 -0
- package/projects/gallery-app/src/index.html +13 -0
- package/projects/gallery-app/src/main.ts +12 -0
- package/projects/gallery-app/src/polyfills.ts +53 -0
- package/projects/gallery-app/src/styles.scss +1 -0
- package/projects/gallery-app/src/test.ts +16 -0
- package/projects/gallery-app/tsconfig.app.json +17 -0
- package/projects/gallery-app/tsconfig.spec.json +18 -0
- package/tsconfig.json +43 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AfterViewInit,
|
|
3
|
+
ChangeDetectionStrategy,
|
|
4
|
+
Component,
|
|
5
|
+
DoCheck,
|
|
6
|
+
ElementRef,
|
|
7
|
+
EventEmitter,
|
|
8
|
+
HostBinding,
|
|
9
|
+
HostListener,
|
|
10
|
+
Input,
|
|
11
|
+
OnInit,
|
|
12
|
+
Output,
|
|
13
|
+
ViewChild,
|
|
14
|
+
ViewEncapsulation
|
|
15
|
+
} from '@angular/core';
|
|
16
|
+
import {NgxGalleryPreviewComponent} from './ngx-gallery-preview/ngx-gallery-preview.component';
|
|
17
|
+
import {NgxGalleryImageComponent} from './ngx-gallery-image/ngx-gallery-image.component';
|
|
18
|
+
import {NgxGalleryThumbnailsComponent} from './ngx-gallery-thumbnails/ngx-gallery-thumbnails.component';
|
|
19
|
+
import {SafeResourceUrl} from '@angular/platform-browser';
|
|
20
|
+
import {NgxGalleryService} from './ngx-gallery.service';
|
|
21
|
+
import {NgxGalleryOptions} from './ngx-gallery-options';
|
|
22
|
+
import {NgxGalleryImage} from './ngx-gallery-image';
|
|
23
|
+
import {NgxGalleryOrderedImage} from './ngx-gallery-ordered-image';
|
|
24
|
+
import {NgxGalleryLayout} from './ngx-gallery-layout';
|
|
25
|
+
|
|
26
|
+
@Component({
|
|
27
|
+
selector: 'ngx-gallery',
|
|
28
|
+
templateUrl: './ngx-gallery.component.html',
|
|
29
|
+
styleUrls: ['./ngx-gallery.component.scss'],
|
|
30
|
+
encapsulation: ViewEncapsulation.None,
|
|
31
|
+
providers: [NgxGalleryService],
|
|
32
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
33
|
+
standalone: false
|
|
34
|
+
})
|
|
35
|
+
export class NgxGalleryComponent implements OnInit, DoCheck, AfterViewInit {
|
|
36
|
+
@Input() options: NgxGalleryOptions[] = [{}];
|
|
37
|
+
@Input() images: NgxGalleryImage[];
|
|
38
|
+
|
|
39
|
+
@Output() imagesReady = new EventEmitter();
|
|
40
|
+
// eslint-disable-next-line @angular-eslint/no-output-native
|
|
41
|
+
@Output() change = new EventEmitter<{ index: number; image: NgxGalleryImage; }>();
|
|
42
|
+
@Output() previewOpen = new EventEmitter();
|
|
43
|
+
@Output() previewClose = new EventEmitter();
|
|
44
|
+
@Output() previewChange = new EventEmitter<{ index: number; image: NgxGalleryImage; }>();
|
|
45
|
+
|
|
46
|
+
smallImages: string[] | SafeResourceUrl[];
|
|
47
|
+
mediumImages: NgxGalleryOrderedImage[];
|
|
48
|
+
bigImages: string[] | SafeResourceUrl[];
|
|
49
|
+
descriptions: string[];
|
|
50
|
+
links: string[];
|
|
51
|
+
labels: string[];
|
|
52
|
+
|
|
53
|
+
oldImages: NgxGalleryImage[];
|
|
54
|
+
oldImagesLength = 0;
|
|
55
|
+
|
|
56
|
+
selectedIndex = 0;
|
|
57
|
+
isAnimating: boolean;
|
|
58
|
+
previewEnabled: boolean;
|
|
59
|
+
|
|
60
|
+
currentOptions: NgxGalleryOptions;
|
|
61
|
+
|
|
62
|
+
private breakpoint: number | undefined = undefined;
|
|
63
|
+
private prevBreakpoint: number | undefined = undefined;
|
|
64
|
+
private fullWidthTimeout: any;
|
|
65
|
+
|
|
66
|
+
@ViewChild(NgxGalleryPreviewComponent) preview: NgxGalleryPreviewComponent;
|
|
67
|
+
@ViewChild(NgxGalleryImageComponent) image: NgxGalleryImageComponent;
|
|
68
|
+
@ViewChild(NgxGalleryThumbnailsComponent) thumbnails: NgxGalleryThumbnailsComponent;
|
|
69
|
+
|
|
70
|
+
@HostBinding('style.width') width: string;
|
|
71
|
+
@HostBinding('style.height') height: string;
|
|
72
|
+
@HostBinding('style.transform') left: string;
|
|
73
|
+
|
|
74
|
+
constructor(private myElement: ElementRef, private helperService: NgxGalleryService) {
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
ngOnInit() {
|
|
78
|
+
this.options = this.options.map((opt) => new NgxGalleryOptions(opt));
|
|
79
|
+
this.sortOptions();
|
|
80
|
+
this.setBreakpoint();
|
|
81
|
+
this.setOptions();
|
|
82
|
+
this.checkFullWidth();
|
|
83
|
+
if (this.currentOptions) {
|
|
84
|
+
this.selectedIndex = this.currentOptions.startIndex as number;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
ngDoCheck(): void {
|
|
89
|
+
if (this.images !== undefined && (this.images.length !== this.oldImagesLength)
|
|
90
|
+
|| (this.images !== this.oldImages)) {
|
|
91
|
+
this.oldImagesLength = this.images.length;
|
|
92
|
+
this.oldImages = this.images;
|
|
93
|
+
this.setOptions();
|
|
94
|
+
this.setImages();
|
|
95
|
+
|
|
96
|
+
if (this.images && this.images.length) {
|
|
97
|
+
this.imagesReady.emit();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (this.image) {
|
|
101
|
+
this.image.reset(this.currentOptions.startIndex as number);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (this.currentOptions.thumbnailsAutoHide && this.currentOptions.thumbnails
|
|
105
|
+
&& this.images.length <= 1) {
|
|
106
|
+
this.currentOptions.thumbnails = false;
|
|
107
|
+
this.currentOptions.imageArrows = false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this.resetThumbnails();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
ngAfterViewInit(): void {
|
|
115
|
+
this.checkFullWidth();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@HostListener('window:resize') onResize() {
|
|
119
|
+
this.setBreakpoint();
|
|
120
|
+
|
|
121
|
+
if (this.prevBreakpoint !== this.breakpoint) {
|
|
122
|
+
this.setOptions();
|
|
123
|
+
this.resetThumbnails();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (this.currentOptions && this.currentOptions.fullWidth) {
|
|
127
|
+
|
|
128
|
+
if (this.fullWidthTimeout) {
|
|
129
|
+
clearTimeout(this.fullWidthTimeout);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this.fullWidthTimeout = setTimeout(() => {
|
|
133
|
+
this.checkFullWidth();
|
|
134
|
+
}, 200);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
getImageHeight(): string {
|
|
139
|
+
return (this.currentOptions && this.currentOptions.thumbnails) ?
|
|
140
|
+
this.currentOptions.imagePercent + '%' : '100%';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getThumbnailsHeight(): string {
|
|
144
|
+
if (this.currentOptions && this.currentOptions.image) {
|
|
145
|
+
return 'calc(' + this.currentOptions.thumbnailsPercent + '% - '
|
|
146
|
+
+ this.currentOptions.thumbnailsMargin + 'px)';
|
|
147
|
+
} else {
|
|
148
|
+
return '100%';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
getThumbnailsMarginTop(): string {
|
|
153
|
+
if (this.currentOptions && this.currentOptions.layout === NgxGalleryLayout.ThumbnailsBottom) {
|
|
154
|
+
return this.currentOptions.thumbnailsMargin + 'px';
|
|
155
|
+
} else {
|
|
156
|
+
return '0px';
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
getThumbnailsMarginBottom(): string {
|
|
161
|
+
if (this.currentOptions && this.currentOptions.layout === NgxGalleryLayout.ThumbnailsTop) {
|
|
162
|
+
return this.currentOptions.thumbnailsMargin + 'px';
|
|
163
|
+
} else {
|
|
164
|
+
return '0px';
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
openPreview(index: number): void {
|
|
169
|
+
if (this.currentOptions.previewCustom) {
|
|
170
|
+
this.currentOptions.previewCustom(index);
|
|
171
|
+
} else {
|
|
172
|
+
this.previewEnabled = true;
|
|
173
|
+
this.preview.open(index);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
onPreviewOpen(): void {
|
|
178
|
+
this.previewOpen.emit();
|
|
179
|
+
|
|
180
|
+
if (this.image && this.image.autoPlay) {
|
|
181
|
+
this.image.stopAutoPlay();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
onPreviewClose(): void {
|
|
186
|
+
this.previewEnabled = false;
|
|
187
|
+
this.previewClose.emit();
|
|
188
|
+
|
|
189
|
+
if (this.image && this.image.autoPlay) {
|
|
190
|
+
this.image.startAutoPlay();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
selectFromImage(index: number) {
|
|
195
|
+
this.select(index);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
selectFromThumbnails(index: number) {
|
|
199
|
+
this.select(index);
|
|
200
|
+
|
|
201
|
+
if (this.currentOptions && this.currentOptions.thumbnails && this.currentOptions.preview
|
|
202
|
+
&& (!this.currentOptions.image || this.currentOptions.thumbnailsRemainingCount)) {
|
|
203
|
+
this.openPreview(this.selectedIndex);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
show(index: number): void {
|
|
208
|
+
this.select(index);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
showNext(): void {
|
|
212
|
+
this.image.showNext();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
showPrev(): void {
|
|
216
|
+
this.image.showPrev();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
canShowNext(): boolean {
|
|
220
|
+
if (this.images && this.currentOptions) {
|
|
221
|
+
return !!(this.currentOptions.imageInfinityMove || this.selectedIndex < this.images.length - 1);
|
|
222
|
+
} else {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
canShowPrev(): boolean {
|
|
228
|
+
if (this.images && this.currentOptions) {
|
|
229
|
+
return !!(this.currentOptions.imageInfinityMove || this.selectedIndex > 0);
|
|
230
|
+
} else {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
previewSelect(index: number) {
|
|
236
|
+
this.previewChange.emit({index, image: this.images[index]});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
moveThumbnailsRight() {
|
|
240
|
+
this.thumbnails.moveRight();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
moveThumbnailsLeft() {
|
|
244
|
+
this.thumbnails.moveLeft();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
canMoveThumbnailsRight() {
|
|
248
|
+
return this.thumbnails.canMoveRight();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
canMoveThumbnailsLeft() {
|
|
252
|
+
return this.thumbnails.canMoveLeft();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private resetThumbnails() {
|
|
256
|
+
if (this.thumbnails) {
|
|
257
|
+
this.thumbnails.reset(this.currentOptions.startIndex as number);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private select(index: number) {
|
|
262
|
+
this.selectedIndex = index;
|
|
263
|
+
|
|
264
|
+
this.change.emit({
|
|
265
|
+
index,
|
|
266
|
+
image: this.images[index]
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private checkFullWidth(): void {
|
|
271
|
+
if (this.currentOptions && this.currentOptions.fullWidth) {
|
|
272
|
+
this.width = document.body.clientWidth + 'px';
|
|
273
|
+
this.left = 'translateX(' + (-(document.body.clientWidth -
|
|
274
|
+
this.myElement.nativeElement.parentNode.innerWidth) / 2) + 'px)';
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
private setImages(): void {
|
|
279
|
+
this.images.forEach((img) =>
|
|
280
|
+
img.type = this.helperService.getFileType(img.url as string || img.big as string || img.medium as string || img.small as string || '')
|
|
281
|
+
);
|
|
282
|
+
this.smallImages = this.images.map((img) => img.small as string);
|
|
283
|
+
this.mediumImages = this.images.map((img, i) => new NgxGalleryOrderedImage({
|
|
284
|
+
src: img.medium,
|
|
285
|
+
type: img.type,
|
|
286
|
+
index: i
|
|
287
|
+
}));
|
|
288
|
+
this.bigImages = this.images.map((img) => img.big as string);
|
|
289
|
+
this.descriptions = this.images.map((img) => img.description as string);
|
|
290
|
+
this.links = this.images.map((img) => img.url as string);
|
|
291
|
+
this.labels = this.images.map((img) => img.label as string);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
private setBreakpoint(): void {
|
|
295
|
+
this.prevBreakpoint = this.breakpoint;
|
|
296
|
+
let breakpoints;
|
|
297
|
+
|
|
298
|
+
if (typeof window !== 'undefined') {
|
|
299
|
+
breakpoints = this.options.filter((opt) => opt.breakpoint >= window.innerWidth)
|
|
300
|
+
.map((opt) => opt.breakpoint);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (breakpoints && breakpoints.length) {
|
|
304
|
+
this.breakpoint = breakpoints.pop();
|
|
305
|
+
} else {
|
|
306
|
+
this.breakpoint = undefined;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
private sortOptions(): void {
|
|
311
|
+
this.options = [
|
|
312
|
+
...this.options.filter((a) => a.breakpoint === undefined),
|
|
313
|
+
...this.options
|
|
314
|
+
.filter((a) => a.breakpoint !== undefined)
|
|
315
|
+
.sort((a, b) => b.breakpoint - a.breakpoint)
|
|
316
|
+
];
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private setOptions(): void {
|
|
320
|
+
this.currentOptions = new NgxGalleryOptions({});
|
|
321
|
+
|
|
322
|
+
this.options
|
|
323
|
+
.filter((opt) => opt.breakpoint === undefined || opt.breakpoint >= this.breakpoint)
|
|
324
|
+
.map((opt) => this.combineOptions(this.currentOptions, opt));
|
|
325
|
+
|
|
326
|
+
this.width = this.currentOptions.width as string;
|
|
327
|
+
this.height = this.currentOptions.height as string;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private combineOptions(first: NgxGalleryOptions, second: NgxGalleryOptions) {
|
|
331
|
+
Object.keys(second).map((val) => first[val] = second[val] !== undefined ? second[val] : first[val]);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
setAnimating(event: boolean) {
|
|
335
|
+
this.isAnimating = event;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NgModule, Injectable } from '@angular/core';
|
|
2
|
+
import { NgxGalleryComponent } from './ngx-gallery.component';
|
|
3
|
+
import { NgxGalleryImageComponent } from './ngx-gallery-image/ngx-gallery-image.component';
|
|
4
|
+
import { NgxGalleryArrowsComponent } from './ngx-gallery-arrows/ngx-gallery-arrows.component';
|
|
5
|
+
import { NgxGalleryThumbnailsComponent } from './ngx-gallery-thumbnails/ngx-gallery-thumbnails.component';
|
|
6
|
+
import { NgxGalleryPreviewComponent } from './ngx-gallery-preview/ngx-gallery-preview.component';
|
|
7
|
+
import { NgxGalleryActionComponent } from './ngx-gallery-action/ngx-gallery-action.component';
|
|
8
|
+
import { NgxGalleryBulletsComponent } from './ngx-gallery-bullets/ngx-gallery-bullets.component';
|
|
9
|
+
import { CommonModule } from '@angular/common';
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
@NgModule({
|
|
13
|
+
declarations: [
|
|
14
|
+
NgxGalleryComponent,
|
|
15
|
+
NgxGalleryImageComponent,
|
|
16
|
+
NgxGalleryArrowsComponent,
|
|
17
|
+
NgxGalleryThumbnailsComponent,
|
|
18
|
+
NgxGalleryPreviewComponent,
|
|
19
|
+
NgxGalleryActionComponent,
|
|
20
|
+
NgxGalleryBulletsComponent
|
|
21
|
+
],
|
|
22
|
+
imports: [CommonModule],
|
|
23
|
+
exports: [NgxGalleryComponent],
|
|
24
|
+
providers: [
|
|
25
|
+
|
|
26
|
+
]
|
|
27
|
+
})
|
|
28
|
+
export class NgxGalleryModule {
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {inject, TestBed} from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { NgxGalleryService } from './ngx-gallery.service';
|
|
4
|
+
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
|
|
5
|
+
import {Renderer2} from '@angular/core';
|
|
6
|
+
|
|
7
|
+
describe('NgxGalleryService', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
TestBed.configureTestingModule({
|
|
10
|
+
imports: [],
|
|
11
|
+
providers: [NgxGalleryService, Renderer2, provideHttpClient(withInterceptorsFromDi())]
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should be created', inject([NgxGalleryService], (service: NgxGalleryService) => {
|
|
16
|
+
expect(service).toBeTruthy();
|
|
17
|
+
}));
|
|
18
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ElementRef, Injectable, Renderer2 } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
@Injectable({ providedIn: 'root' })
|
|
4
|
+
export class NgxGalleryService {
|
|
5
|
+
private swipeHandlers: Map<string, (() => void)[]> = new Map();
|
|
6
|
+
private pointerData: Map<string, { x: number }> = new Map();
|
|
7
|
+
|
|
8
|
+
constructor(private renderer: Renderer2) {}
|
|
9
|
+
|
|
10
|
+
manageSwipe(
|
|
11
|
+
status: boolean,
|
|
12
|
+
element: ElementRef,
|
|
13
|
+
id: string,
|
|
14
|
+
nextHandler: () => void,
|
|
15
|
+
prevHandler: () => void
|
|
16
|
+
): void {
|
|
17
|
+
const handlers = this.swipeHandlers.get(id);
|
|
18
|
+
|
|
19
|
+
if (status && !handlers) {
|
|
20
|
+
const el = element.nativeElement;
|
|
21
|
+
|
|
22
|
+
const pointerDown = this.renderer.listen(el, 'pointerdown', (event: PointerEvent) => {
|
|
23
|
+
this.pointerData.set(id, { x: event.clientX });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const pointerUp = this.renderer.listen(el, 'pointerup', (event: PointerEvent) => {
|
|
27
|
+
const start = this.pointerData.get(id);
|
|
28
|
+
const endX = event.clientX;
|
|
29
|
+
|
|
30
|
+
if (!start) return;
|
|
31
|
+
|
|
32
|
+
const deltaX = endX - start.x;
|
|
33
|
+
const threshold = 40;
|
|
34
|
+
|
|
35
|
+
if (deltaX > threshold) {
|
|
36
|
+
prevHandler();
|
|
37
|
+
} else if (deltaX < -threshold) {
|
|
38
|
+
nextHandler();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.pointerData.delete(id);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const pointerCancel = this.renderer.listen(el, 'pointercancel', () => {
|
|
45
|
+
this.pointerData.delete(id);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const pointerLeave = this.renderer.listen(el, 'pointerleave', () => {
|
|
49
|
+
this.pointerData.delete(id);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
this.swipeHandlers.set(id, [pointerDown, pointerUp, pointerCancel, pointerLeave]);
|
|
53
|
+
} else if (!status && handlers) {
|
|
54
|
+
handlers.forEach(unlisten => unlisten());
|
|
55
|
+
this.swipeHandlers.delete(id);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
validateUrl(url: string): string {
|
|
60
|
+
return url?.replace(/ /g, '%20').replace(/'/g, '%27') ?? url;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getBackgroundUrl(image: string): string {
|
|
64
|
+
return `url('${this.validateUrl(image)}')`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getFileType(fileSource: string): string {
|
|
68
|
+
const ext = fileSource.split('.').pop()?.toLowerCase();
|
|
69
|
+
return ['avi', 'flv', 'wmv', 'mov', 'mp4'].includes(ext ?? '') ? 'video' : 'image';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Public API Surface of ngx-gallery
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from './lib/ngx-gallery.service';
|
|
6
|
+
export * from './lib/ngx-gallery.component';
|
|
7
|
+
export * from './lib/ngx-gallery.module';
|
|
8
|
+
export * from './lib/ngx-gallery-action';
|
|
9
|
+
export * from './lib/ngx-gallery-image';
|
|
10
|
+
export * from './lib/ngx-gallery-thumbnails/ngx-gallery-thumbnails.component';
|
|
11
|
+
export * from './lib/ngx-gallery-preview/ngx-gallery-preview.component';
|
|
12
|
+
export * from './lib/ngx-gallery-arrows/ngx-gallery-arrows.component';
|
|
13
|
+
export * from './lib/ngx-gallery-bullets/ngx-gallery-bullets.component';
|
|
14
|
+
export * from './lib/ngx-gallery-options';
|
|
15
|
+
export * from './lib/ngx-gallery-image';
|
|
16
|
+
export * from './lib/ngx-gallery-animation';
|
|
17
|
+
export * from './lib/ngx-gallery-image-size';
|
|
18
|
+
export * from './lib/ngx-gallery-layout';
|
|
19
|
+
export * from './lib/ngx-gallery-order';
|
|
20
|
+
export * from './lib/ngx-gallery-ordered-image';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
+
|
|
3
|
+
import 'zone.js';
|
|
4
|
+
import 'zone.js/testing';
|
|
5
|
+
import { getTestBed } from '@angular/core/testing';
|
|
6
|
+
import {
|
|
7
|
+
BrowserDynamicTestingModule,
|
|
8
|
+
platformBrowserDynamicTesting
|
|
9
|
+
} from '@angular/platform-browser-dynamic/testing';
|
|
10
|
+
|
|
11
|
+
// First, initialize the Angular testing environment.
|
|
12
|
+
getTestBed().initTestEnvironment(
|
|
13
|
+
BrowserDynamicTestingModule,
|
|
14
|
+
platformBrowserDynamicTesting(), {
|
|
15
|
+
teardown: { destroyAfterEach: false }
|
|
16
|
+
}
|
|
17
|
+
);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
|
|
2
|
+
# For additional information regarding the format and rule options, please see:
|
|
3
|
+
# https://github.com/browserslist/browserslist#queries
|
|
4
|
+
|
|
5
|
+
# You can see what browsers were selected by your queries by running:
|
|
6
|
+
# npx browserslist
|
|
7
|
+
|
|
8
|
+
> 0.5%
|
|
9
|
+
last 2 versions
|
|
10
|
+
Firefox ESR
|
|
11
|
+
not dead
|
|
12
|
+
not IE 9-11 # For IE 9-11 support, remove 'not'.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../.eslintrc.json",
|
|
3
|
+
"ignorePatterns": [
|
|
4
|
+
"!**/*"
|
|
5
|
+
],
|
|
6
|
+
"overrides": [
|
|
7
|
+
{
|
|
8
|
+
"files": [
|
|
9
|
+
"*.ts"
|
|
10
|
+
],
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"project": [
|
|
13
|
+
"projects/gallery-app/tsconfig.app.json",
|
|
14
|
+
"projects/gallery-app/tsconfig.spec.json",
|
|
15
|
+
"projects/gallery-app/e2e/tsconfig.json"
|
|
16
|
+
],
|
|
17
|
+
"createDefaultProgram": true
|
|
18
|
+
},
|
|
19
|
+
"rules": {
|
|
20
|
+
"@typescript-eslint/explicit-member-accessibility": [
|
|
21
|
+
"off",
|
|
22
|
+
{
|
|
23
|
+
"accessibility": "explicit"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"arrow-parens": [
|
|
27
|
+
"off",
|
|
28
|
+
"always"
|
|
29
|
+
],
|
|
30
|
+
"import/order": "off"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"files": [
|
|
35
|
+
"*.html"
|
|
36
|
+
],
|
|
37
|
+
"rules": {}
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Protractor configuration file, see link for more information
|
|
3
|
+
// https://github.com/angular/protractor/blob/master/lib/config.ts
|
|
4
|
+
|
|
5
|
+
const { SpecReporter } = require('jasmine-spec-reporter');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type { import("protractor").Config }
|
|
9
|
+
*/
|
|
10
|
+
exports.config = {
|
|
11
|
+
allScriptsTimeout: 11000,
|
|
12
|
+
specs: [
|
|
13
|
+
'./src/**/*.e2e-spec.ts'
|
|
14
|
+
],
|
|
15
|
+
capabilities: {
|
|
16
|
+
browserName: 'chrome'
|
|
17
|
+
},
|
|
18
|
+
directConnect: true,
|
|
19
|
+
baseUrl: 'http://localhost:4200/',
|
|
20
|
+
framework: 'jasmine',
|
|
21
|
+
jasmineNodeOpts: {
|
|
22
|
+
showColors: true,
|
|
23
|
+
defaultTimeoutInterval: 30000,
|
|
24
|
+
print: function() {}
|
|
25
|
+
},
|
|
26
|
+
onPrepare() {
|
|
27
|
+
require('ts-node').register({
|
|
28
|
+
project: require('path').join(__dirname, './tsconfig.json')
|
|
29
|
+
});
|
|
30
|
+
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AppPage } from './app.po';
|
|
2
|
+
import { browser, logging } from 'protractor';
|
|
3
|
+
|
|
4
|
+
describe('workspace-project App', () => {
|
|
5
|
+
let page: AppPage;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
page = new AppPage();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should display welcome message', () => {
|
|
12
|
+
page.navigateTo();
|
|
13
|
+
expect(page.getTitleText()).toEqual('gallery-app app is running!');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(async () => {
|
|
17
|
+
// Assert that there are no errors emitted from the browser
|
|
18
|
+
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
|
|
19
|
+
expect(logs).not.toContain(jasmine.objectContaining({
|
|
20
|
+
level: logging.Level.SEVERE,
|
|
21
|
+
} as logging.Entry));
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { browser, by, element } from 'protractor';
|
|
2
|
+
|
|
3
|
+
export class AppPage {
|
|
4
|
+
navigateTo() {
|
|
5
|
+
return browser.get(browser.baseUrl) as Promise<any>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
getTitleText() {
|
|
9
|
+
return element(by.css('app-root .content span')).getText() as Promise<string>;
|
|
10
|
+
}
|
|
11
|
+
}
|