From 897a237807d8cbd427b18674750859aca363453f Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Tue, 20 Jan 2015 11:23:34 -0800 Subject: [PATCH] Added viewport-change event; fixed spring reset --- changelog.txt | 2 ++ src/spring.js | 6 ++---- src/tiledimage.js | 3 --- src/viewer.js | 26 +++++++++++++++++++------- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/changelog.txt b/changelog.txt index 671a9edd..d3a20e31 100644 --- a/changelog.txt +++ b/changelog.txt @@ -44,6 +44,8 @@ OPENSEADRAGON CHANGELOG * Added union() to OpenSeadragon.Rect * Fixed an error in fitBounds if the new and old bounds were extremely close in size * Added ajaxWithCredentials option (#543) +* Added viewport-change event for after the viewport changes but before it's drawn +* A spring's current value is now updated immediately on reset (#524) 1.2.1: (in progress) diff --git a/src/spring.js b/src/spring.js index 4f92dfcb..3320ecc2 100644 --- a/src/spring.js +++ b/src/spring.js @@ -117,10 +117,8 @@ $.Spring.prototype = /** @lends OpenSeadragon.Spring.prototype */{ * @param {Number} target */ resetTo: function( target ) { - this.target.value = target; - this.target.time = this.current.time; - this.start.value = this.target.value; - this.start.time = this.target.time; + this.start.value = this.target.value = this.current.value = target; + this.start.time = this.target.time = this.current.time = $.now(); }, /** diff --git a/src/tiledimage.js b/src/tiledimage.js index fc444b83..db52c66c 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -409,8 +409,6 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag this._xSpring.resetTo(position.x); this._ySpring.resetTo(position.y); - this._xSpring.update(); - this._ySpring.update(); } else { if (sameTarget) { return; @@ -454,7 +452,6 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag } this._scaleSpring.resetTo(scale); - this._scaleSpring.update(); this._updateForScale(); } else { if (sameTarget) { diff --git a/src/viewer.js b/src/viewer.js index f48eea97..8a291e50 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2798,13 +2798,10 @@ function updateMulti( viewer ) { function updateOnce( viewer ) { - var containerSize, - animated; - //viewer.profiler.beginUpdate(); if ( viewer.autoResize ) { - containerSize = _getSafeElemSize( viewer.container ); + var containerSize = _getSafeElemSize( viewer.container ); if ( !containerSize.equals( THIS[ viewer.hash ].prevContainerSize ) ) { // maintain image position var oldBounds = viewer.viewport.getBounds(); @@ -2815,8 +2812,22 @@ function updateOnce( viewer ) { } } - animated = viewer.viewport.update(); - animated = viewer.world.update() || animated; + var viewportChange = viewer.viewport.update(); + var animated = viewer.world.update() || viewportChange; + + if (viewportChange) { + /** + * Raised when any spring animation update occurs (zoom, pan, etc.), + * before the viewer has drawn the new location. + * + * @event viewport-change + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event. + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + viewer.raiseEvent('viewport-change'); + } if( viewer.referenceStrip ){ animated = viewer.referenceStrip.update( viewer.viewport ) || animated; @@ -2847,7 +2858,8 @@ function updateOnce( viewer ) { if (animated) { /** - * Raised when any spring animation update occurs (zoom, pan, etc.). + * Raised when any spring animation update occurs (zoom, pan, etc.), + * after the viewer has drawn the new location. * * @event animation * @memberof OpenSeadragon.Viewer