@brandocms/jupiter 3.48.3 → 3.49.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brandocms/jupiter",
3
- "version": "3.48.3",
3
+ "version": "3.49.0",
4
4
  "description": "Frontend helpers.",
5
5
  "author": "Univers/Twined",
6
6
  "license": "UNLICENSED",
@@ -107,6 +107,10 @@ export default class Application {
107
107
  left: 0
108
108
  }
109
109
 
110
+ this.state = {
111
+ revealed: false
112
+ }
113
+
110
114
  this.opts = _defaultsDeep(opts, DEFAULT_OPTIONS)
111
115
  this.focusableSelectors = this.opts.focusableSelectors
112
116
 
@@ -487,6 +491,7 @@ export default class Application {
487
491
 
488
492
  _emitRevealedEvent() {
489
493
  if (!document.body.hasAttribute('data-app-revealed')) {
494
+ this.state.revealed = true
490
495
  document.body.dataset.appRevealed = true
491
496
  window.dispatchEvent(this.revealedEvent)
492
497
  this.executeCallbacks(Events.APPLICATION_REVEALED)
@@ -27,9 +27,13 @@ export default class Lazyload {
27
27
  this.initialize()
28
28
 
29
29
  if (this.opts.registerCallback) {
30
- this.app.registerCallback(Events.APPLICATION_REVEALED, () => {
30
+ if (this.app.state.revealed) {
31
31
  this.watch()
32
- })
32
+ } else {
33
+ this.app.registerCallback(Events.APPLICATION_REVEALED, () => {
34
+ this.watch()
35
+ })
36
+ }
33
37
  }
34
38
  }
35
39
 
@@ -73,7 +77,6 @@ export default class Lazyload {
73
77
  this.opts.revealIntersectionObserverConfig
74
78
  )
75
79
 
76
- this.lazyPictures = document.querySelectorAll('[data-ll-srcset]')
77
80
  this.initObserver(this.loadObserver)
78
81
 
79
82
  // Deprecate data-ll-image sometime
@@ -94,6 +97,7 @@ export default class Lazyload {
94
97
  initObserver(observer, setAttrs = true) {
95
98
  this.lazyPictures.forEach((picture, idx) => {
96
99
  if (setAttrs) {
100
+ picture.setAttribute('data-ll-srcset-initialized', '')
97
101
  picture.querySelectorAll('img:not([data-ll-loaded])').forEach(img => {
98
102
  img.setAttribute('data-ll-blurred', '')
99
103
  img.setAttribute('data-ll-idx', idx)
@@ -181,11 +185,27 @@ export default class Lazyload {
181
185
 
182
186
  // we reveal the picture when it enters the viewport
183
187
  handleRevealEntries(elements) {
188
+ const srcsetReadyObserver = new MutationObserver(mutations => {
189
+ mutations.forEach(record => {
190
+ if (record.type === 'attributes' && record.attributeName === 'data-ll-srcset-ready') {
191
+ this.revealPicture(record.target)
192
+ this.revealObserver.unobserve(record.target)
193
+ }
194
+ })
195
+ })
196
+
184
197
  elements.forEach(item => {
185
198
  if (item.isIntersecting || item.intersectionRatio > 0) {
186
199
  const picture = item.target
187
- this.revealPicture(picture)
188
- this.revealObserver.unobserve(item.target)
200
+ const ready = item.target.hasAttribute('data-ll-srcset-ready')
201
+ if (!ready) {
202
+ // element is not loaded, observe the picture and wait for
203
+ // `data-ll-srcset-ready` before revealing
204
+ srcsetReadyObserver.observe(picture, { attributes: true })
205
+ } else {
206
+ this.revealPicture(picture)
207
+ this.revealObserver.unobserve(item.target)
208
+ }
189
209
  }
190
210
  })
191
211
  }
@@ -63,7 +63,8 @@ const DEFAULT_EVENTS = {
63
63
  h._hiding = false
64
64
  }
65
65
  })
66
- }
66
+ },
67
+ onSmall: () => {}
67
68
  }
68
69
 
69
70
  const DEFAULT_OPTIONS = {