@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/README.md CHANGED
@@ -1,3 +1,715 @@
1
- # Temporary Holding Version
1
+ # GLightbox
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ GLightbox is a pure javascript lightbox. It can display images, iframes, inline content and videos with optional autoplay for YouTube, Vimeo and even self hosted videos.
4
+
5
+ > NOTE: This is forked version of the main package, released with patched fixes
6
+
7
+ ## Features
8
+
9
+ - **Small** - only 11KB Gzipped
10
+ - **Fast and Responsive** - works with any screen size
11
+ - **Gallery Support** - Create multiple galleries
12
+ - **Responsive Images Support** - Let the browser use the optimal image for the current screen resolution
13
+ - **Video Support** - Youtube, Vimeo and self hosted videos with autoplay
14
+ - **Inline content support** - display any inline content
15
+ - **Iframe support** - need to embed an iframe? no problem
16
+ - **Keyboard Navigation** - esc, arrows keys, tab and enter is all you need
17
+ - **Touch Navigation** - mobile touch events
18
+ - **Zoomable images** - zoom and drag images on mobile and desktop
19
+ - **API** - control the lightbox with the provided methods
20
+ - **Themeable** - create your skin or modify the animations with some minor css changes
21
+
22
+ ## Live Demo
23
+
24
+ You can check the live demo [right here](https://biati-digital.github.io/glightbox/)
25
+
26
+ ## Usage
27
+
28
+ ```bash
29
+ $ npm install @tomasvn/glightbox
30
+ # OR
31
+ $ yarn add @tomasvn/glightbox
32
+ # OR
33
+ $ bower install glightbox
34
+ ```
35
+
36
+ ```javascript
37
+ // Using ESM specification
38
+ import '/path/to/glightbox.js';
39
+
40
+ // Using a bundler like webpack
41
+ import GLightbox from 'glightbox';
42
+ ```
43
+
44
+ Or manually download and link `glightbox.min.js` in your HTML:
45
+
46
+ ```html
47
+ <link rel="stylesheet" href="dist/css/glightbox.css" />
48
+ <script src="dist/js/glightbox.min.js"></script>
49
+
50
+ <!-- USING A CDN -->
51
+
52
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/glightbox/dist/css/glightbox.min.css" />
53
+ <script src="https://cdn.jsdelivr.net/gh/mcstudios/glightbox/dist/js/glightbox.min.js"></script>
54
+
55
+ <script type="text/javascript">
56
+ const lightbox = GLightbox({ ...options });
57
+ </script>
58
+
59
+ <!-- USING ES MODULES -->
60
+
61
+ <script type="module">
62
+ import 'https://cdn.jsdelivr.net/gh/mcstudios/glightbox/dist/js/glightbox.min.js';
63
+
64
+ const lightbox = GLightbox({ ...options });
65
+ </script>
66
+ ```
67
+
68
+ ## Examples
69
+
70
+ ```html
71
+ <!-- Simple image -->
72
+ <a href="large.jpg" class="glightbox">
73
+ <img src="small.jpg" alt="image" />
74
+ </a>
75
+
76
+ <!-- Video -->
77
+ <a href="https://vimeo.com/115041822" class="glightbox2">
78
+ <img src="small.jpg" alt="image" />
79
+ </a>
80
+
81
+ <!-- Gallery -->
82
+ <a href="large.jpg" class="glightbox3" data-gallery="gallery1">
83
+ <img src="small.jpg" alt="image" />
84
+ </a>
85
+ <a href="video.mp4" class="glightbox3" data-gallery="gallery1">
86
+ <img src="small.jpg" alt="image" />
87
+ </a>
88
+
89
+ <!-- Simple Description -->
90
+ <a href="large.jpg" class="glightbox4" data-glightbox="title: My title; description: this is the slide description">
91
+ <img src="small.jpg" alt="image" />
92
+ </a>
93
+
94
+ <!-- Advanced Description -->
95
+ <a href="large.jpg" class="glightbox5" data-glightbox="title: My title; description: .custom-desc1">
96
+ <img src="small.jpg" alt="image" />
97
+ </a>
98
+
99
+ <div class="glightbox-desc custom-desc1">
100
+ <p>The content of this div will be used as the slide description</p>
101
+ <p>You can add links and any HTML you want</p>
102
+ </div>
103
+
104
+ <!-- URL with no extension -->
105
+ <a href="https://picsum.photos/1200/800" data-glightbox="type: image">
106
+ <img src="small.jpg" alt="image" />
107
+ </a>
108
+ <!-- OR using multiple data attributes -->
109
+ <a href="https://picsum.photos/1200/800" data-type="image">
110
+ <img src="small.jpg" alt="image" />
111
+ </a>
112
+
113
+ <!-- Using responsive images: specify sizes and srcset through data attributes in the
114
+ same way you would with the img tag.
115
+ See: https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images -->
116
+ <a
117
+ href="default.jpg"
118
+ class="glightbox6"
119
+ data-title="Responsive example"
120
+ data-description="Your browser will choose the optimal image for the resolution"
121
+ data-sizes="(max-width: 600px) 480px, 800px"
122
+ data-srcset="img480.jpg 480w, img800.jpg 800w"
123
+ >
124
+ <img src="small.jpg" alt="image" />
125
+ </a>
126
+ ```
127
+
128
+ ## Slide Options
129
+
130
+ You can specify some options to each individual slide, the available options are:
131
+
132
+ - title
133
+ - alt
134
+ - description
135
+ - descPosition
136
+ - type
137
+ - effect
138
+ - width
139
+ - height
140
+ - zoomable
141
+ - draggable
142
+
143
+ ```html
144
+ <!-- One line config -->
145
+ <a href="large.jpg" data-glightbox="title: Your title; description: description here; descPosition: left; type: image; effect: fade; width: 900px; height: auto; zoomable: true; draggable: true;"></a>
146
+
147
+ <!-- Multiple data attributes / You can use the options as separated data attributes -->
148
+ <a
149
+ href="large.jpg"
150
+ data-title="My title"
151
+ data-description="description here"
152
+ data-desc-position="right"
153
+ data-type="image"
154
+ data-effect="fade"
155
+ data-width="900px"
156
+ data-height="auto"
157
+ data-zoomable="true"
158
+ data-draggable="true"
159
+ ></a>
160
+ ```
161
+
162
+ ## Lightbox Options
163
+
164
+ Example use of the options.
165
+
166
+ ```javascript
167
+ const lightbox = GLightbox({
168
+ touchNavigation: true,
169
+ loop: true,
170
+ autoplayVideos: true
171
+ });
172
+
173
+ // Instead of using a selector, define the gallery elements
174
+ const myGallery = GLightbox({
175
+ elements: [
176
+ {
177
+ 'href': 'https://picsum.photos/1200/800',
178
+ 'type': 'image',
179
+ 'title': 'My Title',
180
+ 'description': 'Example',
181
+ },
182
+ {
183
+ 'href': 'https://picsum.photos/1200/800',
184
+ 'type': 'image',
185
+ 'alt': 'image text alternatives'
186
+ },
187
+ {
188
+ 'href': 'https://www.youtube.com/watch?v=Ga6RYejo6Hk',
189
+ 'type': 'video',
190
+ 'source': 'youtube', //vimeo, youtube or local
191
+ 'width': 900,
192
+ },
193
+ {
194
+ 'content': '<p>This will append some html inside the slide</p>' // read more in the API section
195
+ },
196
+ {
197
+ 'content': document.getElementById('inline-example') // this will append a node inside the slide
198
+ },
199
+ ],
200
+ autoplayVideos: true,
201
+ });
202
+ myGallery.open();
203
+
204
+ // If later you need to modify the elements you can use setElements
205
+ myGallery.setElements([...]);
206
+ ```
207
+
208
+ | Option | Type | Default | Description |
209
+ | --- | --- | --- | --- |
210
+ | selector | string | `.glightbox` | Name of the selector for example '.glightbox' or 'data-glightbox' or '\*[data-glightbox]' |
211
+ | elements | array | `null` | Instead of passing a selector you can pass all the items that you want in the gallery. |
212
+ | skin | string | `clean` | Name of the skin, it will add a class to the lightbox so you can style it with css. |
213
+ | openEffect | string | `zoom` | Name of the effect on lightbox open. (zoom, fade, none) |
214
+ | closeEffect | string | `zoom` | Name of the effect on lightbox close. (zoom, fade, none) |
215
+ | slideEffect | string | `slide` | Name of the effect on slide change. (slide, fade, zoom, none) |
216
+ | moreText | string | `See more` | More text for descriptions on mobile devices. |
217
+ | lessText | string | `See less` | Text for collapsing expanded descriptions. |
218
+ | moreLength | number | `60` | Number of characters to display on the description before adding the moreText link (only for mobiles), if 0 it will display the entire description. |
219
+ | closeButtonText | string | `Close` | Text for the close button. |
220
+ | closeButton | boolean | `true` | Show or hide the close button. |
221
+ | nextButtonText | string | `Next` | Text for the next slide button. |
222
+ | prevButtonText | string | `Previous` | Text for the previous slide button. |
223
+ | touchNavigation | boolean | `true` | Enable or disable the touch navigation (swipe). |
224
+ | touchFollowAxis | boolean | `true` | Image follow axis when dragging on mobile. |
225
+ | keyboardNavigation | boolean | `true` | Enable or disable the keyboard navigation. |
226
+ | closeOnOutsideClick | boolean | `true` | Close the lightbox when clicking outside the active slide. |
227
+ | startAt | number | `0` | Start lightbox at defined index. |
228
+ | width | number | `900px` | Default width for inline elements and iframes, you can define a specific size on each slide. You can use any unit for example 90% or 100vw for full width |
229
+ | height | number | `506px` | Default height for inline elements and iframes, you can define a specific size on each slide.You can use any unit for example 90% or 100vh **For inline elements you can set the height to auto**. |
230
+ | videosWidth | number | `960px` | Default width for videos. Videos are responsive so height is not required. The width can be in px % or even vw for example, 500px, 90% or 100vw for full width videos |
231
+ | descPosition | string | `bottom` | Global position for slides description, you can define a specific position on each slide (bottom, top, left, right). |
232
+ | loop | boolean | `false` | Loop slides on end. |
233
+ | zoomable | boolean | `true` | Enable or disable zoomable images you can also use data-zoomable="false" on individual nodes. |
234
+ | draggable | boolean | `true` | Enable or disable mouse drag to go prev and next slide (only images and inline content), you can also use data-draggable="false" on individual nodes. |
235
+ | dragToleranceX | number | `40` | Used with draggable. Number of pixels the user has to drag to go to prev or next slide. |
236
+ | dragToleranceY | number | `65` | Used with draggable. Number of pixels the user has to drag up or down to close the lightbox (Set 0 to disable vertical drag). |
237
+ | dragAutoSnap | boolean | `false` | If true the slide will automatically change to prev/next or close if dragToleranceX or dragToleranceY is reached, otherwise it will wait till the mouse is released. |
238
+ | preload | boolean | `true` | Enable or disable preloading. |
239
+ | svg | object | `{}` | Set your own svg icons. |
240
+ | cssEfects | object | 'See animations' | Define or adjust lightbox animations. See the Animations section in the README. |
241
+ | lightboxHTML | string | 'See themes' | You can completely change the html of GLightbox. See the Themeable section in the README. |
242
+ | slideHTML | string | 'See themes' | You can completely change the html of the individual slide. See the Themeable section in the README. |
243
+ | autoplayVideos | boolean | `true` | Autoplay videos on open. |
244
+ | autofocusVideos | boolean | `false` | If true video will be focused on play to allow keyboard sortcuts for the player, this will deactivate prev and next arrows to change slide so use it only if you know what you are doing. |
245
+ | plyr | object | `{}` | [View video player options.](#video-player) |
246
+
247
+ ## Events
248
+
249
+ You can listen for events using your GLightbox instance (see example under the table). You can use the on() API method or once().
250
+
251
+ ```javascript
252
+ const lightbox = GLightbox();
253
+ lightbox.on('open', () => {
254
+ // Do something
255
+ });
256
+
257
+ lightbox.once('slide_changed', () => {
258
+ // Do something just one time
259
+ });
260
+ ```
261
+
262
+ | Event Type | Description |
263
+ | ------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
264
+ | open | Provide a function when the lightbox is opened. |
265
+ | close | Provide a function when the lightbox is closed. |
266
+ | slide_before_change | Trigger a function before the slide is changed. |
267
+ | slide_changed | Trigger a function after the slide is changed. |
268
+ | slide_before_load | Trigger a function before a slide is loaded for the first time, the function will only be called once |
269
+ | slide_after_load | Trigger a function after a slide is loaded and it's content is set for the first time, the function will only be called once |
270
+ | slide_inserted | Trigger a function after a slide is inserted using insertSlide. |
271
+ | slide_removed | Trigger a function after a slide is removed` |
272
+
273
+ ```javascript
274
+ const lightbox = GLightbox();
275
+ lightbox.on('slide_before_change', ({ prev, current }) => {
276
+ console.log('Prev slide', prev);
277
+ console.log('Current slide', current);
278
+
279
+ // Prev and current are objects that contain the following data
280
+ const { slideIndex, slideNode, slideConfig, player, trigger } = current;
281
+
282
+ // slideIndex - the slide index
283
+ // slideNode - the node you can modify
284
+ // slideConfig - will contain the configuration of the slide like title, description, etc.
285
+ // player - the slide player if it exists otherwise will return false
286
+ // trigger - this will contain the element that triggers this slide, this can be a link, a button, etc in your HTML, it can be null if the elements in the gallery were set dinamically
287
+ });
288
+
289
+ lightbox.on('slide_changed', ({ prev, current }) => {
290
+ console.log('Prev slide', prev);
291
+ console.log('Current slide', current);
292
+
293
+ // Prev and current are objects that contain the following data
294
+ const { slideIndex, slideNode, slideConfig, player, trigger } = current;
295
+
296
+ // slideIndex - the slide index
297
+ // slideNode - the node you can modify
298
+ // slideConfig - will contain the configuration of the slide like title, description, etc.
299
+ // player - the slide player if it exists otherwise will return false
300
+ // trigger - this will contain the element that triggers this slide, this can be a link, a button, etc in your HTML, it can be null if the elements in the gallery were set dinamically
301
+
302
+ if (player) {
303
+ if (!player.ready) {
304
+ // If player is not ready
305
+ player.on('ready', (event) => {
306
+ // Do something when video is ready
307
+ });
308
+ }
309
+
310
+ player.on('play', (event) => {
311
+ console.log('Started play');
312
+ });
313
+
314
+ player.on('volumechange', (event) => {
315
+ console.log('Volume change');
316
+ });
317
+
318
+ player.on('ended', (event) => {
319
+ console.log('Video ended');
320
+ });
321
+ }
322
+ });
323
+
324
+ // Useful to modify the slide
325
+ // before it's content is added
326
+ lightbox.on('slide_before_load', (data) => {
327
+ // data is an object that contain the following
328
+ const { slideIndex, slideNode, slideConfig, player, trigger } = data;
329
+
330
+ // slideIndex - the slide index
331
+ // slideNode - the node you can modify
332
+ // slideConfig - will contain the configuration of the slide like title, description, etc.
333
+ // player - the slide player if it exists otherwise will return false
334
+ // trigger - this will contain the element that triggers this slide, this can be a link, a button, etc in your HTML, it can be null if the elements in the gallery were set dinamically
335
+ });
336
+
337
+ // Useful to execute scripts that depends
338
+ // on the slide to be ready with all it's content
339
+ // and already has a height
340
+ // data will contain all the info about the slide
341
+ lightbox.on('slide_after_load', (data) => {
342
+ // data is an object that contain the following
343
+ const { slideIndex, slideNode, slideConfig, player, trigger } = data;
344
+
345
+ // slideIndex - the slide index
346
+ // slideNode - the node you can modify
347
+ // slideConfig - will contain the configuration of the slide like title, description, etc.
348
+ // player - the slide player if it exists otherwise will return false
349
+ // trigger - this will contain the element that triggers this slide, this can be a link, a button, etc in your HTML, it can be null if the elements in the gallery were set dinamically
350
+ });
351
+
352
+ // Trigger a function when a slide is inserted
353
+ lightbox.on('slide_inserted', (data) => {
354
+ // data is an object that contain the following
355
+ const { slideIndex, slideNode, slideConfig, player, trigger } = data;
356
+
357
+ // slideIndex - the slide index
358
+ // slideNode - the node you can modify
359
+ // slideConfig - will contain the configuration of the slide like title, description, etc.
360
+ // player - the slide player if it exists otherwise will return false
361
+ // trigger - null
362
+ });
363
+
364
+ // Trigger a function when a slide is removed
365
+ lightbox.on('slide_removed', (index) => {
366
+ // index is the position of the element in the gallery
367
+ });
368
+ ```
369
+
370
+ ## Video player
371
+
372
+ GLightbox includes "[Plyr](https://plyr.io/)" the best player out there, you can pass any Plyr option to the player, view all available options here [Plyr options](https://github.com/sampotts/plyr). GLightbox will only inject the player library if required and only when the lightbox is opened.
373
+
374
+ **Internet Explorer 11. If you need support for this browser you need to set the js url to use the polyfilled version. This is not the default because IE11 is ancient and we need to let it die.**
375
+
376
+ ### Autoplay for mobile/tablet
377
+
378
+ Please note, autoplay is blocked in some browsers, there’s nothing we can do to change that unfortunately, the browser will decide if your video can be autoplayed. Please do not post issues about this, instead inform yourself about this topic:
379
+
380
+ - [https://webkit.org/blog/6784/new-video-policies-for-ios/](https://webkit.org/blog/6784/new-video-policies-for-ios/)
381
+ - [https://developers.google.com/web/updates/2017/09/autoplay-policy-changes](https://developers.google.com/web/updates/2017/09/autoplay-policy-changes)
382
+ - [https://hacks.mozilla.org/2019/02/firefox-66-to-block-automatically-playing-audible-video-and-audio/](https://hacks.mozilla.org/2019/02/firefox-66-to-block-automatically-playing-audible-video-and-audio/)
383
+
384
+ they decide if a video can be autoplayed based in a few rules
385
+
386
+ ```
387
+ plyr: {
388
+ js: 'https://cdn.plyr.io/3.6.2/plyr.polyfilled.js',
389
+ ....
390
+ ```
391
+
392
+ ```javascript
393
+ const lightbox = GLightbox({
394
+ plyr: {
395
+ css: 'https://cdn.plyr.io/3.5.6/plyr.css', // Default not required to include
396
+ js: 'https://cdn.plyr.io/3.5.6/plyr.js', // Default not required to include
397
+ config: {
398
+ ratio: '16:9', // or '4:3'
399
+ muted: false,
400
+ hideControls: true,
401
+ youtube: {
402
+ noCookie: true,
403
+ rel: 0,
404
+ showinfo: 0,
405
+ iv_load_policy: 3
406
+ },
407
+ vimeo: {
408
+ byline: false,
409
+ portrait: false,
410
+ title: false,
411
+ speed: true,
412
+ transparent: false
413
+ }
414
+ }
415
+ }
416
+ });
417
+ ```
418
+
419
+ ## API
420
+
421
+ There are methods, setters and getters on a GLightbox object. The easiest way to access the GLightbox object is to set the return value from your call to a variable. For example:
422
+
423
+ ```javascript
424
+ const lightbox = GLightbox({ ...options });
425
+ ```
426
+
427
+ ## Methods
428
+
429
+ Example method use:
430
+
431
+ ```javascript
432
+ lightbox.nextSlide(); // Go to next slide
433
+ lightbox.close(); // Close the lightbox
434
+ ```
435
+
436
+ | Option | Parameters | Description |
437
+ | ---------------------- | ------------------ | -------------------------------------------------------------------------- |
438
+ | open | `node` | Open the lightbox, you can optionally pass a node. |
439
+ | openAt | `number` | Open at specific index. |
440
+ | close | `-` | Close the lightbox. |
441
+ | reload | `-` | Reload the lightbox, after inserting content with ajax. |
442
+ | destroy | `-` | Destroy and remove all attached events. |
443
+ | prevSlide | `-` | Go to the previous slide. |
444
+ | nextSlide | `-` | Go to the next slide. |
445
+ | goToSlide | `number` | Index of the slide. |
446
+ | insertSlide | `object, index` | Insert a slide at the specified index. |
447
+ | removeSlide | `index` | Remove slide at the specified index. |
448
+ | getActiveSlide | `-` | Get active slide. It will return the active node. |
449
+ | getActiveSlideIndex | `-` | Get active slide. It will return the active slide index. |
450
+ | slidePlayerPlay | `number` | Play video in the specified slide. |
451
+ | slidePlayerPause | `number` | Pause video in the specified slide. |
452
+ | getSlidePlayerInstance | `node, index` | Get the player instance of the specified slide. |
453
+ | getAllPlayers | `-` | Get all players instance. |
454
+ | setElements | `[]` | Update the lightbox gallery elements. |
455
+ | on | `string, function` | Set an event listener. See Events section |
456
+ | once | `string, function` | Set an event listener that will be triggered only once. See Events section |
457
+
458
+ ```javascript
459
+ // Example set custom gallery items
460
+ // This overwrites all the items in the gallery
461
+ lightbox.setElements([
462
+ {
463
+ 'href': 'https://picsum.photos/1200/800',
464
+ 'type': 'image' // Type is only required if GLightbox fails to know what kind of content should display
465
+ },
466
+ {
467
+ 'href': 'https://www.youtube.com/watch?v=Ga6RYejo6Hk',
468
+ 'type': 'video', // Type is only required if GLightbox fails to know what kind of content should display
469
+ 'width': '900px',
470
+ },
471
+ {
472
+ 'content': '<p>some html to append in the slide</p>',
473
+ 'width': '900px',
474
+ }
475
+ ]);
476
+
477
+
478
+ // Insert a single slide at the end of all the items,
479
+ lightbox.insertSlide({
480
+ href: 'video url...',
481
+ width: '90vw'
482
+ });
483
+
484
+ // Insert a single slide at index 2 or pass 0 to add it at the start
485
+ lightbox.insertSlide({
486
+ href: 'video url...',
487
+ width: '90vw'
488
+ }, 2);
489
+
490
+ // You can insert a slide with a defined html
491
+ lightbox.insertSlide({
492
+ content: '<p>some html to append in the slide</p>',
493
+ width: '90vw'
494
+ }, 2);
495
+
496
+ // Or if you prefer you can pass a node
497
+ // and it will be inserted in the slide
498
+ lightbox.insertSlide({
499
+ content: document.getElementById('inline-example'),
500
+ width: '90vw'
501
+ }, 2);
502
+
503
+ // Remove the slide at index 2
504
+ lightbox.removeSlide(2);
505
+
506
+ // Open the lightbox
507
+ lightbox.open();
508
+
509
+ // You can also open the lightbox at a specific index
510
+ lightbox.openAt(2);
511
+
512
+ // So imagine that you are making an ajax request that returns some html
513
+ // You can create an empty instance and append the content once is returned
514
+
515
+ const ajaxExample = GLightbox({ selector: null }); // or you can set the selector empty selector: ''
516
+
517
+ doAjaxCall({...}).then(response => {
518
+ ajaxExample.insertSlide({
519
+ width: '500px',
520
+ content: response.html
521
+ });
522
+ ajaxExample.open();
523
+ })
524
+
525
+ // Or you could use the set elements method to empty all the slides if any
526
+
527
+ doAjaxCall({...}).then(response => {
528
+ ajaxExample.setElements([
529
+ {
530
+ content: response.html
531
+ }
532
+ ]);
533
+ ajaxExample.open();
534
+ })
535
+
536
+ ```
537
+
538
+ ## Animations
539
+
540
+ Animations are created with CSS, each effect has an in and out value and they are used to attach the correct classes to the node.
541
+
542
+ For example if you are using
543
+
544
+ ```javascript
545
+ const glightbox = GLightbox({
546
+ openEffect: 'zoom',
547
+ closeEffect: 'fade',
548
+ cssEfects: {
549
+ // This are some of the animations included, no need to overwrite
550
+ fade: { in: 'fadeIn', out: 'fadeOut' },
551
+ zoom: { in: 'zoomIn', out: 'zoomOut' }
552
+ }
553
+ });
554
+ ```
555
+
556
+ The open effect will use cssEfects.zoom.in and will add the class gzoomIn, if you take a look at the CSS you'll see:
557
+
558
+ ```javascript
559
+ .gzoomIn {
560
+ animation: gzoomIn .5s ease;
561
+ }
562
+
563
+ @keyframes gzoomIn {
564
+ from {
565
+ opacity: 0;
566
+ transform: scale3d(.3, .3, .3);
567
+ }
568
+ to {
569
+ opacity: 1;
570
+ }
571
+ }
572
+ ```
573
+
574
+ ### Adding a custom animation
575
+
576
+ You can create any animation you want, you can find some inspiration in the Animate.css library, for example you can add the bounce animation like this:
577
+
578
+ ```javascript
579
+ const glightbox = GLightbox({
580
+ openEffect: 'bounce', // Define that we want the bounce animation on open
581
+ cssEfects: {
582
+ // register our new animation
583
+ bounce: { in: 'bounceIn', out: 'bounceOut' }
584
+ }
585
+ });
586
+ ```
587
+
588
+ ```css
589
+ /*A g will be appended to the animation name so bounceIn will become gbounceIn */
590
+ .gbounceIn {
591
+ animation: bounceIn 1.3s ease;
592
+ }
593
+
594
+ @keyframes bounceIn {
595
+ from,
596
+ 20%,
597
+ 40%,
598
+ 60%,
599
+ 80%,
600
+ to {
601
+ animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
602
+ }
603
+
604
+ 0% {
605
+ opacity: 0;
606
+ transform: scale3d(0.3, 0.3, 0.3);
607
+ }
608
+
609
+ 20% {
610
+ transform: scale3d(1.1, 1.1, 1.1);
611
+ }
612
+
613
+ 40% {
614
+ transform: scale3d(0.9, 0.9, 0.9);
615
+ }
616
+
617
+ 60% {
618
+ opacity: 1;
619
+ transform: scale3d(1.03, 1.03, 1.03);
620
+ }
621
+
622
+ 80% {
623
+ transform: scale3d(0.97, 0.97, 0.97);
624
+ }
625
+
626
+ to {
627
+ opacity: 1;
628
+ transform: scale3d(1, 1, 1);
629
+ }
630
+ }
631
+ ```
632
+
633
+ ## Themeable
634
+
635
+ You can completely customize the structure of GLightbox and use CSS to change any part you want.
636
+
637
+ ```javascript
638
+ const customLightboxHTML = `<div id="glightbox-body" class="glightbox-container">
639
+ <div class="gloader visible"></div>
640
+ <div class="goverlay"></div>
641
+ <div class="gcontainer">
642
+ <div id="glightbox-slider" class="gslider"></div>
643
+ <button class="gnext gbtn" tabindex="0" aria-label="Next" data-customattribute="example">{nextSVG}</button>
644
+ <button class="gprev gbtn" tabindex="1" aria-label="Previous">{prevSVG}</button>
645
+ <button class="gclose gbtn" tabindex="2" aria-label="Close">{closeSVG}</button>
646
+ </div>
647
+ </div>`;
648
+
649
+ let customSlideHTML = `<div class="gslide">
650
+ <div class="gslide-inner-content">
651
+ <div class="ginner-container">
652
+ <div class="gslide-media">
653
+ </div>
654
+ <div class="gslide-description">
655
+ <div class="gdesc-inner">
656
+ <h4 class="gslide-title"></h4>
657
+ <div class="gslide-desc"></div>
658
+ </div>
659
+ </div>
660
+ </div>
661
+ </div>
662
+ </div>`;
663
+
664
+ const glightbox = GLightbox({
665
+ lightboxHTML: customLightboxHTML,
666
+ slideHTML: customSlideHTML,
667
+ skin: 'supercool'
668
+ });
669
+ ```
670
+
671
+ You can also define a skin name and the lightbox will append the class name "glightbox-supercool" so you can customize it with CSS, this will leave a barebones structure so you can change the buttons appearance, etc.
672
+
673
+ ## Development
674
+
675
+ ```bash
676
+ $ npm install
677
+ $ npm run watch
678
+ ```
679
+
680
+ ## Browser Support
681
+
682
+ GLightbox was tested in the following browsers.
683
+
684
+ - Safari
685
+ - Mobile Safari
686
+ - Opera
687
+ - Edge
688
+ - Firefox
689
+ - Internet Explorer 11
690
+
691
+ It will work in any browser that supports CSS Flexbox
692
+
693
+ ## Contributing
694
+
695
+ Feel free to report any issues! If you wish to contribute by fixing a bug or implementing a new feature, please first read the [CONTRIBUTING](./CONTRIBUTING.md) guide.
696
+
697
+ ## Donate
698
+
699
+ If you find this code useful, please consider a donation to keep this project growing, any amount is appreciated.
700
+
701
+ [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://paypal.me/bdigital9816/5usd)
702
+
703
+ ## Support
704
+
705
+ We only provide support for bugs and feature requests, so please only post issues about this two topics, if you need help implementing GLightbox or you are just starting with HTML/CSS/Javascript please use stackoverlow, you'll be able to find more help there. This will help us to keep the issues related to the library and solve issues faster.
706
+
707
+ ## Changelog
708
+
709
+ #### Latest version vundefined
710
+
711
+ See the [CHANGELOG.md](CHANGELOG.md) file for details
712
+
713
+ ## License
714
+
715
+ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details