Support a custom container element for the dropdowndiv, widgetdiv and tooltip. (#3772)

* Support a custom container element for the dropdowndiv, widgetdiv and tooltip
This commit is contained in:
Sam El-Husseini
2020-03-27 17:13:46 -07:00
committed by GitHub
parent e1e99fd2fe
commit a3dbbfd7ab
4 changed files with 24 additions and 3 deletions

View File

@@ -90,6 +90,13 @@ Blockly.clipboardTypeCounts_ = null;
*/
Blockly.cache3dSupported_ = null;
/**
* Container element to render the WidgetDiv, DropDownDiv and Tooltip.
* @type {?Element}
* @package
*/
Blockly.parentContainer = null;
/**
* Blockly opaque event data used to unbind events when using
* `Blockly.bindEvent_` and `Blockly.bindEventWithChecks_`.
@@ -661,3 +668,14 @@ Blockly.checkBlockColourConstant_ = function(
console.warn(warning);
}
};
/**
* 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} container The container element.
*/
Blockly.setParentContainer = function(container) {
Blockly.parentContainer = container;
};

View File

@@ -127,7 +127,8 @@ Blockly.DropDownDiv.createDom = function() {
}
var div = document.createElement('div');
div.className = 'blocklyDropDownDiv';
document.body.appendChild(div);
var container = Blockly.parentContainer || document.body;
container.appendChild(div);
/**
* The div element.
* @type {!Element}

View File

@@ -121,7 +121,8 @@ 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';
document.body.appendChild(Blockly.Tooltip.DIV);
var container = Blockly.parentContainer || document.body;
container.appendChild(Blockly.Tooltip.DIV);
};
/**

View File

@@ -62,7 +62,8 @@ Blockly.WidgetDiv.createDom = function() {
*/
Blockly.WidgetDiv.DIV = document.createElement('div');
Blockly.WidgetDiv.DIV.className = 'blocklyWidgetDiv';
document.body.appendChild(Blockly.WidgetDiv.DIV);
var container = Blockly.parentContainer || document.body;
container.appendChild(Blockly.WidgetDiv.DIV);
};
/**