From 2b9328164156405621206b354e9a90193daa4153 Mon Sep 17 00:00:00 2001 From: Meiguro Date: Sat, 27 Feb 2016 17:33:03 -0800 Subject: [PATCH] Fix Element animate to properly queue subsequent animations (Addresses #123) --- src/js/ui/element.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/js/ui/element.js b/src/js/ui/element.js index fb469b71..95195ad5 100644 --- a/src/js/ui/element.js +++ b/src/js/ui/element.js @@ -80,14 +80,12 @@ StageElement.prototype.animate = function(field, value, duration) { duration = value; } var animateDef = myutil.toObject(field, value); - function animate() { + this.queue(function() { this._animate(animateDef, duration); util2.copy(animateDef, this.state); - } - if (this._queue.length === 0) { - animate.call(this); - } else { - this.queue(animate); + }); + if (!this.state.animating) { + this.dequeue(); } return this; }; @@ -98,8 +96,12 @@ StageElement.prototype.queue = function(callback) { StageElement.prototype.dequeue = function() { var callback = this._queue.shift(); - if (!callback) { return; } - callback.call(this, this.dequeue.bind(this)); + if (callback) { + this.state.animating = true; + callback.call(this, this.dequeue.bind(this)); + } else { + this.state.animating = false; + } }; StageElement.emitAnimateDone = function(id) {