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
master
Thomas Brierley 2017-01-31 23:50:07 +00:00 committed by Dmitry Baranovskiy
parent 768ddb1b77
commit 230396fd68
1 changed files with 16 additions and 4 deletions

View File

@ -19,8 +19,10 @@ var mina = (function (eve) {
window.oRequestAnimationFrame || window.oRequestAnimationFrame ||
window.msRequestAnimationFrame || window.msRequestAnimationFrame ||
function (callback) { function (callback) {
setTimeout(callback, 16); setTimeout(callback, 16, new Date().getTime());
return true;
}, },
requestID,
isArray = Array.isArray || function (a) { isArray = Array.isArray || function (a) {
return a instanceof Array || return a instanceof Array ||
Object.prototype.toString.call(a) == "[object Array]"; Object.prototype.toString.call(a) == "[object Array]";
@ -94,6 +96,7 @@ var mina = (function (eve) {
a.b = a.get() - a.pdif; a.b = a.get() - a.pdif;
delete a.pdif; delete a.pdif;
animations[a.id] = a; animations[a.id] = a;
frame();
}, },
update = function () { update = function () {
var a = this, var a = this,
@ -109,7 +112,16 @@ var mina = (function (eve) {
} }
a.set(res); 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; var len = 0;
for (var i in animations) if (animations.hasOwnProperty(i)) { for (var i in animations) if (animations.hasOwnProperty(i)) {
var a = animations[i], var a = animations[i],
@ -129,7 +141,7 @@ var mina = (function (eve) {
} }
a.update(); a.update();
} }
len && requestAnimFrame(frame); requestID = len ? requestAnimFrame(frame) : false;
}, },
/*\ /*\
* mina * mina
@ -193,7 +205,7 @@ var mina = (function (eve) {
break; break;
} }
} }
len == 1 && requestAnimFrame(frame); len == 1 && frame();
return anim; return anim;
}; };
/*\ /*\