From dcd463b5507b7d5921731555b83b05049d819136 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 21 Oct 2015 13:25:02 -0700 Subject: [PATCH] Add 'startScale' and remove 'enabled' options on zoom. --- core/inject.js | 70 +++++++++++++++++++++---------------------- demos/code/code.js | 4 ++- tests/playground.html | 4 +-- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/core/inject.js b/core/inject.js index fd18dbd0c..bf8a29c11 100644 --- a/core/inject.js +++ b/core/inject.js @@ -161,19 +161,17 @@ Blockly.parseOptions_ = function(options) { /* TODO (fraser): Add documentation page: * https://developers.google.com/blockly/installation/zoom * - * enabled - * - * Set to `true` to allow zooming of the main workspace. Zooming is only - * possible if the workspace has scrollbars. If `false`, then the options - * below have no effect. Defaults to `false`. - * * controls * - * Set to `true` to show zoom-in and zoom-out buttons. Defaults to `true`. + * Set to `true` to show zoom-in and zoom-out buttons. Defaults to `false`. * * wheel * - * Set to `true` to allow the mouse wheel to zoom. Defaults to `true`. + * Set to `true` to allow the mouse wheel to zoom. Defaults to `false`. + * + * startScale + * + * Initial magnification factor. Defaults to `1.0`. * * maxScale * @@ -194,36 +192,35 @@ Blockly.parseOptions_ = function(options) { // https://developers.google.com/blockly/installation/zoom var zoom = options['zoom'] || {}; var zoomOptions = {}; - zoomOptions.enabled = hasScrollbars && !!zoom['enabled']; - if (zoomOptions.enabled) { - if (zoom['controls'] === undefined) { - zoomOptions.controls = true; - } else { - zoomOptions.controls = !!zoom['controls']; - } - if (zoom['wheel'] === undefined) { - zoomOptions.wheel = true; - } else { - zoomOptions.wheel = !!zoom['wheel']; - } - if (zoom['maxScale'] === undefined) { - zoomOptions.maxScale = 3; - } else { - zoomOptions.maxScale = parseFloat(zoom['maxScale']); - } - if (zoom['minScale'] === undefined) { - zoomOptions.minScale = 0.3; - } else { - zoomOptions.minScale = parseFloat(zoom['minScale']); - } - if (zoom['scaleSpeed'] === undefined) { - zoomOptions.scaleSpeed = 1.2; - } else { - zoomOptions.scaleSpeed = parseFloat(zoom['scaleSpeed']); - } - } else { + if (zoom['controls'] === undefined) { zoomOptions.controls = false; + } else { + zoomOptions.controls = !!zoom['controls']; + } + if (zoom['wheel'] === undefined) { zoomOptions.wheel = false; + } else { + zoomOptions.wheel = !!zoom['wheel']; + } + if (zoom['startScale'] === undefined) { + zoomOptions.startScale = 1; + } else { + zoomOptions.startScale = parseFloat(zoom['startScale']); + } + if (zoom['maxScale'] === undefined) { + zoomOptions.maxScale = 3; + } else { + zoomOptions.maxScale = parseFloat(zoom['maxScale']); + } + if (zoom['minScale'] === undefined) { + zoomOptions.minScale = 0.3; + } else { + zoomOptions.minScale = parseFloat(zoom['minScale']); + } + if (zoom['scaleSpeed'] === undefined) { + zoomOptions.scaleSpeed = 1.2; + } else { + zoomOptions.scaleSpeed = parseFloat(zoom['scaleSpeed']); } var enableRealtime = !!options['realtime']; @@ -377,6 +374,7 @@ Blockly.createMainWorkspace_ = function(svg, options) { options.getMetrics = Blockly.getMainWorkspaceMetrics_; options.setMetrics = Blockly.setMainWorkspaceMetrics_; var mainWorkspace = new Blockly.WorkspaceSvg(options); + mainWorkspace.scale = options.zoomOptions.startScale; svg.appendChild(mainWorkspace.createDom('blocklyMainBackground')); mainWorkspace.markFocused(); diff --git a/demos/code/code.js b/demos/code/code.js index 846c8ce6f..d7c50d95d 100644 --- a/demos/code/code.js +++ b/demos/code/code.js @@ -384,7 +384,9 @@ Code.init = function() { media: '../../media/', rtl: rtl, toolbox: toolbox, - zoom: {enabled: true} + zoom: + {controls: true, + wheel: true} }); // Add to reserved word list: Local variables in execution environment (runJS) diff --git a/tests/playground.html b/tests/playground.html index 278db90a9..7e37763b2 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -84,9 +84,9 @@ function start() { scrollbars: true, toolbox: toolbox, zoom: - {enabled: true, - controls: true, + {controls: true, wheel: true, + startScale: 2.0, maxScale: 4, minScale: .25, scaleSpeed: 1.1