From c91039b5459d8c01bf233015db5261aec2c022ff Mon Sep 17 00:00:00 2001 From: Victor Rodriguez Gil Date: Mon, 13 Jun 2016 23:07:17 +0000 Subject: [PATCH] Code that fixes #890, new test passes. Events.js test needed fixing with good value, unrelated to actual test. --- src/viewport.js | 43 ++++++++++++++++++++++++++---------------- test/modules/events.js | 2 +- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/viewport.js b/src/viewport.js index da2ce761..60a5e2c4 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -503,21 +503,26 @@ $.Viewport.prototype = { } else { var dx = 0; var thresholdLeft = newBounds.x + (newBounds.width - horizontalThreshold); - if (this._contentBoundsNoRotate.x > thresholdLeft) { - dx = this._contentBoundsNoRotate.x - thresholdLeft; - } - + var leftDx = this._contentBoundsNoRotate.x - thresholdLeft; var contentRight = this._contentBoundsNoRotate.x + this._contentBoundsNoRotate.width; var thresholdRight = newBounds.x + horizontalThreshold; + var rightDx = contentRight - thresholdRight; + + if (this._contentBoundsNoRotate.x > thresholdLeft) { + dx = leftDx; + } if (contentRight < thresholdRight) { - var newDx = contentRight - thresholdRight; if (dx) { - dx = (dx + newDx) / 2; + dx = (dx + rightDx) / 2; } else { - dx = newDx; + dx = rightDx; } } - newBounds.x += dx; + if (horizontalThreshold > this._contentBoundsNoRotate.width && (newBounds.x > -thresholdLeft || newBounds.x + horizontalThreshold < 1)) { + newBounds.x += (leftDx + rightDx) / 2; + } else { + newBounds.x += dx; + } } if (this.wrapVertical) { @@ -525,21 +530,27 @@ $.Viewport.prototype = { } else { var dy = 0; var thresholdTop = newBounds.y + (newBounds.height - verticalThreshold); - if (this._contentBoundsNoRotate.y > thresholdTop) { - dy = this._contentBoundsNoRotate.y - thresholdTop; - } - + var topDy = this._contentBoundsNoRotate.y - thresholdTop; var contentBottom = this._contentBoundsNoRotate.y + this._contentBoundsNoRotate.height; var thresholdBottom = newBounds.y + verticalThreshold; + var bottomDy = contentBottom - thresholdBottom; + + if (this._contentBoundsNoRotate.y > thresholdTop) { + dy = topDy; + } if (contentBottom < thresholdBottom) { - var newDy = contentBottom - thresholdBottom; if (dy) { - dy = (dy + newDy) / 2; + dy = (dy + bottomDy) / 2; } else { - dy = newDy; + dy = bottomDy; } } - newBounds.y += dy; + if (verticalThreshold > this._contentBoundsNoRotate.height && (newBounds.y > -thresholdTop || newBounds.y + verticalThreshold < 1)) { + newBounds.y += (topDy + bottomDy) / 2; + } else { + newBounds.y += dy; + } + } if (this.viewer) { diff --git a/test/modules/events.js b/test/modules/events.js index 30dc28a2..ccfbab26 100644 --- a/test/modules/events.js +++ b/test/modules/events.js @@ -820,8 +820,8 @@ Util.assessNumericValue(zoom, 0.002, epsilon, "Zoom should not be prevented"); Util.assertRectangleEquals( + new OpenSeadragon.Rect(-249.5, -0.25, 500, 0.5), bounds, - new OpenSeadragon.Rect(-250, -0.25, 500, 0.5), epsilon, 'Pan should not be prevented');