From f0cf90df76693bc6f9ff039d5cfa9068ead60ddb Mon Sep 17 00:00:00 2001 From: ronnymikalsen Date: Fri, 26 Mar 2021 09:43:30 +0100 Subject: [PATCH] fix: removes resize event on destroy --- src/viewer.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) 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 ); } });