Skip to content

Commit 7a002e7

Browse files
authored
fix: change play once from being per timeline, to per trigger (#11)
Co-authored-by: bfintal@gmail.com <>
1 parent fa0fb00 commit 7a002e7

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/frontend/scripts/class-timeline.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export class Timeline {
2424
this._resetAtStart = !! timelineData.reset
2525
this._onceOnly = !! timelineData.onceOnly
2626
this._actionStarts = {}
27+
28+
// Used to track if the timeline is played per each trigger.
29+
this.timelineData._playedTriggers = new WeakSet()
2730
}
2831

2932
this._targets = []
@@ -40,19 +43,19 @@ export class Timeline {
4043

4144
createInstance( options ) {
4245
// If triggered only once, then we don't create anymore animations.
43-
// We reference timelineData._played here so that it persists across other timeline instances.
46+
const currentTrigger = this.interaction.getCurrentTrigger()
4447
if ( this.getRunner().isFrontend ) {
45-
if ( this.timelineData.onceOnly && this.timelineData._played ) {
48+
if ( this.timelineData.onceOnly && this.timelineData._playedTriggers.has( currentTrigger ) ) {
4649
return null
4750
}
4851
}
4952

53+
this.timelineData._playedTriggers.add( currentTrigger )
54+
5055
// We have to empty the promises here because we are creating a new timeline.
5156
// This is to prevent the promises from the previous timeline from affecting the new one.
5257
this._funcPromises = {}
5358

54-
this.timelineData._played = true
55-
5659
const propsToPass = {}
5760
if ( this.type === 'percentage' ) {
5861
propsToPass.duration = 100 // 100% so it's easier to compute the actions later.

0 commit comments

Comments
 (0)