From 4d22442e1b30b26464171688e296f61abf1b1066 Mon Sep 17 00:00:00 2001 From: "Evan W. Patton" Date: Tue, 23 May 2017 13:21:51 -0400 Subject: [PATCH] Add method for changing scrollbar visibility --- core/flyout.js | 12 +++++++++--- core/workspace_svg.js | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/core/flyout.js b/core/flyout.js index 54e0fe8ca..adb005934 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -711,7 +711,9 @@ Blockly.Flyout.prototype.updateDisplay_ = function() { this.svgGroup_.style.display = show ? 'block' : 'none'; // Update the scrollbar's visiblity too since it should mimic the // flyout's visibility. - this.scrollbar_.setContainerVisible(show); + if (this.scrollbar_) { + this.scrollbar_.setContainerVisible(show); + } }; /** @@ -721,7 +723,9 @@ Blockly.Flyout.prototype.hide = function() { if (!this.isVisible()) { return; } - Blockly.mainWorkspace.scrollbar.setContainerVisible(true); + if (Blockly.mainWorkspace) { + Blockly.mainWorkspace.setScrollbarsVisible(true); + } this.setVisible(false); // Delete all the event listeners. for (var x = 0, listen; listen = this.listeners_[x]; x++) { @@ -742,7 +746,9 @@ Blockly.Flyout.prototype.hide = function() { * Variables and procedures have a custom set of blocks. */ Blockly.Flyout.prototype.show = function(xmlList) { - Blockly.mainWorkspace.scrollbar.setContainerVisible(false); // hide parent's scrollbars + if (Blockly.mainWorkspace) { + Blockly.mainWorkspace.setScrollbarsVisible(false); // hide parent's scrollbars + } this.workspace_.setResizesEnabled(false); this.hide(); this.clearOldBlocks_(); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index d1d850a7c..96cb15128 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -1671,6 +1671,15 @@ Blockly.WorkspaceSvg.prototype.getButtonCallback = function(key) { return this.flyoutButtonCallbacks_[key]; }; +/** + * Convenience method to hide the scrollbars on the workspace. This method has + * no effect if the workspace's options had scrollbars set to false. + * @param {boolean} visible true to show the scrollbars, otherwise false. + */ +Blockly.WorkspaceSvg.prototype.setScrollbarsVisible = function(visible) { + this.scrollbar && this.scrollbar.setContainerVisible(visible) +}; + // Export symbols that would otherwise be renamed by Closure compiler. Blockly.WorkspaceSvg.prototype['setVisible'] = Blockly.WorkspaceSvg.prototype.setVisible;