diff --git a/core/blockly.js b/core/blockly.js index 4d14aac1e..f8dc17d3d 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -101,13 +101,6 @@ Blockly.selected = null; */ Blockly.draggingConnections = []; -/** - * Container element to render the WidgetDiv, DropDownDiv and Tooltip. - * @type {?Element} - * @package - */ -Blockly.parentContainer = null; - /** * Returns the dimensions of the specified SVG image. * @param {!SVGElement} svg SVG image. @@ -377,9 +370,7 @@ Blockly.hueToHex = function(hue) { * This method is a NOP if called after the first ``Blockly.inject``. * @param {!Element} container The container element. */ -Blockly.setParentContainer = function(container) { - Blockly.parentContainer = container; -}; +Blockly.setParentContainer = Blockly.common.setParentContainer; /** Aliases. */ diff --git a/core/common.js b/core/common.js index d9a6b9638..711cf3571 100644 --- a/core/common.js +++ b/core/common.js @@ -44,3 +44,31 @@ const setMainWorkspace = function(workspace) { mainWorkspace = workspace; }; exports.setMainWorkspace = setMainWorkspace; + +/** + * Container element in which to render the WidgetDiv, DropDownDiv and Tooltip. + * @type {?Element} + */ +let parentContainer; + +/** + * Get the container element in which to render the WidgetDiv, DropDownDiv and\ + * Tooltip. + * @return {?Element} + */ +const getParentContainer = function() { + return parentContainer; +}; +exports.getParentContainer = getParentContainer; + +/** + * Set the parent container. This is the container element that the WidgetDiv, + * DropDownDiv, and Tooltip are rendered into the first time `Blockly.inject` + * is called. + * This method is a NOP if called after the first ``Blockly.inject``. + * @param {!Element} newParent The container element. + */ +const setParentContainer = function(newParent) { + parentContainer = newParent; +}; +exports.setParentContainer = setParentContainer; diff --git a/core/dropdowndiv.js b/core/dropdowndiv.js index bf5eddb69..5ebb22a5e 100644 --- a/core/dropdowndiv.js +++ b/core/dropdowndiv.js @@ -163,7 +163,7 @@ Blockly.DropDownDiv.createDom = function() { } var div = document.createElement('div'); div.className = 'blocklyDropDownDiv'; - var container = Blockly.parentContainer || document.body; + var container = Blockly.common.getParentContainer() || document.body; container.appendChild(div); /** * The div element. diff --git a/core/tooltip.js b/core/tooltip.js index 12819e13f..d93825815 100644 --- a/core/tooltip.js +++ b/core/tooltip.js @@ -22,6 +22,7 @@ goog.provide('Blockly.Tooltip'); goog.require('Blockly.browserEvents'); +goog.require('Blockly.common'); goog.require('Blockly.utils.string'); @@ -170,7 +171,7 @@ Blockly.Tooltip.createDom = function() { // Create an HTML container for popup overlays (e.g. editor widgets). Blockly.Tooltip.DIV = document.createElement('div'); Blockly.Tooltip.DIV.className = 'blocklyTooltipDiv'; - var container = Blockly.parentContainer || document.body; + var container = Blockly.common.getParentContainer() || document.body; container.appendChild(Blockly.Tooltip.DIV); }; diff --git a/core/widgetdiv.js b/core/widgetdiv.js index 8b7de7dac..106dce645 100644 --- a/core/widgetdiv.js +++ b/core/widgetdiv.js @@ -67,7 +67,7 @@ Blockly.WidgetDiv.createDom = function() { */ Blockly.WidgetDiv.DIV = document.createElement('div'); Blockly.WidgetDiv.DIV.className = 'blocklyWidgetDiv'; - var container = Blockly.parentContainer || document.body; + var container = Blockly.common.getParentContainer() || document.body; container.appendChild(Blockly.WidgetDiv.DIV); }; diff --git a/tests/deps.js b/tests/deps.js index 14ae08221..784fc398a 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -172,8 +172,13 @@ goog.addDependency('../../core/toolbox/category.js', ['Blockly.ToolboxCategory'] goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.Css', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/toolbox.js', ['Blockly.Toolbox'], ['Blockly.BlockSvg', 'Blockly.CollapsibleToolboxCategory', 'Blockly.ComponentManager', 'Blockly.Css', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.ToolboxItemSelect', 'Blockly.IAutoHideable', 'Blockly.IKeyboardAccessible', 'Blockly.IStyleable', 'Blockly.IToolbox', 'Blockly.Options', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +<<<<<<< HEAD goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'], ['Blockly.IToolboxItem', 'Blockly.utils.IdGenerator'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.utils.string']); +======= +goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'], ['Blockly.IToolboxItem']); +goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.common', 'Blockly.utils.string']); +>>>>>>> c62fba04 (Move set/getParentContainer into common) goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'});