|
9 | 9 | * |
10 | 10 | * Since : 2010-05-16 |
11 | 11 | * Update : 2021-8-17 |
12 | | - * Version: 2.1 |
| 12 | + * Version: 2.1.0 |
13 | 13 | */ |
14 | 14 |
|
15 | 15 | (function(window) { |
|
32 | 32 |
|
33 | 33 | // queue configs |
34 | 34 | this.queConfigs = []; |
35 | | - // current running queue config |
36 | | - this.queConfig = null; |
| 35 | + // whether to dequeue the queue action to play |
| 36 | + this.isDequeue = true; |
37 | 37 | // current running actions include shift queue and nonqueued |
38 | 38 | this.curActions = []; |
39 | 39 | // whether animation is playing |
|
58 | 58 | /** |
59 | 59 | * Add animation with config to update array. |
60 | 60 | * |
61 | | - * @param {Object} animation |
| 61 | + * @param {Object} anim |
62 | 62 | * @param {Object} config |
63 | 63 | */ |
64 | 64 | addAnim: function(anim, config) { |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 |
|
| 120 | + if (config.isQueue) { |
| 121 | + // into queue waiting to play |
| 122 | + anim.queConfigs.push(config); |
| 123 | + |
| 124 | + if (anim.isDequeue) { |
| 125 | + this.dequeueAction(anim); |
| 126 | + } |
| 127 | + } else { |
| 128 | + // into current to play |
| 129 | + anim.curActions.push(this.createAction(anim, config)); |
| 130 | + } |
| 131 | + |
120 | 132 | if (anim.isPlaying === false) { |
121 | 133 | this.anims.push(anim); |
122 | 134 | anim.isPlaying = true; |
123 | | - } |
124 | | - |
125 | | - config.isQueue ? |
126 | | - // into queue waiting to run |
127 | | - anim.queConfigs.push(config) : |
128 | | - // add action into curActions |
129 | | - anim.curActions.push(this.createAction(anim, config)); |
| 135 | + } |
130 | 136 | }, |
131 | 137 |
|
132 | 138 | /** |
|
239 | 245 | * |
240 | 246 | * one action to one config. |
241 | 247 | * |
242 | | - * @param {Object} animation |
| 248 | + * @param {Object} anim |
243 | 249 | * @param {Object} config |
244 | | - * @return {Object} action |
245 | 250 | */ |
246 | 251 | createAction: function(anim, config) { |
247 | 252 | var |
|
264 | 269 | /** |
265 | 270 | * Create acton steps by config steps and els current style. |
266 | 271 | * |
267 | | - * @param {Object} animation |
| 272 | + * @param {Object} anim |
268 | 273 | * @param {Object} action |
269 | 274 | */ |
270 | 275 | createSteps: function(anim, action) { |
|
387 | 392 | */ |
388 | 393 | update: function(deltaTime) { |
389 | 394 | var |
390 | | - anim, queConfigs, curActions, len, i; |
| 395 | + anim, curActions, len, i; |
391 | 396 |
|
392 | 397 | for (i = 0, len = this.anims.length; i < len; ++i) { |
393 | 398 | anim = this.anims[i]; |
394 | | - queConfigs = anim.queConfigs; |
395 | 399 | curActions = anim.curActions; |
396 | 400 |
|
397 | | - if (anim.queConfig === null && queConfigs.length !== 0) { |
398 | | - // get one config from queue |
399 | | - anim.queConfig = queConfigs.shift(); |
400 | | - // add queue action into current runnings |
401 | | - curActions.push(this.createAction(anim, anim.queConfig)); |
402 | | - } |
403 | | - |
404 | 401 | if (curActions.length > 0) { |
405 | 402 | this.doActions(anim, curActions, deltaTime); |
406 | 403 | } else { |
|
416 | 413 |
|
417 | 414 | return true; |
418 | 415 | }, |
| 416 | + |
| 417 | + /** |
| 418 | + * Dequeue one action to play. |
| 419 | + * |
| 420 | + * @param {Object} anim |
| 421 | + */ |
| 422 | + dequeueAction(anim) { |
| 423 | + var |
| 424 | + queConfigs = anim.queConfigs; |
| 425 | + |
| 426 | + if (queConfigs.length !== 0) { |
| 427 | + // get one config from queue into curActions |
| 428 | + anim.curActions.push(this.createAction(anim, queConfigs.shift())); |
| 429 | + } |
| 430 | + |
| 431 | + anim.isDequeue = false; |
| 432 | + }, |
419 | 433 |
|
420 | 434 | /** |
421 | 435 | * Do animation current actions. |
422 | 436 | * |
423 | | - * @param {Object} animation |
| 437 | + * @param {Object} anim |
424 | 438 | * @param {Array} actions |
425 | 439 | * @param {Number} deltaTime |
426 | 440 | */ |
|
451 | 465 | time = 1.0; |
452 | 466 | actions.splice(j--, 1); |
453 | 467 | --aLen; |
454 | | - |
455 | | - // check whether the action is in queue |
456 | | - if (anim.queConfig === action.config) { |
457 | | - anim.queConfig = null; |
458 | | - } |
459 | | - |
460 | 468 | // action is complete |
461 | 469 | completes.push(action.config); |
462 | 470 | } |
|
491 | 499 | for (k = 0, cLen = completes.length; k < cLen; ++k) { |
492 | 500 | config = completes[k]; |
493 | 501 |
|
| 502 | + if (config.isQueue) { |
| 503 | + // need to dequeue action when queue action is complete |
| 504 | + anim.isDequeue = true; |
| 505 | + } |
| 506 | + |
494 | 507 | if (config.complete !== null) { |
495 | 508 | // do action callback |
496 | 509 | config.complete.apply(anim, config.args); |
|
511 | 524 | } |
512 | 525 | } |
513 | 526 | } |
| 527 | + |
| 528 | + if (anim.isDequeue) |
| 529 | + { |
| 530 | + this.dequeueAction(anim); |
| 531 | + } |
514 | 532 | }, |
515 | 533 |
|
516 | 534 | /** |
|
610 | 628 | * Animate with config. |
611 | 629 | * |
612 | 630 | * @param {Object} animStyle |
613 | | - * @return {Object} animation |
| 631 | + * @return {Object} anim |
614 | 632 | */ |
615 | 633 | animate: function(animStyle) { |
616 | 634 | var |
|
0 commit comments