From 968cb96bc428c2ff0f903a609e0ab6cbe5d0f5cc Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 28 Nov 2022 17:54:23 -0500 Subject: [PATCH] added before-destroy event; reverted viewport boundary constraint changes --- src/viewer.js | 13 +++++++++++ src/viewport.js | 59 ++++++++++++++++++++++++++++++------------------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index a564814b..748137fe 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -756,6 +756,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * viewer = null; //important * * @function + * @fires OpenSeadragon.Viewer.event:before-destroy * @fires OpenSeadragon.Viewer.event:destroy */ destroy: function( ) { @@ -764,6 +765,17 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, return; } + /** + * Raised when the viewer is about to be destroyed (see {@link OpenSeadragon.Viewer#before-destroy}). + * + * @event before-destroy + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event. + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + this.raiseEvent( 'before-destroy' ); + this._removeUpdatePixelDensityRatioEvent(); this.close(); @@ -841,6 +853,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, // clear our reference to the main element - they will need to pass it in again, creating a new viewer this.element = null; + /** * Raised when the viewer is destroyed (see {@link OpenSeadragon.Viewer#destroy}). * diff --git a/src/viewport.js b/src/viewport.js index 0aff620d..22d8b744 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -513,7 +513,7 @@ $.Viewport.prototype = { * @param {OpenSeadragon.Rect} bounds * @returns {OpenSeadragon.Rect} constrained bounds. */ - _applyBoundaryConstraints: function(bounds) { + _applyBoundaryConstraints: function(bounds) { var newBounds = new $.Rect( bounds.x, bounds.y, @@ -529,19 +529,26 @@ $.Viewport.prototype = { var horizontalThreshold, leftDx, rightDx; if (newBounds.width > this._contentBoundsNoRotate.width) { horizontalThreshold = this.visibilityRatio * this._contentBoundsNoRotate.width; + leftDx = this._contentBoundsNoRotate.x - newBounds.x + horizontalThreshold; + rightDx = contentRight - boundsRight - horizontalThreshold; + + if (rightDx > 0) { + newBounds.x += rightDx; + } else if (leftDx < 0) { + newBounds.x += leftDx; + } } else { horizontalThreshold = this.visibilityRatio * newBounds.width; + leftDx = this._contentBoundsNoRotate.x - boundsRight + horizontalThreshold; + rightDx = contentRight - newBounds.x - horizontalThreshold; + if (horizontalThreshold > this._contentBoundsNoRotate.width) { + newBounds.x += (leftDx + rightDx) / 2; + } else if (rightDx < 0) { + newBounds.x += rightDx; + } else if (leftDx > 0) { + newBounds.x += leftDx; + } } - leftDx = this._contentBoundsNoRotate.x - boundsRight + horizontalThreshold; - rightDx = contentRight - newBounds.x - horizontalThreshold; - if (horizontalThreshold > this._contentBoundsNoRotate.width) { - newBounds.x += (leftDx + rightDx) / 2; - } else if (rightDx < 0) { - newBounds.x += rightDx; - } else if (leftDx > 0) { - newBounds.x += leftDx; - } - } if (this.wrapVertical) { @@ -553,20 +560,26 @@ $.Viewport.prototype = { var verticalThreshold, topDy, bottomDy; if (newBounds.height > this._contentBoundsNoRotate.height) { verticalThreshold = this.visibilityRatio * this._contentBoundsNoRotate.height; - } else{ + topDy = this._contentBoundsNoRotate.y - newBounds.y + verticalThreshold; + bottomDy = contentBottom - boundsBottom - verticalThreshold; + + if (bottomDy > 0) { + newBounds.y += bottomDy; + } else if (topDy < 0) { + newBounds.y += topDy; + } + } else { verticalThreshold = this.visibilityRatio * newBounds.height; + topDy = this._contentBoundsNoRotate.y - boundsBottom + verticalThreshold; + bottomDy = contentBottom - newBounds.y - verticalThreshold; + if (verticalThreshold > this._contentBoundsNoRotate.height) { + newBounds.y += (topDy + bottomDy) / 2; + } else if (bottomDy < 0) { + newBounds.y += bottomDy; + } else if (topDy > 0) { + newBounds.y += topDy; + } } - - topDy = this._contentBoundsNoRotate.y - boundsBottom + verticalThreshold; - bottomDy = contentBottom - newBounds.y - verticalThreshold; - if (verticalThreshold > this._contentBoundsNoRotate.height) { - newBounds.y += (topDy + bottomDy) / 2; - } else if (bottomDy < 0) { - newBounds.y += bottomDy; - } else if (topDy > 0) { - newBounds.y += topDy; - } - } return newBounds;