@brandocms/jupiter 3.48.2 → 3.48.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brandocms/jupiter",
3
- "version": "3.48.2",
3
+ "version": "3.48.3",
4
4
  "description": "Frontend helpers.",
5
5
  "author": "Univers/Twined",
6
6
  "license": "UNLICENSED",
@@ -8,6 +8,9 @@ const DEFAULT_OPTIONS = {
8
8
  /* enable captions */
9
9
  captions: false,
10
10
 
11
+ /* enable index numbers */
12
+ numbers: false,
13
+
11
14
  /* enable swipe — this breaks native zoom! */
12
15
  swipe: true,
13
16
 
@@ -73,6 +76,10 @@ const DEFAULT_OPTIONS = {
73
76
  lightbox.timelines.image.to(lightbox.nextImage, { duration: 0.5, autoAlpha: 1, delay })
74
77
  },
75
78
 
79
+ onNumbers: (lightbox, section) => {
80
+ lightbox.elements.numbers.innerHTML = `${lightbox.currentIndex + 1}/${section.length}`
81
+ },
82
+
76
83
  onBeforeOpen: () => {},
77
84
 
78
85
  onOpen: h => {
@@ -177,6 +184,7 @@ export default class Lightbox {
177
184
  this.elements.content = document.createElement('div')
178
185
  this.elements.imgWrapper = document.createElement('div')
179
186
  this.elements.dots = document.createElement('div')
187
+ this.elements.numbers = document.createElement('div')
180
188
  this.elements.nextArrow = document.createElement('a')
181
189
  this.elements.prevArrow = document.createElement('a')
182
190
  this.elements.close = document.createElement('a')
@@ -188,6 +196,7 @@ export default class Lightbox {
188
196
  this.elements.prevArrow.classList.add('lightbox-prev')
189
197
  this.elements.close.classList.add('lightbox-close')
190
198
  this.elements.dots.classList.add('lightbox-dots')
199
+ this.elements.numbers.classList.add('lightbox-numbers')
191
200
  this.elements.wrapper.classList.add('lightbox-backdrop')
192
201
  this.elements.wrapper.setAttribute('data-lightbox-wrapper-section', section)
193
202
  this.elements.imgWrapper.classList.add('lightbox-image-wrapper')
@@ -210,9 +219,12 @@ export default class Lightbox {
210
219
  this.setImg(section, this.getPrevIdx(section))
211
220
  })
212
221
 
213
- document.addEventListener('keyup', event => {
222
+ this.keyUpCallback = event => {
214
223
  this.onKeyup(event, section)
215
- })
224
+ }
225
+
226
+ document.removeEventListener('keyup', this.keyUpCallback)
227
+ document.addEventListener('keyup', this.keyUpCallback)
216
228
 
217
229
  this.elements.wrapper.addEventListener('mousemove', event => {
218
230
  this.onMouseMove(event)
@@ -264,6 +276,10 @@ export default class Lightbox {
264
276
  this.elements.content.appendChild(this.elements.prevArrow)
265
277
  this.elements.content.appendChild(this.elements.dots)
266
278
 
279
+ if (this.opts.numbers) {
280
+ this.elements.content.appendChild(this.elements.numbers)
281
+ }
282
+
267
283
  if (this.opts.captions) {
268
284
  this.elements.caption = document.createElement('div')
269
285
  this.elements.caption.classList.add('lightbox-caption')
@@ -273,7 +289,7 @@ export default class Lightbox {
273
289
  this.elements.wrapper.appendChild(this.elements.content)
274
290
  document.body.appendChild(this.elements.wrapper)
275
291
 
276
- this.setImg(section, index, this.getPrevIdx(index))
292
+ this.setImg(section, index, this.getPrevIdx(section))
277
293
  if (this.opts.swipe) {
278
294
  this.attachSwiper(section, this.elements.content, index)
279
295
  }
@@ -289,7 +305,7 @@ export default class Lightbox {
289
305
  }
290
306
 
291
307
  close() {
292
- document.removeEventListener('keyup', this.onKeyup.bind(this))
308
+ document.removeEventListener('keyup', this.keyUpCallback)
293
309
  this.opts.onClose(this)
294
310
  this.opts.onAfterClose(this)
295
311
  this.currentIndex = null
@@ -326,6 +342,10 @@ export default class Lightbox {
326
342
  })
327
343
  }
328
344
 
345
+ if (this.elements.numbers) {
346
+ this.opts.onNumbers(this, this.sections[section])
347
+ }
348
+
329
349
  if (this.currentImage) {
330
350
  // fade out current image
331
351
  this.opts.onImageOut(this)