@tomasvn/glightbox 0.0.0-stage → 3.3.4

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.
Files changed (46) hide show
  1. package/.editorconfig +16 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.json +94 -0
  4. package/.github/FUNDING.yml +3 -0
  5. package/.github/ISSUE_TEMPLATE/bug_report.md +41 -0
  6. package/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
  7. package/.github/stale.yml +21 -0
  8. package/.github/workflows/greetings.yml +13 -0
  9. package/.husky/pre-commit +3 -0
  10. package/.lando.yml +10 -0
  11. package/.prettierignore +3 -0
  12. package/.prettierrc.json +30 -0
  13. package/CHANGELOG.md +259 -0
  14. package/CONTRIBUTING.md +29 -0
  15. package/LICENSE.md +21 -0
  16. package/README.md +714 -2
  17. package/bower.json +29 -0
  18. package/development/build.js +44 -0
  19. package/development/jscompiler.js +90 -0
  20. package/development/notifications.js +15 -0
  21. package/development/package.js +116 -0
  22. package/development/postcss.js +63 -0
  23. package/development/watcher.js +105 -0
  24. package/dist/css/glightbox.css +939 -0
  25. package/dist/css/glightbox.min.css +1 -0
  26. package/dist/js/glightbox.js +3109 -0
  27. package/dist/js/glightbox.min.js +1 -0
  28. package/index.d.ts +586 -0
  29. package/package.json +60 -4
  30. package/src/js/.jshintrc +6 -0
  31. package/src/js/core/drag.js +203 -0
  32. package/src/js/core/keyboard-navigation.js +101 -0
  33. package/src/js/core/slide-parser.js +236 -0
  34. package/src/js/core/slide.js +251 -0
  35. package/src/js/core/touch-events.js +378 -0
  36. package/src/js/core/touch-navigation.js +291 -0
  37. package/src/js/core/zoom.js +156 -0
  38. package/src/js/glightbox.js +1351 -0
  39. package/src/js/slides/iframe.js +24 -0
  40. package/src/js/slides/image.js +56 -0
  41. package/src/js/slides/inline.js +71 -0
  42. package/src/js/slides/video.js +108 -0
  43. package/src/js/utils/helpers.js +541 -0
  44. package/src/postcss/glightbox.css +725 -0
  45. package/tests/slide.test.mjs +130 -0
  46. package/tests/touch-navigation.test.mjs +13 -0
