From 230396fd680f3a49cd1fd11198a87f1e388edda8 Mon Sep 17 00:00:00 2001 From: Thomas Brierley Date: Tue, 31 Jan 2017 23:50:07 +0000 Subject: [PATCH] Fix mina frame loop exit on resume (#499) Invoke frame function from resume to restart animation loop when it has previously exited after running out of animations. Add checks to frame function and move handling of animation frame requests internally to prevent simultaneous requests / loops. Fixes adobe-webplatform/Snap.svg#496 --- src/mina.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/mina.js b/src/mina.js index f36361b..8b967a9 100644 --- a/src/mina.js +++ b/src/mina.js @@ -19,8 +19,10 @@ var mina = (function (eve) { window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { - setTimeout(callback, 16); + setTimeout(callback, 16, new Date().getTime()); + return true; }, + requestID, isArray = Array.isArray || function (a) { return a instanceof Array || Object.prototype.toString.call(a) == "[object Array]"; @@ -94,6 +96,7 @@ var mina = (function (eve) { a.b = a.get() - a.pdif; delete a.pdif; animations[a.id] = a; + frame(); }, update = function () { var a = this, @@ -109,7 +112,16 @@ var mina = (function (eve) { } a.set(res); }, - frame = function () { + frame = function (timeStamp) { + // Manual invokation? + if (!timeStamp) { + // Frame loop stopped? + if (!requestID) { + // Start frame loop... + requestID = requestAnimFrame(frame); + } + return; + } var len = 0; for (var i in animations) if (animations.hasOwnProperty(i)) { var a = animations[i], @@ -129,7 +141,7 @@ var mina = (function (eve) { } a.update(); } - len && requestAnimFrame(frame); + requestID = len ? requestAnimFrame(frame) : false; }, /*\ * mina @@ -193,7 +205,7 @@ var mina = (function (eve) { break; } } - len == 1 && requestAnimFrame(frame); + len == 1 && frame(); return anim; }; /*\