Fix #425. Attash the resize handler to the workspace so it can be removed (#429)

when workspace.dispose() is called.
This commit is contained in:
picklesrus
2016-06-13 14:46:58 -07:00
committed by GitHub
parent 477562b597
commit 6851baea12
2 changed files with 24 additions and 5 deletions

View File

@@ -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_();

View File

@@ -64,6 +64,12 @@ Blockly.WorkspaceSvg = function(options) {
};
goog.inherits(Blockly.WorkspaceSvg, Blockly.Workspace);
/**
* Wrapper function called when a resize event occurs.
* @type {Array.<!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.<!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;
}
};
/**