package/index.d.ts ADDED
@@ -0,0 +1,586 @@
1
+ // Type definitions for Glightbox 3.2.2
2
+ // Project: https://github.com/biati-digital/glightbox/blob/master/README.md
3
+ // Definitions by: Ngoc Tu Nguyen <https://github.com/tomasvn>
4
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
+
6
+ declare namespace Glightbox {
7
+ /**
8
+ * Youtube iframe api
9
+ * @see https://developers.google.com/youtube/player_parameters
10
+ */
11
+ interface YoutubeOptions {
12
+ /**
13
+ * Whether to use an alternative version of Youtube without cookies
14
+ */
15
+ noCookie?: boolean;
16
+ /**
17
+ * Show related videos
18
+ */
19
+ rel?: number;
20
+ /**
21
+ * Show video title
22
+ * @see https://google.com/youtube/player_parameters#release_notes_08_23_2018
23
+ *
24
+ * @deprecated
25
+ */
26
+ showinfo?: number;
27
+ /**
28
+ * Show or hide annotations
29
+ */
30
+ iv_load_policy?: number;
31
+ }
32
+
33
+ /**
34
+ * Vimeo embed video api
35
+ *
36
+ * @see https://help.vimeo.com/hc/en-us/articles/360001494447-Using-Player-Parameters
37
+ */
38
+ interface VimeoOptions {
39
+ /**
40
+ * Show the byline on the video.
41
+ */
42
+ byline?: boolean;
43
+ /**
44
+ * Show the author’s profile image (portrait)
45
+ */
46
+ portrait?: boolean;
47
+ /**
48
+ * Show the video’s title.
49
+ */
50
+ title?: boolean;
51
+ /**
52
+ * Enable or disable the background of the player
53
+ */
54
+ transparent?: boolean;
55
+ }
56
+
57
+ interface Config {
58
+ /**
59
+ * Set aspect ratio
60
+ */
61
+ ratio?: string;
62
+ /**
63
+ * Toggles whether fullscreen should be enabled or
64
+ * whether to use native iOS fullscreen when entering
65
+ * fullscreen
66
+ */
67
+ fullscreen?: Record<'enabled' | 'iosNative', boolean>;
68
+ youtube?: YoutubeOptions;
69
+ vimeo?: VimeoOptions;
70
+ }
71
+
72
+ interface PlyrOptions {
73
+ /**
74
+ * Get Plyr.js css files from cdn
75
+ */
76
+ css?: string;
77
+ /**
78
+ * Get Plyr.js js files from cdn
79
+ */
80
+ js?: string;
81
+ config?: Config;
82
+ }
83
+
84
+ interface Options {
85
+ /**
86
+ * Name of the selector for example '.glightbox' or 'data-glightbox'
87
+ * or '*[data-glightbox]'
88
+ *
89
+ * @default '.glightbox'
90
+ */
91
+ selector?: string;
92
+ /**
93
+ * Instead of passing a selector you can pass all the items
94
+ * that you want in the gallery.
95
+ *
96
+ * @default null
97
+ */
98
+ elements?: ({ href: string; type: 'image'; title?: string; description?: string; alt?: string } | { href: string; type: 'video'; source: string; width?: number } | { content: string | HTMLElement })[] | null;
99
+ /**
100
+ * Name of the skin, it will add a class to the lightbox
101
+ * so you can style it with css.
102
+ *
103
+ * @default 'clean'
104
+ */
105
+ skin?: string;
106
+ /**
107
+ * Name of the effect on lightbox open. (zoom, fade, none)
108
+ *
109
+ * @default 'zoom'
110
+ */
111
+ openEffect?: string;
112
+ /**
113
+ * Name of the effect on lightbox close. (zoom, fade, none)
114
+ *
115
+ * @default 'zoom'
116
+ */
117
+ closeEffect?: string;
118
+ /**
119
+ * Name of the effect on slide change. (slide, fade, zoom, none)
120
+ *
121
+ * @default 'slide'
122
+ */
123
+ slideEffect?: string;
124
+ /**
125
+ * More text for descriptions on mobile devices.
126
+ *
127
+ * @default 'See more'
128
+ */
129
+ moreText?: string;
130
+ /**
131
+ * Text for collapsing expanded descriptions.
132
+ *
133
+ * @default 'See less'
134
+ */
135
+ lessText?: string;
136
+ /**
137
+ * Number of characters to display on the description before adding
138
+ * the moreText link (only for mobiles),
139
+ * if 0 it will display the entire description.
140
+ *
141
+ * @default 60
142
+ */
143
+ moreLength?: number;
144
+ /**
145
+ * Show or hide the close button.
146
+ *
147
+ * @default true
148
+ */
149
+ closeButton?: boolean;
150
+ /**
151
+ * Text for the close button.
152
+ *
153
+ * @default 'Close'
154
+ */
155
+ closeButtonText?: string;
156
+ /**
157
+ * Text for the next slide button.
158
+ *
159
+ * @default 'Next'
160
+ */
161
+ nextButtonText?: string;
162
+ /**
163
+ * Text for the previous slide button.
164
+ *
165
+ * @default 'Previous'
166
+ */
167
+ prevButtonText?: string;
168
+ /**
169
+ * Enable or disable the touch navigation (swipe).
170
+ *
171
+ * @default true
172
+ */
173
+ touchNavigation?: boolean;
174
+ /**
175
+ * Image follow axis when dragging on mobile.
176
+ *
177
+ * @default true
178
+ */
179
+ touchFollowAxis?: boolean;
180
+ /**
181
+ * Enable or disable the keyboard navigation.
182
+ *
183
+ * @default true
184
+ */
185
+ keyboardNavigation?: boolean;
186
+ /**
187
+ * Close the lightbox when clicking outside the active slide.
188
+ *
189
+ * @default true
190
+ */
191
+ closeOnOutsideClick?: boolean;
192
+ /**
193
+ * Start lightbox at defined index.
194
+ *
195
+ * @default 0
196
+ */
197
+ startAt?: number;
198
+ /**
199
+ * Default width for inline elements and iframes
200
+ *
201
+ * @default '900px'
202
+ */
203
+ width?: string;
204
+ /**
205
+ * Default height for inline elements and iframes
206
+ *
207
+ * @default '506px'
208
+ */
209
+ height?: string;
210
+ /**
211
+ * Default width for videos.
212
+ *
213
+ * @default '560px'
214
+ */
215
+ videosWidth?: string;
216
+ /**
217
+ * Global position for slides description
218
+ *
219
+ * @default 'bottom'
220
+ */
221
+ descPosition?: string;
222
+ /**
223
+ * Loop slides on end.
224
+ *
225
+ * @default false
226
+ */
227
+ loop?: Exclude<boolean, undefined>;
228
+ /**
229
+ * Enable or disable zoomable images
230
+ *
231
+ * @default true
232
+ */
233
+ zoomable?: boolean;
234
+ /**
235
+ * Enable or disable mouse drag to go prev and next slide
236
+ *
237
+ * @default true
238
+ */
239
+ draggable?: boolean;
240
+ /**
241
+ * Used with draggable. Number of pixels the user
242
+ * has to drag to go to prev or next slide.
243
+ *
244
+ * @default 40
245
+ */
246
+ dragToleranceX?: number;
247
+ /**
248
+ * Used with draggable. Number of pixels the user has to drag
249
+ * up or down to close the lightbox
250
+ *
251
+ * @default 65
252
+ */
253
+ dragToleranceY?: number;
254
+ /**
255
+ * If true the slide will automatically change to prev/next or close
256
+ * if dragToleranceX or dragToleranceY is reached,
257
+ * otherwise it will wait till the mouse is released.
258
+ *
259
+ * @default false
260
+ */
261
+ dragAutoSnap?: boolean;
262
+ /**
263
+ * Enable or disable preloading.
264
+ *
265
+ * @default true
266
+ */
267
+ preload?: boolean;
268
+ /**
269
+ * Set your own svg icons.
270
+ */
271
+ svg?: Record<'close' | 'next' | 'prev', string>;
272
+ /**
273
+ * Define or adjust lightbox animations.
274
+ *
275
+ * @see:
276
+ */
277
+ cssEffects?: Record<string, Record<'in' | 'out', string>>;
278
+ /**
279
+ * You can completely change the html of GLightbox.
280
+ */
281
+ lightboxHTML?: string;
282
+ /**
283
+ * You can completely change the html of the individual slide.
284
+ */
285
+ slideHTML?: string;
286
+ /**
287
+ * Autoplay videos on open.
288
+ *
289
+ * @default true
290
+ */
291
+ autoplayVideos?: boolean;
292
+ /**
293
+ * If true video will be focused on play to allow
294
+ * keyboard sortcuts for the player, this will deactivate
295
+ * prev and next arrows to change slide.
296
+ *
297
+ */
298
+ autofocusVideos?: boolean;
299
+ plyr?: PlyrOptions;
300
+ }
301
+
302
+ type EventTypes = 'open' | 'close' | 'slide_before_change' | 'slide_changed' | 'slide_before_load' | 'slide_after_load' | 'slide_inserted' | 'slide_removed';
303
+
304
+ interface SlideConfig {
305
+ href?: string;
306
+ sizes?: string;
307
+ srcset?: string;
308
+ title?: string;
309
+ type?: 'image' | 'video' | 'inline';
310
+ videoProvider?: string;
311
+ description?: string;
312
+ alt?: string;
313
+ descPosition?: 'bottom' | 'top' | 'left' | 'right';
314
+ effect?: string;
315
+ width?: string;
316
+ height?: string;
317
+ content?: boolean;
318
+ zoomable?: boolean;
319
+ draggable?: boolean;
320
+ }
321
+
322
+ interface BaseData {
323
+ index?: number;
324
+ slide?: Element;
325
+ slideNode?: Element;
326
+ slideConfig?: SlideConfig;
327
+ slideIndex?: number;
328
+ trigger?: Element;
329
+ player?: null | Record<any, any>;
330
+ }
331
+
332
+ type Payload<T extends EventTypes> = {
333
+ open: undefined;
334
+ close: undefined;
335
+ slide_before_change: {
336
+ prev: BaseData;
337
+ current: BaseData;
338
+ };
339
+ slide_changed: {
340
+ prev: BaseData;
341
+ current: BaseData;
342
+ };
343
+ slide_before_load: BaseData;
344
+ slide_after_load: BaseData;
345
+ slide_inserted: BaseData;
346
+ slide_removed: number;
347
+ }[T];
348
+ }
349
+
350
+ declare class GlightboxInit {
351
+ constructor(options: Glightbox.Options);
352
+
353
+ /**
354
+ * Initialize lightbox
355
+ */
356
+ private init(): void;
357
+
358
+ /**
359
+ * Open lightbox
360
+ */
361
+ public open(element?: Element, startAt?: number): void;
362
+
363
+ /**
364
+ * Open at specific index
365
+ */
366
+ public openAt(index?: number): void;
367
+
368
+ /**
369
+ * Set Slide
370
+ */
371
+ private showSlide(index?: number, first?: boolean): void;
372
+
373
+ /**
374
+ * Preload slides
375
+ */
376
+ private preloadSlide(index: number): null;
377
+
378
+ /**
379
+ * Load previous slide
380
+ * calls goToslide
381
+ */
382
+ public prevSlide(): void;
383
+
384
+ /**
385
+ * Load next slide
386
+ * calls goToslide
387
+ */
388
+ public nextSlide(): void;
389
+
390
+ /**
391
+ * Go to slide
392
+ * calls set slide
393
+ */
394
+ public goToSlide(index?: number): void;
395
+
396
+ /**
397
+ * Insert slide
398
+ */
399
+ insertSlide(config?: Record<any, any>, index?: number): void;
400
+
401
+ /**
402
+ * Remove slide
403
+ */
404
+ public removeSlide(index?: number): boolean | undefined;
405
+
406
+ /**
407
+ * Slide In
408
+ */
409
+ private slideAnimateIn(slide: Element, first: boolean): null;
410
+
411
+ /**
412
+ * Slide out
413
+ */
414
+ private slideAnimateOut(): void;
415
+
416
+ /**
417
+ * Get all defined players
418
+ */
419
+ getAllPlayers(): Record<string, any>;
420
+
421
+ /**
422
+ * Get player at index
423
+ */
424
+ getSlidePlayerInstance(index: number): boolean | Record<any, any>;
425
+
426
+ /**
427
+ * Stop video at specified
428
+ * node or index
429
+ */
430
+ stopSlideVideo(slide: Element | number): void;
431
+
432
+ /**
433
+ * Stop player at specified index
434
+ */
435
+ slidePlayerPause(slide: Element | number): void;
436
+
437
+ /**
438
+ * Stop video at specified
439
+ * node or index
440
+ *
441
+ * @deprecated use slidePlayerPause instead
442
+ */
443
+ stopSlide(slide: Element | number): void;
444
+
445
+ /**
446
+ * Play video at specified
447
+ * node or index
448
+ */
449
+ playSlideVideo(slide: Element | number): void;
450
+
451
+ /**
452
+ * Play media player at specified
453
+ * node or index
454
+ */
455
+ slidePlayerPlay(slide: Element | number): void;
456
+
457
+ /**
458
+ * Set the entire elements
459
+ * in the gallery, it replaces all
460
+ * the existing elements
461
+ * with the specified list
462
+ */
463
+ setElements(elements: any[]): void;
464
+
465
+ /**
466
+ * Return the index
467
+ * of the specified node,
468
+ * this node is for example an image, link, etc.
469
+ * that when clicked it opens the lightbox
470
+ * its position in the elements array can change
471
+ * when using insertSlide or removeSlide so we
472
+ * need to find it in the elements list
473
+ */
474
+ private getElementIndex(node: Node): boolean | number;
475
+
476
+ /**
477
+ * Get elements
478
+ * returns an array containing all
479
+ * the elements that must be displayed in the
480
+ * lightbox
481
+ */
482
+ private getElements(): any[];
483
+
484
+ /**
485
+ * Return only the elements
486
+ * from a specific gallery
487
+ */
488
+ private getGalleryElements(list: any[], gallery: any[]): any[];
489
+
490
+ /**
491
+ * Get selector
492
+ */
493
+ private getSelector(): boolean | string;
494
+
495
+ /**
496
+ * Get the active slide
497
+ */
498
+ public getActiveSlide(): Element;
499
+
500
+ /**
501
+ * Get the active index
502
+ */
503
+ public getActiveSlideIndex(): number | undefined;
504
+
505
+ /**
506
+ * Get the defined
507
+ * effects as string
508
+ */
509
+ private getAnimationClasses(): string;
510
+
511
+ /**
512
+ * Build the structure
513
+ */
514
+ private build(): null;
515
+
516
+ /**
517
+ * Handle resize
518
+ * Create only to handle
519
+ * when the height of the screen
520
+ * is lower than the slide content
521
+ * this helps to resize videos vertically
522
+ * and images with description
523
+ */
524
+ private resize(slide?: null): void;
525
+
526
+ /**
527
+ * Reload Lightbox
528
+ * reload and apply events to nodes
529
+ */
530
+ public reload(): void;
531
+
532
+ /**
533
+ * Update navigation classes on slide change
534
+ */
535
+ private updateNavigationClasses(): void;
536
+
537
+ /**
538
+ * Handle loop config
539
+ */
540
+ private loop(): void;
541
+
542
+ /**
543
+ * Close Lightbox
544
+ * closes the lightbox and removes the slides
545
+ * and some classes
546
+ */
547
+ public close(): boolean | undefined;
548
+
549
+ /**
550
+ * Destroy lightbox
551
+ * and all events
552
+ */
553
+ public destroy(): void;
554
+
555
+ /**
556
+ * Set event
557
+ */
558
+ public on(eventName: Glightbox.EventTypes, callback: () => void, once?: boolean): void;
559
+
560
+ /**
561
+ * Set event once
562
+ */
563
+ public once(eventName: Glightbox.EventTypes, callback: () => void): void;
564
+
565
+ /**
566
+ * Triggers an specific event
567
+ * with data
568
+ */
569
+ public trigger<T extends Glightbox.EventTypes>(eventName: T, data?: Glightbox.Payload<T>): void;
570
+
571
+ /**
572
+ * Removes all events
573
+ * set using the API
574
+ */
575
+ private clearAllEvents(): void;
576
+
577
+ /**
578
+ * Get Version
579
+ */
580
+ version(): string;
581
+ }
582
+
583
+ declare function GLightbox(options: Glightbox.Options): InstanceType<typeof GlightboxInit>;
584
+
585
+ export = GLightbox;
586
+ export as namespace GLightbox;
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@tomasvn/glightbox",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "3.3.4",
4
+ "description": "Pure Javascript lightbox",
5
+ "main": "dist/js/glightbox.min.js",
6
+ "scripts": {
7
+ "build": "node development/build.js",
8
+ "test": "node --test",
9
+ "watch": "node development/watcher.js",
10
+ "lint": "eslint \"src/js/**/*.js\"",
11
+ "format": "prettier --write \"src/js/**/*.js\"",
12
+ "prepare": "husky"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "author": "Biati Digital",
18
+ "types": "./index.d.ts",
19
+ "keywords": [
20
+ "lightbox",
21
+ "javascript",
22
+ "gallery",
23
+ "popup"
24
+ ],
25
+ "license": "MIT",
26
+ "homepage": "https://biati-digital.github.io/glightbox/",
27
+ "repository": {
28
+ "url": "https://github.com/biati-digital/glightbox",
29
+ "type": "git"
30
+ },
31
+ "bugs": "https://github.com/biati-digital/glightbox/issues",
32
+ "devDependencies": {
33
+ "@babel/cli": "^7.10.3",
34
+ "@babel/core": "^7.10.3",
35
+ "@babel/node": "^7.10.3",
36
+ "@babel/preset-env": "^7.10.3",
37
+ "@babel/register": "^7.10.3",
38
+ "archiver": "^3.1.1",
39
+ "babel-plugin-transform-runtime": "^6.23.0",
40
+ "chokidar": "^3.4.0",
41
+ "clean-css": "^4.2.3",
42
+ "css-mqpacker": "^7.0.0",
43
+ "eslint": "^7.16.0",
44
+ "fs-jetpack": "^2.4.0",
45
+ "husky": "^9.1.7",
46
+ "install": "^0.13.0",
47
+ "node-notifier": "^5.4.0",
48
+ "npm": "^6.14.10",
49
+ "postcss": "^7.0.32",
50
+ "postcss-nested": "^4.1.1",
51
+ "postcss-preset-env": "^6.5.0",
52
+ "postcss-prettify": "^0.3.4",
53
+ "prettier": "^3.10.1",
54
+ "rollup": "^1.32.1",
55
+ "rollup-plugin-babel": "^4.4.0",
56
+ "rollup-plugin-commonjs": "^9.2.0",
57
+ "rollup-plugin-node-resolve": "^4.0.0",
58
+ "temporary": "^1.1.0",
59
+ "terser": "^4.8.0",
60
+ "uninstall": "0.0.0"
61
+ }
62
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "esnext": true,
3
+ "esversion": 6,
4
+ "maxparams": 4,
5
+ "asi": false
6
+ }