From fd7d4a2befd751b1d914b55acb4f0790e70c998d Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 21 Apr 2016 04:52:43 -0700 Subject: [PATCH] Make scrollCenter public, remove zoomReset. --- core/workspace_svg.js | 17 ++--------------- core/zoom_controls.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 4b9570ce3..2d562fd2e 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -1038,26 +1038,13 @@ Blockly.WorkspaceSvg.prototype.zoomToFit = function() { var ratioX = workspaceWidth / blocksWidth; var ratioY = workspaceHeight / blocksHeight; this.setScale(Math.min(ratioX, ratioY)); - this.scrollCenter_(); -}; - -/** - * Reset zooming and dragging. - * @param {!Event} e Mouse down event. - */ -Blockly.WorkspaceSvg.prototype.zoomReset = function(e) { - this.setScale(1); - this.scrollCenter_(); - // This event has been handled. Don't start a workspace drag. - e.stopPropagation(); - e.preventDefault(); + this.scrollCenter(); }; /** * Center the workspace. - * @private */ -Blockly.WorkspaceSvg.prototype.scrollCenter_ = function() { +Blockly.WorkspaceSvg.prototype.scrollCenter = function() { if (!this.scrollbar) { // Can't center a non-scrolling workspace. return; diff --git a/core/zoom_controls.js b/core/zoom_controls.js index f745c9c21..d50110829 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -162,16 +162,21 @@ Blockly.ZoomControls.prototype.createDom = function() { workspace.options.pathToMedia + Blockly.SPRITE.url); // Attach event listeners. - Blockly.bindEvent_(zoomresetSvg, 'mousedown', workspace, workspace.zoomReset); + Blockly.bindEvent_(zoomresetSvg, 'mousedown', null, function(e) { + workspace.setScale(1); + workspace.scrollCenter(); + e.stopPropagation(); // Don't start a workspace scroll. + e.preventDefault(); // Stop double-clicking from selecting text. + }); Blockly.bindEvent_(zoominSvg, 'mousedown', null, function(e) { workspace.zoomCenter(1); e.stopPropagation(); // Don't start a workspace scroll. - e.preventDefault(); + e.preventDefault(); // Stop double-clicking from selecting text. }); Blockly.bindEvent_(zoomoutSvg, 'mousedown', null, function(e) { workspace.zoomCenter(-1); e.stopPropagation(); // Don't start a workspace scroll. - e.preventDefault(); + e.preventDefault(); // Stop double-clicking from selecting text. }); return this.svgGroup_;