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:
parent
fd2c69a5b7
commit
7d99950942
1 changed files with 15 additions and 4 deletions
|
@ -188,10 +188,14 @@ appPanel
|
||||||
loadingScreen.appendChild(images.loadingIcon);
|
loadingScreen.appendChild(images.loadingIcon);
|
||||||
|
|
||||||
// FF3.6 document.body can be undefined here
|
// FF3.6 document.body can be undefined here
|
||||||
|
var onloadCalled = false;
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
document.body.style.margin = 0;
|
if (!onloadCalled) {
|
||||||
document.body.appendChild(loadingScreen);
|
onloadCalled = true;
|
||||||
startAnimation();
|
document.body.style.margin = 0;
|
||||||
|
document.body.appendChild(loadingScreen);
|
||||||
|
startAnimation();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
// IE8 does not call onload if already loaded before set
|
// IE8 does not call onload if already loaded before set
|
||||||
document.body && window.onload();
|
document.body && window.onload();
|
||||||
|
@ -556,6 +560,10 @@ appPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
function startAnimation() {
|
function startAnimation() {
|
||||||
|
if (animationInterval !== undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var css, deg = 0, loadingIcon = document.getElementById('loadingIcon'),
|
var css, deg = 0, loadingIcon = document.getElementById('loadingIcon'),
|
||||||
previousTime = +new Date();
|
previousTime = +new Date();
|
||||||
animationInterval = setInterval(function() {
|
animationInterval = setInterval(function() {
|
||||||
|
@ -573,7 +581,10 @@ appPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopAnimation() {
|
function stopAnimation() {
|
||||||
clearInterval(animationInterval);
|
if (animationInterval !== undefined) {
|
||||||
|
clearInterval(animationInterval);
|
||||||
|
animationInterval = undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
Loading…
Reference in a new issue