@brandocms/jupiter 3.47.0 → 3.48.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 +9 -9
- package/src/events/index.js +1 -0
- package/src/index.js +5 -7
- package/src/modules/Application/index.js +110 -77
- package/src/modules/Breakpoints/index.js +14 -17
- package/src/modules/Cookies/index.js +86 -43
- package/src/modules/CoverOverlay/index.js +6 -3
- package/src/modules/Dataloader/index.js +173 -7
- package/src/modules/Dom/index.js +26 -26
- package/src/modules/Dropdown/index.js +14 -14
- package/src/modules/EqualHeightElements/index.js +70 -0
- package/src/modules/EqualHeightImages/index.js +17 -18
- package/src/modules/FeatureTests/index.js +22 -15
- package/src/modules/FixedHeader/index.js +79 -75
- package/src/modules/Fontloader/index.js +5 -3
- package/src/modules/FooterReveal/index.js +1 -1
- package/src/modules/HeroSlider/index.js +33 -23
- package/src/modules/HeroVideo/index.js +15 -13
- package/src/modules/Lazyload/index.js +119 -65
- package/src/modules/Lightbox/index.js +40 -43
- package/src/modules/Links/index.js +8 -7
- package/src/modules/Marquee/index.js +40 -34
- package/src/modules/MobileMenu/index.js +112 -65
- package/src/modules/Moonwalk/index.js +256 -203
- package/src/modules/Parallax/index.js +24 -14
- package/src/modules/Popup/index.js +24 -21
- package/src/modules/ScrollSpy/index.js +5 -5
- package/src/modules/StackedBoxes/index.js +5 -5
- package/src/modules/StickyHeader/index.js +73 -70
- package/src/modules/Toggler/index.js +2 -2
- package/src/modules/Typography/index.js +13 -10
- package/src/utils/dispatchElementEvent.js +2 -2
- package/src/utils/imageIsLoaded.js +1 -1
- package/src/utils/imagesAreLoaded.js +3 -3
- package/src/utils/loadScript.js +9 -8
- package/src/utils/rafCallback.js +12 -10
- package/src/utils/zoom.js +11 -8
|
@@ -93,7 +93,7 @@ const DEFAULT_OPTIONS = {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
export default class Moonwalk {
|
|
96
|
-
constructor
|
|
96
|
+
constructor(app, opts = {}, container = document.body) {
|
|
97
97
|
this.app = app
|
|
98
98
|
this.opts = _defaultsDeep(opts, DEFAULT_OPTIONS)
|
|
99
99
|
if (container !== document.body) {
|
|
@@ -102,7 +102,7 @@ export default class Moonwalk {
|
|
|
102
102
|
this.initialize(container)
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
initialize
|
|
105
|
+
initialize(container = document.body) {
|
|
106
106
|
if (this.opts.clearMoonwalkOnAnchors) {
|
|
107
107
|
if (window.location.hash) {
|
|
108
108
|
this.removeAllWalks()
|
|
@@ -111,7 +111,9 @@ export default class Moonwalk {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
if (this.opts.clearNestedSections) {
|
|
114
|
-
container
|
|
114
|
+
container
|
|
115
|
+
.querySelectorAll('[data-moonwalk-section] [data-moonwalk-section]')
|
|
116
|
+
.forEach(ms => ms.removeAttribute('data-moonwalk-section'))
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
this.addClass()
|
|
@@ -134,15 +136,20 @@ export default class Moonwalk {
|
|
|
134
136
|
/**
|
|
135
137
|
* Add `moonwalk` class to html element to identify ourselves.
|
|
136
138
|
*/
|
|
137
|
-
addClass
|
|
139
|
+
addClass() {
|
|
138
140
|
document.documentElement.classList.add('moonwalk')
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
/**
|
|
142
144
|
* Remove all moonwalks. Useful for clients who prefer reduced motion
|
|
143
145
|
*/
|
|
144
|
-
removeAllWalks
|
|
145
|
-
const keys = [
|
|
146
|
+
removeAllWalks(container = document.body) {
|
|
147
|
+
const keys = [
|
|
148
|
+
'data-moonwalk',
|
|
149
|
+
'data-moonwalk-run',
|
|
150
|
+
'data-moonwalk-section',
|
|
151
|
+
'data-moonwalk-children'
|
|
152
|
+
]
|
|
146
153
|
keys.forEach(key => {
|
|
147
154
|
const elems = container.querySelectorAll(`[${key}]`)
|
|
148
155
|
Array.from(elems).forEach(el => el.removeAttribute(key))
|
|
@@ -150,8 +157,13 @@ export default class Moonwalk {
|
|
|
150
157
|
})
|
|
151
158
|
}
|
|
152
159
|
|
|
153
|
-
removeFor
|
|
154
|
-
const keys = [
|
|
160
|
+
removeFor(container = document.body, selector) {
|
|
161
|
+
const keys = [
|
|
162
|
+
'data-moonwalk',
|
|
163
|
+
'data-moonwalk-run',
|
|
164
|
+
'data-moonwalk-section',
|
|
165
|
+
'data-moonwalk-children'
|
|
166
|
+
]
|
|
155
167
|
keys.forEach(key => {
|
|
156
168
|
const elems = container.querySelectorAll(`${selector}[${key}]`)
|
|
157
169
|
Array.from(elems).forEach(el => el.removeAttribute(key))
|
|
@@ -159,18 +171,18 @@ export default class Moonwalk {
|
|
|
159
171
|
}
|
|
160
172
|
|
|
161
173
|
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
removeRun
|
|
174
|
+
* Remove run matching name
|
|
175
|
+
*/
|
|
176
|
+
removeRun(container = document.body, name) {
|
|
165
177
|
const key = 'data-moonwalk-run'
|
|
166
178
|
const elems = container.querySelectorAll(`[${key}="${name}"]`)
|
|
167
179
|
Array.from(elems).forEach(el => el.removeAttribute(key))
|
|
168
180
|
}
|
|
169
181
|
|
|
170
182
|
/**
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
removeRuns
|
|
183
|
+
* Remove all runs
|
|
184
|
+
*/
|
|
185
|
+
removeRuns(container = document.body) {
|
|
174
186
|
const key = 'data-moonwalk-run'
|
|
175
187
|
const elems = container.querySelectorAll(`[${key}]`)
|
|
176
188
|
Array.from(elems).forEach(el => el.removeAttribute(key))
|
|
@@ -181,7 +193,7 @@ export default class Moonwalk {
|
|
|
181
193
|
*
|
|
182
194
|
* @param {*} section
|
|
183
195
|
*/
|
|
184
|
-
addIds
|
|
196
|
+
addIds(section) {
|
|
185
197
|
Array.from(section.querySelectorAll('[data-moonwalk]')).forEach(el => {
|
|
186
198
|
el.setAttribute('data-moonwalk-id', Math.random().toString(36).substring(7))
|
|
187
199
|
})
|
|
@@ -192,7 +204,7 @@ export default class Moonwalk {
|
|
|
192
204
|
*
|
|
193
205
|
* @param {*} section
|
|
194
206
|
*/
|
|
195
|
-
addIndexes
|
|
207
|
+
addIndexes(section) {
|
|
196
208
|
Object.keys(this.opts.walks).forEach(key => {
|
|
197
209
|
const searchAttr = key === 'default' ? '[data-moonwalk=""]' : `[data-moonwalk="${key}"]`
|
|
198
210
|
const elements = section.querySelectorAll(searchAttr)
|
|
@@ -207,7 +219,7 @@ export default class Moonwalk {
|
|
|
207
219
|
* Go through each `data-moonwalk-run`, parse children, add IDs/indexes
|
|
208
220
|
* (if wanted), initialize a new object for each.
|
|
209
221
|
*/
|
|
210
|
-
initializeRuns
|
|
222
|
+
initializeRuns(container = document.body) {
|
|
211
223
|
const runs = container.querySelectorAll('[data-moonwalk-run]')
|
|
212
224
|
return Array.from(runs).map(run => {
|
|
213
225
|
const foundRun = this.opts.runs[run.getAttribute('data-moonwalk-run')]
|
|
@@ -227,17 +239,21 @@ export default class Moonwalk {
|
|
|
227
239
|
* Go through each `data-moonwalk-section`, parse children, add IDs/indexes
|
|
228
240
|
* (if wanted), initialize a new object for each.
|
|
229
241
|
*/
|
|
230
|
-
initializeSections
|
|
242
|
+
initializeSections(container = document.body) {
|
|
231
243
|
const sections = container.querySelectorAll('[data-moonwalk-section]')
|
|
232
244
|
|
|
233
|
-
if (
|
|
245
|
+
if (
|
|
246
|
+
container !== document &&
|
|
247
|
+
!sections.length &&
|
|
248
|
+
container.hasAttribute('data-moonwalk-section')
|
|
249
|
+
) {
|
|
234
250
|
return [this.initializeSection(container)]
|
|
235
251
|
}
|
|
236
252
|
|
|
237
253
|
return Array.from(sections).map(section => this.initializeSection(section))
|
|
238
254
|
}
|
|
239
255
|
|
|
240
|
-
initializeSection
|
|
256
|
+
initializeSection(section) {
|
|
241
257
|
this.parseChildren(section)
|
|
242
258
|
|
|
243
259
|
if (this.opts.uniqueIds) {
|
|
@@ -250,7 +266,7 @@ export default class Moonwalk {
|
|
|
250
266
|
|
|
251
267
|
const timeline = gsap.timeline({
|
|
252
268
|
autoRemoveChildren: false,
|
|
253
|
-
smoothChildTiming: false
|
|
269
|
+
smoothChildTiming: false
|
|
254
270
|
})
|
|
255
271
|
|
|
256
272
|
return {
|
|
@@ -272,7 +288,7 @@ export default class Moonwalk {
|
|
|
272
288
|
* Removes `data-moonwalk` from all elements who already have `data-ll-srcset´
|
|
273
289
|
* Can be used if Moonwalking interferes with custom lazyloading animations
|
|
274
290
|
*/
|
|
275
|
-
clearLazyloads
|
|
291
|
+
clearLazyloads(container = document.body) {
|
|
276
292
|
const srcsets = container.querySelectorAll('[data-ll-srcset][data-moonwalk]')
|
|
277
293
|
Array.from(srcsets).forEach(srcset => srcset.removeAttribute('data-moonwalk'))
|
|
278
294
|
}
|
|
@@ -284,7 +300,7 @@ export default class Moonwalk {
|
|
|
284
300
|
*
|
|
285
301
|
* @param {*} section
|
|
286
302
|
*/
|
|
287
|
-
parseChildren
|
|
303
|
+
parseChildren(section) {
|
|
288
304
|
const mwc = Dom.all(section, '[data-moonwalk-children]')
|
|
289
305
|
|
|
290
306
|
Array.from(mwc).forEach(c => {
|
|
@@ -299,7 +315,7 @@ export default class Moonwalk {
|
|
|
299
315
|
* @param {*} element
|
|
300
316
|
* @param {*} val
|
|
301
317
|
*/
|
|
302
|
-
setAttrs
|
|
318
|
+
setAttrs(element, val) {
|
|
303
319
|
const affectedElements = []
|
|
304
320
|
|
|
305
321
|
Array.prototype.forEach.call(element.children, c => {
|
|
@@ -317,14 +333,16 @@ export default class Moonwalk {
|
|
|
317
333
|
*
|
|
318
334
|
* @param {*} section
|
|
319
335
|
*/
|
|
320
|
-
setupNamesAndStages
|
|
336
|
+
setupNamesAndStages(section) {
|
|
321
337
|
section.el.setAttribute('data-moonwalk-section-ready', '')
|
|
322
|
-
|
|
338
|
+
|
|
323
339
|
if (!section.stage.name && !section.name) {
|
|
324
340
|
return
|
|
325
341
|
}
|
|
326
342
|
|
|
327
|
-
const {
|
|
343
|
+
const {
|
|
344
|
+
opts: { walks }
|
|
345
|
+
} = this
|
|
328
346
|
|
|
329
347
|
if (section.name) {
|
|
330
348
|
// set initial tweens
|
|
@@ -334,15 +352,15 @@ export default class Moonwalk {
|
|
|
334
352
|
section.el.querySelectorAll(sectionWalk.sectionTargets)
|
|
335
353
|
)
|
|
336
354
|
} else {
|
|
337
|
-
section.children = this.orderChildren(
|
|
338
|
-
section.el.children
|
|
339
|
-
)
|
|
355
|
+
section.children = this.orderChildren(section.el.children)
|
|
340
356
|
}
|
|
341
357
|
|
|
342
|
-
const fromTransition = sectionWalk.alphaTween
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
358
|
+
const fromTransition = sectionWalk.alphaTween
|
|
359
|
+
? {
|
|
360
|
+
...sectionWalk.transition.from,
|
|
361
|
+
opacity: 0
|
|
362
|
+
}
|
|
363
|
+
: sectionWalk.transition.from
|
|
346
364
|
|
|
347
365
|
gsap.set(section.children, fromTransition)
|
|
348
366
|
}
|
|
@@ -351,7 +369,10 @@ export default class Moonwalk {
|
|
|
351
369
|
// reset the element to its `from` state.
|
|
352
370
|
const stageTween = walks[section.stage.name]
|
|
353
371
|
if (!stageTween) {
|
|
354
|
-
console.error(
|
|
372
|
+
console.error(
|
|
373
|
+
'==> JUPITER/MOONWALK: MISSING referenced moonwalk stage',
|
|
374
|
+
section.stage.name
|
|
375
|
+
)
|
|
355
376
|
} else {
|
|
356
377
|
gsap.set(section.el, stageTween.transition.from)
|
|
357
378
|
}
|
|
@@ -366,84 +387,88 @@ export default class Moonwalk {
|
|
|
366
387
|
*
|
|
367
388
|
* @param {*} section
|
|
368
389
|
*/
|
|
369
|
-
sectionObserver
|
|
390
|
+
sectionObserver(section) {
|
|
370
391
|
const { opts } = this
|
|
371
392
|
const { walks } = opts
|
|
372
393
|
|
|
373
|
-
return new IntersectionObserver(
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
if (
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
394
|
+
return new IntersectionObserver(
|
|
395
|
+
(entries, self) => {
|
|
396
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
397
|
+
const entry = entries[i]
|
|
398
|
+
|
|
399
|
+
if (entry.isIntersecting) {
|
|
400
|
+
/* stage section */
|
|
401
|
+
if (section.stage.name) {
|
|
402
|
+
if (!section.stage.running) {
|
|
403
|
+
// we have a stage and the section is not running.
|
|
404
|
+
// run stage tween
|
|
405
|
+
const stageTween = walks[section.stage.name]
|
|
406
|
+
|
|
407
|
+
const to = {
|
|
408
|
+
...stageTween.transition.to,
|
|
409
|
+
duration: stageTween.duration
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
section.timeline.to(entry.target, to, 0)
|
|
413
|
+
section.stage.firstTween = true
|
|
388
414
|
}
|
|
389
|
-
|
|
390
|
-
section.timeline.to(entry.target, to, 0)
|
|
391
|
-
section.stage.firstTween = true
|
|
392
415
|
}
|
|
393
|
-
}
|
|
394
416
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
417
|
+
/* named section. stagger reveal children */
|
|
418
|
+
if (section.name) {
|
|
419
|
+
const tween = walks[section.name]
|
|
398
420
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
if (typeof tween.alphaTween === 'object') {
|
|
404
|
-
tween.alphaTween.duration = tween.alphaTween.duration
|
|
405
|
-
? tween.alphaTween.duration : tween.duration
|
|
406
|
-
} else if (tween.alphaTween === true) {
|
|
407
|
-
tween.alphaTween = {
|
|
408
|
-
duration: tween.duration,
|
|
409
|
-
ease: 'sine.in'
|
|
421
|
+
if (!tween) {
|
|
422
|
+
console.error(`==> JUPITER: Walk [${section.name}] not found in config`)
|
|
410
423
|
}
|
|
411
|
-
}
|
|
412
424
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
425
|
+
if (typeof tween.alphaTween === 'object') {
|
|
426
|
+
tween.alphaTween.duration = tween.alphaTween.duration
|
|
427
|
+
? tween.alphaTween.duration
|
|
428
|
+
: tween.duration
|
|
429
|
+
} else if (tween.alphaTween === true) {
|
|
430
|
+
tween.alphaTween = {
|
|
431
|
+
duration: tween.duration,
|
|
432
|
+
ease: 'sine.in'
|
|
433
|
+
}
|
|
417
434
|
}
|
|
418
|
-
}
|
|
419
435
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
)
|
|
436
|
+
if (tween.startDelay) {
|
|
437
|
+
tween.transition.to = {
|
|
438
|
+
...tween.transition.to,
|
|
439
|
+
delay: tween.startDelay
|
|
440
|
+
}
|
|
441
|
+
}
|
|
427
442
|
|
|
428
|
-
if (tween.alphaTween) {
|
|
429
443
|
section.timeline.staggerTo(
|
|
430
444
|
section.children,
|
|
431
|
-
tween.
|
|
432
|
-
|
|
433
|
-
opacity: 1,
|
|
434
|
-
ease: tween.alphaTween.ease,
|
|
435
|
-
delay: tween.startDelay || 0
|
|
436
|
-
},
|
|
445
|
+
tween.duration,
|
|
446
|
+
tween.transition.to,
|
|
437
447
|
tween.interval,
|
|
438
448
|
0
|
|
439
449
|
)
|
|
450
|
+
|
|
451
|
+
if (tween.alphaTween) {
|
|
452
|
+
section.timeline.staggerTo(
|
|
453
|
+
section.children,
|
|
454
|
+
tween.alphaTween.duration,
|
|
455
|
+
{
|
|
456
|
+
opacity: 1,
|
|
457
|
+
ease: tween.alphaTween.ease,
|
|
458
|
+
delay: tween.startDelay || 0
|
|
459
|
+
},
|
|
460
|
+
tween.interval,
|
|
461
|
+
0
|
|
462
|
+
)
|
|
463
|
+
}
|
|
440
464
|
}
|
|
441
|
-
}
|
|
442
465
|
|
|
443
|
-
|
|
466
|
+
self.unobserve(entry.target)
|
|
467
|
+
}
|
|
444
468
|
}
|
|
445
|
-
}
|
|
446
|
-
|
|
469
|
+
},
|
|
470
|
+
{ rootMargin: opts.rootMargin }
|
|
471
|
+
)
|
|
447
472
|
}
|
|
448
473
|
|
|
449
474
|
/**
|
|
@@ -451,10 +476,14 @@ export default class Moonwalk {
|
|
|
451
476
|
*
|
|
452
477
|
* @param {*} children
|
|
453
478
|
*/
|
|
454
|
-
orderChildren
|
|
479
|
+
orderChildren(children) {
|
|
455
480
|
return Array.from(children).sort((a, b) => {
|
|
456
|
-
const orderA = a.getAttribute('data-moonwalk-order')
|
|
457
|
-
|
|
481
|
+
const orderA = a.getAttribute('data-moonwalk-order')
|
|
482
|
+
? parseInt(a.getAttribute('data-moonwalk-order'))
|
|
483
|
+
: null
|
|
484
|
+
const orderB = a.getAttribute('data-moonwalk-order')
|
|
485
|
+
? parseInt(b.getAttribute('data-moonwalk-order'))
|
|
486
|
+
: null
|
|
458
487
|
|
|
459
488
|
if (!orderA && !orderB) {
|
|
460
489
|
return 0
|
|
@@ -472,7 +501,7 @@ export default class Moonwalk {
|
|
|
472
501
|
})
|
|
473
502
|
}
|
|
474
503
|
|
|
475
|
-
onReady
|
|
504
|
+
onReady() {
|
|
476
505
|
if (this.opts.initialDelay) {
|
|
477
506
|
setTimeout(() => {
|
|
478
507
|
this.ready()
|
|
@@ -486,7 +515,7 @@ export default class Moonwalk {
|
|
|
486
515
|
* Called on `APPLICATION_READY` event, if `config.fireOnReady`.
|
|
487
516
|
* Otherwise must be triggered manually
|
|
488
517
|
*/
|
|
489
|
-
ready
|
|
518
|
+
ready() {
|
|
490
519
|
const { opts } = this
|
|
491
520
|
|
|
492
521
|
for (let idx = 0; idx < this.runs.length; idx += 1) {
|
|
@@ -537,19 +566,22 @@ export default class Moonwalk {
|
|
|
537
566
|
* @param {*} run
|
|
538
567
|
* @param {*} rootMargin
|
|
539
568
|
*/
|
|
540
|
-
runObserver
|
|
541
|
-
return new IntersectionObserver(
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
569
|
+
runObserver(run, rootMargin) {
|
|
570
|
+
return new IntersectionObserver(
|
|
571
|
+
(entries, self) => {
|
|
572
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
573
|
+
const entry = entries[i]
|
|
574
|
+
if (entry.isIntersecting) {
|
|
575
|
+
run.callback(entry.target)
|
|
576
|
+
self.unobserve(entry.target)
|
|
577
|
+
}
|
|
547
578
|
}
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
rootMargin,
|
|
582
|
+
threshold: run.threshold
|
|
548
583
|
}
|
|
549
|
-
|
|
550
|
-
rootMargin,
|
|
551
|
-
threshold: run.threshold
|
|
552
|
-
})
|
|
584
|
+
)
|
|
553
585
|
}
|
|
554
586
|
|
|
555
587
|
/**
|
|
@@ -559,95 +591,85 @@ export default class Moonwalk {
|
|
|
559
591
|
* @param {*} section
|
|
560
592
|
* @param {*} rootMargin
|
|
561
593
|
*/
|
|
562
|
-
observer
|
|
594
|
+
observer(section, rootMargin) {
|
|
563
595
|
const { opts } = this
|
|
564
596
|
|
|
565
|
-
return new IntersectionObserver(
|
|
566
|
-
|
|
567
|
-
|
|
597
|
+
return new IntersectionObserver(
|
|
598
|
+
(entries, self) => {
|
|
599
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
600
|
+
const entry = entries[i]
|
|
568
601
|
|
|
569
|
-
|
|
570
|
-
|
|
602
|
+
if (entry.isIntersecting || entry.intersectionRatio > 0) {
|
|
603
|
+
section.running = true
|
|
571
604
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
605
|
+
if (entry.target.dataset.moonwalkId) {
|
|
606
|
+
console.debug('-- intersecting', entry.target.dataset.moonwalkId)
|
|
607
|
+
}
|
|
575
608
|
|
|
576
|
-
|
|
577
|
-
|
|
609
|
+
const walkName = entry.target.getAttribute('data-moonwalk')
|
|
610
|
+
const cfg = !walkName.length ? opts.walks.default : opts.walks[walkName]
|
|
578
611
|
|
|
579
|
-
|
|
580
|
-
duration,
|
|
581
|
-
transition,
|
|
582
|
-
interval,
|
|
583
|
-
startDelay
|
|
584
|
-
} = cfg
|
|
612
|
+
const { duration, transition, interval, startDelay } = cfg
|
|
585
613
|
|
|
586
|
-
|
|
587
|
-
|
|
614
|
+
let { alphaTween } = cfg
|
|
615
|
+
let overlap = (duration - interval) * -1 // flip it
|
|
588
616
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
617
|
+
if (section.stage.firstTween) {
|
|
618
|
+
overlap = 0
|
|
619
|
+
section.stage.firstTween = false
|
|
620
|
+
}
|
|
593
621
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
622
|
+
if (typeof alphaTween === 'object' && alphaTween !== null) {
|
|
623
|
+
alphaTween.duration = alphaTween.duration ? alphaTween.duration : duration
|
|
624
|
+
} else if (alphaTween === true) {
|
|
625
|
+
alphaTween = {
|
|
626
|
+
duration,
|
|
627
|
+
ease: 'sine.in'
|
|
628
|
+
}
|
|
600
629
|
}
|
|
601
|
-
}
|
|
602
630
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
const tweenFn = () => {
|
|
606
|
-
tween(
|
|
607
|
-
section,
|
|
608
|
-
entry.target,
|
|
609
|
-
duration,
|
|
610
|
-
interval,
|
|
611
|
-
transition,
|
|
612
|
-
overlap,
|
|
613
|
-
alphaTween
|
|
614
|
-
)
|
|
615
|
-
}
|
|
631
|
+
const tween = transition ? this.tweenJS : this.tweenCSS
|
|
616
632
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
gsap.delayedCall(startDelay, tweenFn)
|
|
620
|
-
} else {
|
|
621
|
-
tweenFn()
|
|
633
|
+
const tweenFn = () => {
|
|
634
|
+
tween(section, entry.target, duration, interval, transition, overlap, alphaTween)
|
|
622
635
|
}
|
|
623
|
-
}
|
|
624
636
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
} else {
|
|
629
|
-
if (entry.target.hasAttribute('data-placeholder')) {
|
|
630
|
-
// if the moonwalked element has data-placeholder, we don't want to wait
|
|
631
|
-
// for the image to load before tweening
|
|
632
|
-
wrappedTweenFn()
|
|
633
|
-
} else {
|
|
634
|
-
const imagesInEntry = entry.target.querySelectorAll('img')
|
|
635
|
-
if (imagesInEntry.length) {
|
|
636
|
-
// entry has children elements that are images
|
|
637
|
-
imagesAreLoaded(imagesInEntry).then(() => wrappedTweenFn())
|
|
637
|
+
const wrappedTweenFn = () => {
|
|
638
|
+
if (startDelay) {
|
|
639
|
+
gsap.delayedCall(startDelay, tweenFn)
|
|
638
640
|
} else {
|
|
639
|
-
|
|
641
|
+
tweenFn()
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
if (entry.target.tagName === 'IMG') {
|
|
646
|
+
// ensure image is loaded before we tween
|
|
647
|
+
imageIsLoaded(entry.target).then(() => wrappedTweenFn())
|
|
648
|
+
} else {
|
|
649
|
+
if (entry.target.hasAttribute('data-placeholder')) {
|
|
650
|
+
// if the moonwalked element has data-placeholder, we don't want to wait
|
|
651
|
+
// for the image to load before tweening
|
|
640
652
|
wrappedTweenFn()
|
|
653
|
+
} else {
|
|
654
|
+
const imagesInEntry = entry.target.querySelectorAll('img')
|
|
655
|
+
if (imagesInEntry.length) {
|
|
656
|
+
// entry has children elements that are images
|
|
657
|
+
imagesAreLoaded(imagesInEntry).then(() => wrappedTweenFn())
|
|
658
|
+
} else {
|
|
659
|
+
// regular entry, just tween it
|
|
660
|
+
wrappedTweenFn()
|
|
661
|
+
}
|
|
641
662
|
}
|
|
642
663
|
}
|
|
664
|
+
self.unobserve(entry.target)
|
|
643
665
|
}
|
|
644
|
-
self.unobserve(entry.target)
|
|
645
666
|
}
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
rootMargin,
|
|
670
|
+
threshold: opts.threshold
|
|
646
671
|
}
|
|
647
|
-
|
|
648
|
-
rootMargin,
|
|
649
|
-
threshold: opts.threshold
|
|
650
|
-
})
|
|
672
|
+
)
|
|
651
673
|
}
|
|
652
674
|
|
|
653
675
|
/**
|
|
@@ -660,7 +682,15 @@ export default class Moonwalk {
|
|
|
660
682
|
* @param {*} tweenOverlap
|
|
661
683
|
* @param {*} alphaTween
|
|
662
684
|
*/
|
|
663
|
-
tweenJS
|
|
685
|
+
tweenJS(
|
|
686
|
+
section,
|
|
687
|
+
target,
|
|
688
|
+
tweenDuration,
|
|
689
|
+
tweenInterval,
|
|
690
|
+
tweenTransition,
|
|
691
|
+
tweenOverlap,
|
|
692
|
+
alphaTween
|
|
693
|
+
) {
|
|
664
694
|
let tweenPosition
|
|
665
695
|
const startingPoint = tweenDuration - tweenOverlap
|
|
666
696
|
|
|
@@ -669,16 +699,24 @@ export default class Moonwalk {
|
|
|
669
699
|
}
|
|
670
700
|
|
|
671
701
|
if (section.timeline.isActive() && section.timeline.recent()) {
|
|
672
|
-
|
|
702
|
+
const currentTime = section.timeline.time()
|
|
703
|
+
const lastTweenTime = section.timeline.recent().time()
|
|
704
|
+
const lastTweenEndTime = section.timeline.recent().endTime()
|
|
705
|
+
if (lastTweenTime > startingPoint) {
|
|
673
706
|
/* We're late for this tween if it was supposed to be sequential,
|
|
674
707
|
so insert at current time in timeline instead */
|
|
675
708
|
tweenPosition = () => section.timeline.time()
|
|
676
709
|
} else {
|
|
677
|
-
|
|
678
|
-
|
|
710
|
+
if (currentTime + tweenOverlap * -1 < lastTweenEndTime) {
|
|
711
|
+
/* Still time, add as normal overlap at the end */
|
|
712
|
+
tweenPosition = () => `>${tweenOverlap}`
|
|
713
|
+
} else {
|
|
714
|
+
/* Won't make it */
|
|
715
|
+
tweenPosition = () => section.timeline.time()
|
|
716
|
+
}
|
|
679
717
|
}
|
|
680
718
|
} else {
|
|
681
|
-
tweenPosition = () => '
|
|
719
|
+
tweenPosition = () => '>'
|
|
682
720
|
}
|
|
683
721
|
|
|
684
722
|
gsap.set(target, tweenTransition.from)
|
|
@@ -692,12 +730,16 @@ export default class Moonwalk {
|
|
|
692
730
|
section.timeline.to(target, toTransition, tweenPosition())
|
|
693
731
|
|
|
694
732
|
if (alphaTween) {
|
|
695
|
-
section.timeline.to(
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
733
|
+
section.timeline.to(
|
|
734
|
+
target,
|
|
735
|
+
{
|
|
736
|
+
duration: alphaTween.duration,
|
|
737
|
+
opacity: 1,
|
|
738
|
+
ease: alphaTween.ease,
|
|
739
|
+
delay: alphaTween.delay ? alphaTween.delay : 0
|
|
740
|
+
},
|
|
741
|
+
'<'
|
|
742
|
+
)
|
|
701
743
|
}
|
|
702
744
|
}
|
|
703
745
|
|
|
@@ -710,35 +752,46 @@ export default class Moonwalk {
|
|
|
710
752
|
* @param {*} transition
|
|
711
753
|
* @param {*} overlap
|
|
712
754
|
*/
|
|
713
|
-
tweenCSS
|
|
755
|
+
tweenCSS(section, target, tweenDuration, tweenInterval, tweenTransition, tweenOverlap) {
|
|
714
756
|
let tweenPosition
|
|
715
|
-
const startingPoint = tweenDuration -
|
|
716
|
-
|
|
757
|
+
const startingPoint = tweenDuration - tweenOverlap * -1
|
|
758
|
+
|
|
717
759
|
if (Dom.hasAttribute(target, 'data-moonwalked')) {
|
|
718
760
|
return
|
|
719
761
|
}
|
|
720
762
|
|
|
721
763
|
if (section.timeline.isActive() && section.timeline.recent()) {
|
|
722
|
-
|
|
764
|
+
const currentTime = section.timeline.time()
|
|
765
|
+
const lastTweenTime = section.timeline.recent().time()
|
|
766
|
+
const lastTweenEndTime = section.timeline.recent().endTime()
|
|
767
|
+
if (lastTweenTime > startingPoint) {
|
|
723
768
|
/* We're late for this tween if it was supposed to be sequential,
|
|
724
769
|
so insert at current time in timeline instead */
|
|
725
770
|
tweenPosition = () => section.timeline.time()
|
|
726
771
|
} else {
|
|
727
|
-
|
|
728
|
-
|
|
772
|
+
if (currentTime + tweenOverlap * -1 < lastTweenEndTime) {
|
|
773
|
+
/* Still time, add as normal overlap at the end */
|
|
774
|
+
tweenPosition = () => `>${tweenOverlap}`
|
|
775
|
+
} else {
|
|
776
|
+
/* Won't make it */
|
|
777
|
+
tweenPosition = () => section.timeline.time()
|
|
778
|
+
}
|
|
729
779
|
}
|
|
730
780
|
} else {
|
|
731
|
-
tweenPosition = () => '
|
|
781
|
+
tweenPosition = () => '>'
|
|
732
782
|
}
|
|
733
783
|
|
|
734
|
-
section.timeline
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
784
|
+
section.timeline
|
|
785
|
+
.to(
|
|
786
|
+
target,
|
|
787
|
+
{
|
|
788
|
+
css: {
|
|
789
|
+
className: target.className ? `${target.className} moonwalked` : 'moonwalked'
|
|
790
|
+
},
|
|
791
|
+
duration: tweenDuration
|
|
738
792
|
},
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
).call(() => target.setAttribute('data-moonwalked', ''), null, '>')
|
|
793
|
+
tweenPosition()
|
|
794
|
+
)
|
|
795
|
+
.call(() => target.setAttribute('data-moonwalked', ''), null, '>')
|
|
743
796
|
}
|
|
744
797
|
}
|