But even when calling the setParentContainer() method, the widget, dropdown and tooltip divs are still added in <body>, not in my target element.
const options = {
collapse: true,
comments: true,
media: "img/",
trashcan: false,
zoom: { controls: true, wheel: false },
renderer: "zelos",
scrollbars: true,
move: { drag: true, wheel: true },
hasSounds: false,
};
let blocklyArea = document.getElementById('blocklyarea');
let blocklyDiv = document.getElementById('blocklydiv');
Blockly.setParentContainer(blocklyArea);
let workspace = Blockly.inject(blocklyDiv, options);
let xml = Blockly.Xml.textToDom("...");
Blockly.Xml.domToWorkspace(xml, workspace);
var onresize = function() {
var element = blocklyArea;
var x = 0;
var y = 0;
do {
x += element.offsetLeft;
y += element.offsetTop;
element = element.offsetParent;
} while (element);
// Position blocklyDiv over blocklyArea.
blocklyDiv.style.left = x + 'px';
blocklyDiv.style.top = y + 'px';
blocklyDiv.style.width = blocklyArea.offsetWidth + 'px';
blocklyDiv.style.height = blocklyArea.offsetHeight + 'px';
Blockly.svgResize(workspace);
};
window.addEventListener('resize', onresize, false);
onresize();
Blockly.svgResize(workspace);
Blockly.getMainWorkspace().zoomToFit();
...
and my html snippet :
...
<div id="blocklyarea">
<div id="blockly">
<div id="blocklydiv"></div>
</div>
</div>
...
Any idea why this doesn't work for me ?
Thanks for your help !