diff --git a/src/viewer.js b/src/viewer.js index 98f8e484..f17621d6 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -220,6 +220,7 @@ $.Viewer = function( options ) { this._updateRequestId = null; this._loadQueue = []; this.currentOverlays = []; + this._updatePixelDensityRatioBind = null; this._lastScrollTime = $.now(); // variable used to help normalize the scroll event speed of different devices @@ -426,8 +427,7 @@ $.Viewer = function( options ) { } } - // Add updatePixelDensityRatio to resize event - $.addEvent( window, 'resize', this._updatePixelDensityRatio.bind(this) ); + this._addUpdatePixelDensityRatioEvent(); //Instantiate a navigator if configured if ( this.showNavigator){ @@ -751,6 +751,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, return; } + this._removeUpdatePixelDensityRatioEvent(); + this.close(); this.clearOverlays(); @@ -2284,6 +2286,23 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, } else { $.console.warn('Attempting to display a reference strip while "sequenceMode" is off.'); } + }, + + /** + * Adds _updatePixelDensityRatio to the window resize event. + * @private + */ + _addUpdatePixelDensityRatioEvent: function() { + this._updatePixelDensityRatioBind = this._updatePixelDensityRatio.bind(this); + $.addEvent( window, 'resize', this._updatePixelDensityRatioBind ); + }, + + /** + * Removes _updatePixelDensityRatio from the window resize event. + * @private + */ + _removeUpdatePixelDensityRatioEvent: function() { + $.removeEvent( window, 'resize', this._updatePixelDensityRatioBind ); } });