From 40efb59a34c9e5bd9b7cb0aaee5e0fc77cf00303 Mon Sep 17 00:00:00 2001 From: Monica Kozbial Date: Fri, 10 Jul 2020 17:34:53 -0700 Subject: [PATCH] Unbind event handlers in dispose of zoom controls. (#4031) * Unbind event handlers in dispose of zoom controls. * Move event handler references to constructor. --- core/zoom_controls.js | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 4b1edadec..98e431f7f 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -29,6 +29,30 @@ Blockly.ZoomControls = function(workspace) { * @private */ this.workspace_ = workspace; + + /** + * A handle to use to unbind the mouse down event handler for zoom reset + * button. Opaque data returned from Blockly.bindEventWithChecks_. + * @type {?Blockly.EventData} + * @private + */ + this.onZoomResetWrapper_ = null; + + /** + * A handle to use to unbind the mouse down event handler for zoom in button. + * Opaque data returned from Blockly.bindEventWithChecks_. + * @type {?Blockly.EventData} + * @private + */ + this.onZoomInWrapper_ = null; + + /** + * A handle to use to unbind the mouse down event handler for zoom out button. + * Opaque data returned from Blockly.bindEventWithChecks_. + * @type {?Blockly.EventData} + * @private + */ + this.onZoomOutWrapper_ = null; }; /** @@ -80,6 +104,7 @@ Blockly.ZoomControls.prototype.left_ = 0; */ Blockly.ZoomControls.prototype.top_ = 0; + /** * Create the zoom controls. * @return {!SVGElement} The zoom controls SVG group. @@ -122,6 +147,15 @@ Blockly.ZoomControls.prototype.dispose = function() { if (this.svgGroup_) { Blockly.utils.dom.removeNode(this.svgGroup_); } + if (this.onZoomResetWrapper_) { + Blockly.unbindEvent_(this.onZoomResetWrapper_); + } + if (this.onZoomInWrapper_) { + Blockly.unbindEvent_(this.onZoomInWrapper_); + } + if (this.onZoomOutWrapper_) { + Blockly.unbindEvent_(this.onZoomOutWrapper_); + } }; /** @@ -209,7 +243,7 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { this.workspace_.options.pathToMedia + Blockly.SPRITE.url); // Attach listener. - Blockly.bindEventWithChecks_( + this.onZoomOutWrapper_ = Blockly.bindEventWithChecks_( zoomoutSvg, 'mousedown', null, this.zoom_.bind(this, -1)); }; @@ -256,7 +290,7 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { this.workspace_.options.pathToMedia + Blockly.SPRITE.url); // Attach listener. - Blockly.bindEventWithChecks_( + this.onZoomInWrapper_ = Blockly.bindEventWithChecks_( zoominSvg, 'mousedown', null, this.zoom_.bind(this, 1)); }; @@ -320,7 +354,7 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { this.workspace_.options.pathToMedia + Blockly.SPRITE.url); // Attach event listeners. - Blockly.bindEventWithChecks_( + this.onZoomResetWrapper_ = Blockly.bindEventWithChecks_( zoomresetSvg, 'mousedown', null, this.resetZoom_.bind(this)); };