diff --git a/core/inject.js b/core/inject.js index d8e6e3d20..667a8713d 100644 --- a/core/inject.js +++ b/core/inject.js @@ -264,11 +264,12 @@ Blockly.init_ = function(mainWorkspace) { } }); - Blockly.bindEvent_(window, 'resize', null, - function() { - Blockly.hideChaff(true); - Blockly.svgResize(mainWorkspace); - }); + var workspaceResizeHandler = Blockly.bindEvent_(window, 'resize', null, + function() { + Blockly.hideChaff(true); + Blockly.svgResize(mainWorkspace); + }); + mainWorkspace.setResizeHandlerWrapper(workspaceResizeHandler); Blockly.inject.bindDocumentEvents_(); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 52560ffdc..7b68c5b03 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -64,6 +64,12 @@ Blockly.WorkspaceSvg = function(options) { }; goog.inherits(Blockly.WorkspaceSvg, Blockly.Workspace); +/** + * Wrapper function called when a resize event occurs. + * @type {Array.} Data that can be passed to unbindEvent_ + */ +Blockly.WorkspaceSvg.prototype.resizeHandlerWrapper_ = null; + /** * Svg workspaces are user-visible (as opposed to a headless workspace). * @type {boolean} True if visible. False if headless. @@ -138,6 +144,14 @@ Blockly.WorkspaceSvg.prototype.scrollbar = null; */ Blockly.WorkspaceSvg.prototype.lastSound_ = null; +/** + * Save resize handler data so we can delete it later in dispose. + * @param {!Array.} handler Data that can be passed to unbindEvent_. + */ +Blockly.WorkspaceSvg.prototype.setResizeHandlerWrapper = function(handler) { + this.resizeHandlerWrapper_ = handler; +}; + /** * Create the workspace DOM elements. * @param {string=} opt_backgroundClass Either 'blocklyMainBackground' or @@ -238,6 +252,10 @@ Blockly.WorkspaceSvg.prototype.dispose = function() { // Top-most workspace. Dispose of the SVG too. goog.dom.removeNode(this.getParentSvg()); } + if (this.resizeHandlerWrapper_) { + Blockly.unbindEvent_(this.resizeHandlerWrapper_); + this.resizeHandlerWrapper_ = null; + } }; /**