benplum/Zoomer — pull request #14 by eyscode (2014-07-01 20:00:26+00:00)
Title: Fix the source of the bug #12, and fix a new regarding bug on resize.

After reading your code I saw that the minimum sizes are calculated for the first time when _onImageLoad has not yet been executed, therefore naturalWidth and naturalHeight are 0, then the minimum sizes are miscalculated give at least an Infinity value, then when _onImageLoad is executed, the naturalWidth, naturalHeight, targetImageWidth and targetImageHeight ​​are calculated, also if the image is larger than the image viewer then enters on the if block:

/ / Initial sizing to fit screen
if (data.naturalHeight> (data.frameHeight - data.marginReal) | | data.naturalWidth> (data.frameWidth - data.marginReal)) {
_setMinimums data = (data);
data.targetImageHeight = data.minHeight;
data.targetImageWidth = data.minWidth;
}

then the minimum values ​​are re-calculated correctly so the targetWidth/targetHeight values are valid​​.

The problem comes when the image is smaller than the image viewer, so never enters on the if block above and stays with minimum sizes ​​invalid (AKA Infinity), then when _updateValues ​​runs in the part "Check Max and Min image values; recenter if too small", at least one of the ifs with < data.minWidth or < data.minHeight runs because is Infinity, for example if the small image is wide the if that runs is:

if (data.targetImageWidth