From 7d999509426cfb425cb441a492ec8698aaff3ed9 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 25 Feb 2016 10:57:04 +0000 Subject: [PATCH] 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. --- static/js/pandora.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/static/js/pandora.js b/static/js/pandora.js index d123f47e..cda1e5fe 100644 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -188,10 +188,14 @@ appPanel loadingScreen.appendChild(images.loadingIcon); // FF3.6 document.body can be undefined here + var onloadCalled = false; window.onload = function() { - document.body.style.margin = 0; - document.body.appendChild(loadingScreen); - startAnimation(); + 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() { - clearInterval(animationInterval); + if (animationInterval !== undefined) { + clearInterval(animationInterval); + animationInterval = undefined; + } } }());