MCPcopy
hub / github.com/greensock/GSAP / _postAddChecks

Function _postAddChecks

esm/gsap-core.js:403–430  ·  view source on GitHub ↗
(timeline, child)

Source from the content-addressed store, hash-verified

401},
402*/
403_postAddChecks = function _postAddChecks(timeline, child) {
404 var t;
405
406 if (child._time || !child._dur && child._initted || child._start < timeline._time && (child._dur || !child.add)) {
407 // in case, for example, the _start is moved on a tween that has already rendered, or if it's being inserted into a timeline BEFORE where the playhead is currently. Imagine it's at its end state, then the startTime is moved WAY later (after the end of this timeline), it should render at its beginning. Special case: if it's a timeline (has .add() method) and no duration, we can skip rendering because the user may be populating it AFTER adding it to a parent timeline (unconventional, but possible, and we wouldn't want it to get removed if the parent's autoRemoveChildren is true).
408 t = _parentToChildTotalTime(timeline.rawTime(), child);
409
410 if (!child._dur || _clamp(0, child.totalDuration(), t) - child._tTime > _tinyNum) {
411 child.render(t, true);
412 }
413 } //if the timeline has already ended but the inserted tween/timeline extends the duration, we should enable this timeline again so that it renders properly. We should also align the playhead with the parent timeline's when appropriate.
414
415
416 if (_uncache(timeline, child)._dp && timeline._initted && timeline._time >= timeline._dur && timeline._ts) {
417 //in case any of the ancestors had completed but should now be enabled...
418 if (timeline._dur < timeline.duration()) {
419 t = timeline;
420
421 while (t._dp) {
422 t.rawTime() >= 0 && t.totalTime(t._tTime); //moves the timeline (shifts its startTime) if necessary, and also enables it. If it's currently zero, though, it may not be scheduled to render until later so there's no need to force it to align with the current playhead position. Only move to catch up with the playhead.
423
424 t = t._dp;
425 }
426 }
427
428 timeline._zTime = -_tinyNum; // helps ensure that the next render() will be forced (crossingStart = true in render()), even if the duration hasn't changed (we're adding a child which would need to get rendered). Definitely an edge case. Note: we MUST do this AFTER the loop above where the totalTime() might trigger a render() because this _addToTimeline() method gets called from the Animation constructor, BEFORE tweens even record their targets, etc. so we wouldn't want things to get triggered in the wrong order.
429 }
430},
431 _addToTimeline = function _addToTimeline(timeline, child, position, skipChecks) {
432 child.parent && _removeFromParent(child);
433 child._start = _roundPrecise((_isNumber(position) ? position : position || timeline !== _globalTimeline ? _parsePosition(timeline, position, child) : timeline._time) + child._delay);

Callers 2

_addToTimelineFunction · 0.70
gsap-core.jsFile · 0.70

Calls 8

rawTimeMethod · 0.80
durationMethod · 0.80
_parentToChildTotalTimeFunction · 0.70
_clampFunction · 0.70
_uncacheFunction · 0.70
totalDurationMethod · 0.45
renderMethod · 0.45
totalTimeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…