From 2e035f1c71f2cd045f3f2400517430c77af8da06 Mon Sep 17 00:00:00 2001 From: Dustin Moore Date: Wed, 29 May 2013 14:07:08 -0700 Subject: [PATCH 1/3] Partial Fix for when hiding openseadragon container Hiding the container div was breaking the viewport. This patch fixes that by defaulting to the home view when hidden. (Better fix would maintain last position) --- src/viewport.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/viewport.js b/src/viewport.js index 7b100283..83c10df7 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -235,6 +235,13 @@ $.Viewport.prototype = { * @function */ getCenter: function( current ) { + //Patch: if centerspring is NaN use home bonds center instead. Only used if container div is hidden. + //To Do: Make it smarter by storing last good position or refactoring so hidden div doesn't return NaN + //results + homeCenter = this.homeBounds.getCenter(); + currentX = isNaN(this.centerSpringX.current.value) ? homeCenter.x : this.centerSpringX.current.value; + currentY = isNaN(this.centerSpringY.current.value) ? homeCenter.y : this.centerSpringY.current.value; + var centerCurrent = new $.Point( this.centerSpringX.current.value, this.centerSpringY.current.value @@ -569,9 +576,12 @@ $.Viewport.prototype = { * @return {OpenSeadragon.Viewport} Chainable. */ resize: function( newContainerSize, maintain ) { + //Set current size to 1 if 0 (hidden div) + var currentsize = this.containerSize.x == 0 ? 1 : this.containerSize.x; + var oldBounds = this.getBounds(), newBounds = oldBounds, - widthDeltaFactor = newContainerSize.x / this.containerSize.x; + widthDeltaFactor = newContainerSize.x / currentsize; this.containerSize = new $.Point( newContainerSize.x, @@ -579,8 +589,14 @@ $.Viewport.prototype = { ); if (maintain) { - newBounds.width = oldBounds.width * widthDeltaFactor; - newBounds.height = newBounds.width / this.getAspectRatio(); + newBounds.width = isNaN(oldBounds.width * widthDeltaFactor) ? 0 : oldBounds.width * widthDeltaFactor; + newBounds.height = isNaN(newBounds.width / this.getAspectRatio()) ? 0 : newBounds.width / this.getAspectRatio(); + } + + //Still getting NaN results when restoring from hidden div, this resets to homebounds. + //ToDo: figure out how to stop NaN results when div is hidden. + if(isNaN(newBounds.width) || isNaN(newBounds.height) || isNaN(newBounds.x) || isNaN(newBounds.y)){ + newBounds = this.getHomeBounds(); } if( this.viewer ){ From df913ecd1240026bc7ec936a420abd7e2a52eed4 Mon Sep 17 00:00:00 2001 From: Dustin Moore Date: Wed, 29 May 2013 14:20:22 -0700 Subject: [PATCH 2/3] Operator Change --- src/viewport.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/viewport.js b/src/viewport.js index 83c10df7..e4945f69 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -577,7 +577,6 @@ $.Viewport.prototype = { */ resize: function( newContainerSize, maintain ) { //Set current size to 1 if 0 (hidden div) - var currentsize = this.containerSize.x == 0 ? 1 : this.containerSize.x; var oldBounds = this.getBounds(), newBounds = oldBounds, From daeb0f172b4d6a486e04f1481dff731ce20df325 Mon Sep 17 00:00:00 2001 From: Dustin Moore Date: Wed, 29 May 2013 14:20:48 -0700 Subject: [PATCH 3/3] Operator Change --- src/viewport.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/viewport.js b/src/viewport.js index e4945f69..88b99fd2 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -577,6 +577,7 @@ $.Viewport.prototype = { */ resize: function( newContainerSize, maintain ) { //Set current size to 1 if 0 (hidden div) + var currentsize = this.containerSize.x === 0 ? 1 : this.containerSize.x; var oldBounds = this.getBounds(), newBounds = oldBounds,