@@ -6,6 +6,7 @@ var GetNewValue = require('./GetNewValue');
66var GetTargets = require ( './GetTargets' ) ;
77var GetTweens = require ( './GetTweens' ) ;
88var GetValue = require ( '../../utils/object/GetValue' ) ;
9+ var GetAdvancedValue = require ( '../../utils/object/GetAdvancedValue' ) ;
910var Timeline = require ( '../timeline/Timeline' ) ;
1011var TweenBuilder = require ( './TweenBuilder' ) ;
1112
@@ -22,8 +23,20 @@ var TimelineBuilder = function (manager, config)
2223
2324 defaults . targets = GetTargets ( config ) ;
2425
26+ // totalDuration: If specified each tween in the Timeline is given an equal portion of the totalDuration
27+
28+ var totalDuration = GetAdvancedValue ( config , 'totalDuration' , 0 ) ;
29+
30+ if ( totalDuration > 0 )
31+ {
32+ defaults . duration = Math . floor ( totalDuration / tweens . length ) ;
33+ }
34+ else
35+ {
36+ defaults . duration = GetNewValue ( config , 'duration' , defaults . duration ) ;
37+ }
38+
2539 defaults . delay = GetNewValue ( config , 'delay' , defaults . delay ) ;
26- defaults . duration = GetNewValue ( config , 'duration' , defaults . duration ) ;
2740 defaults . easeParams = GetValue ( config , 'easeParams' , defaults . easeParams ) ;
2841 defaults . ease = GetEaseFunction ( GetValue ( config , 'ease' , defaults . ease ) , defaults . easeParams ) ;
2942 defaults . hold = GetNewValue ( config , 'hold' , defaults . hold ) ;
@@ -42,6 +55,73 @@ var TimelineBuilder = function (manager, config)
4255 timeline . queue ( TweenBuilder ( manager , tweens [ i ] , defaults ) ) ;
4356 }
4457
58+ timeline . completeDelay = GetAdvancedValue ( config , 'completeDelay' , 0 ) ;
59+ timeline . loop = Math . round ( GetAdvancedValue ( config , 'loop' , 0 ) ) ;
60+ timeline . loopDelay = Math . round ( GetAdvancedValue ( config , 'loopDelay' , 0 ) ) ;
61+ timeline . paused = GetBoolean ( config , 'paused' , false ) ;
62+ timeline . useFrames = GetBoolean ( config , 'useFrames' , false ) ;
63+
64+ // Callbacks
65+
66+ var scope = GetValue ( config , 'callbackScope' , timeline ) ;
67+
68+ var timelineArray = [ timeline ] ;
69+
70+ var onStart = GetValue ( config , 'onStart' , false ) ;
71+
72+ // The Start of the Timeline
73+ if ( onStart )
74+ {
75+ var onStartScope = GetValue ( config , 'onStartScope' , scope ) ;
76+ var onStartParams = GetValue ( config , 'onStartParams' , [ ] ) ;
77+
78+ timeline . setCallback ( 'onStart' , onStart , timelineArray . concat ( onStartParams ) , onStartScope ) ;
79+ }
80+
81+ var onUpdate = GetValue ( config , 'onUpdate' , false ) ;
82+
83+ // Every time the Timeline updates (regardless which Tweens are running)
84+ if ( onUpdate )
85+ {
86+ var onUpdateScope = GetValue ( config , 'onUpdateScope' , scope ) ;
87+ var onUpdateParams = GetValue ( config , 'onUpdateParams' , [ ] ) ;
88+
89+ timeline . setCallback ( 'onUpdate' , onUpdate , timelineArray . concat ( onUpdateParams ) , onUpdateScope ) ;
90+ }
91+
92+ var onLoop = GetValue ( config , 'onLoop' , false ) ;
93+
94+ // Called when the whole Timeline loops
95+ if ( onLoop )
96+ {
97+ var onLoopScope = GetValue ( config , 'onLoopScope' , scope ) ;
98+ var onLoopParams = GetValue ( config , 'onLoopParams' , [ ] ) ;
99+
100+ timeline . setCallback ( 'onLoop' , onLoop , timelineArray . concat ( onLoopParams ) , onLoopScope ) ;
101+ }
102+
103+ var onYoyo = GetValue ( config , 'onYoyo' , false ) ;
104+
105+ // Called when a Timeline yoyos
106+ if ( onYoyo )
107+ {
108+ var onYoyoScope = GetValue ( config , 'onYoyoScope' , scope ) ;
109+ var onYoyoParams = GetValue ( config , 'onYoyoParams' , [ ] ) ;
110+
111+ timeline . setCallback ( 'onYoyo' , onYoyo , timelineArray . concat ( null , onYoyoParams ) , onYoyoScope ) ;
112+ }
113+
114+ var onComplete = GetValue ( config , 'onComplete' , false ) ;
115+
116+ // Called when the Timeline completes, after the completeDelay, etc.
117+ if ( onComplete )
118+ {
119+ var onCompleteScope = GetValue ( config , 'onCompleteScope' , scope ) ;
120+ var onCompleteParams = GetValue ( config , 'onCompleteParams' , [ ] ) ;
121+
122+ timeline . setCallback ( 'onComplete' , onComplete , timelineArray . concat ( onCompleteParams ) , onCompleteScope ) ;
123+ }
124+
45125 return timeline ;
46126} ;
47127
0 commit comments