Only setInterval once to animate the loading icon (fixes #2888)

(On Chrome, at least,) window.onload() is called once by hand, and once
by the browser. This ends up calling setInterval() twice. When
stopAnimation() is called later, only the second interval is cleared; so
the first one keeps firing forever. Mostly harmless but unnecessary.

Only the first hunk of this patch is really needed, but making
startAnimation() / stopAnimation() idempotent can't hurt.
This commit is contained in:
Will Thompson 2016-02-25 10:57:04 +00:00 committed by j
parent fd2c69a5b7
commit 7d99950942

View file

@ -188,10 +188,14 @@ appPanel
loadingScreen.appendChild(images.loadingIcon);
// FF3.6 document.body can be undefined here
var onloadCalled = false;
window.onload = function() {
if (!onloadCalled) {
onloadCalled = true;
document.body.style.margin = 0;
document.body.appendChild(loadingScreen);
startAnimation();
}
};
// IE8 does not call onload if already loaded before set
document.body && window.onload();
@ -556,6 +560,10 @@ appPanel
}
function startAnimation() {
if (animationInterval !== undefined) {
return;
}
var css, deg = 0, loadingIcon = document.getElementById('loadingIcon'),
previousTime = +new Date();
animationInterval = setInterval(function() {
@ -573,7 +581,10 @@ appPanel
}
function stopAnimation() {
if (animationInterval !== undefined) {
clearInterval(animationInterval);
animationInterval = undefined;
}
}
}());