I'll be honest. Code submissions come into our queue sometimes and I have to read them a few times before I can identify the WTF. When Alex asked me to write this one up, I had to read it over line-by-line for almost an hour and figure out what was wrong with it.

This was sent in anonymously, with the note that it's designed to display a pretty, spinning "now loading" image while a report is created.

function Animate() {
   var img = document.getElementById("Logo")
   if (img.src.indexOf("Wait01.gif")!=-1) {
   } else if (img.src.indexOf("Wait02.gif")!=-1) {
   } else if (img.src.indexOf("Wait03.gif")!=-1) {
   } else if (img.src.indexOf("Wait04.gif")!=-1) {
   } else if (img.src.indexOf("Wait05.gif")!=-1) {
   } else {

And finally, I figured out what the problem was and was able to write about it. There's extra unnecessary code in there, wasting precious CPU cycles! it should be something more like:

var animFrame = 0;
function Animate() {
   var img = document.getElementById('Logo');
   animFrame = animFrame % 6 + 1;
   img.src = 'Template/Wait0' + animFrame + '.gif';
   setTimeout('Animate();', 200);

...There. Much cleaner! Just upload your six .gifs to the template folder, run that function, and you're done!


...Or they could've just used a freaking animated gif in the first place.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!