Bug fix in ImageFlow 1.3

Today we are going to fix a bug I found in updating ImageFlow, going from version 1.2.1 to 1.3. The new version is intended to solve, among other things, the problem that was in Internet Explorer when there was only one image in the gallery. The problem was that nothing was showed if only we had a picture in the gallery in IE. Well, version 1.3 already displays the picture if we only have one, but if that image also has a caption, it turns out that the caption is not shown, nor Internet Explorer or any other browser . Well, here is the solution for those wishing to fix the bug (and are brave enough) and want to get their hands on the code of the library.

Fixing the bug

To solve the problem we have to open the file imageflow.js we find in the .zip file that we have downloaded. Let’s go to the line 526 approximately where we found the following code block:

/* Only animate if there is more than one image */
 if(my.max > 1)
 {
     my.glideTo(my.imageID);
 }

In this code block, the author checks for more than one image, in which case it calls a function that among other things, sets the caption to the current image (my.imageID). Well, to this if block we simply need to add an else block where we look at the case where there is not more than one image (ie exactly 1). The entire block should be something like this:

...
/* Only animate if there is more than one image */
 if(my.max > 1)
 {
     my.glideTo(my.imageID);
 }
 else
 {
     var caption = my.imagesDiv.childNodes[my.imageID].getAttribute('alt');
     if (caption === '' || my.captions === false)
     {
         caption = ' ';
     }
     my.captionDiv.innerHTML = caption;
 }
...

Thus, although we only have one image, we make sure that the image has a corresponding caption. I have advised the author about this little glitch and hopefully take it into account for the next update.

So that, I hope this post has been helpful!

Leave a Reply

Your email address will not be published. Required fields are marked *