[div here].innerHTML = "<svg id='blocksvg'></svg>" //creates the svg (with id blocksvg) inside the div
var svg = workspace.getParentSvg().getElementsByClassName("blocklyWorkspace")[0].getElementsByClassName("blocklyBlockCanvas")[0].getElementsByClassName("blocklyDraggable blocklySelected")[0]
svg.setAttribute("transform","") //getting rid of the transform property
[div here].children.blocksvg.innerHTML = svg.outerHTML //sets the SVG to the block's svg
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Blockly Demo: Custom Dialog</title>
<script src="../../blockly_compressed.js"></script>
<script src="../../blocks_compressed.js"></script>
<script src="../../msg/js/en.js"></script>
<script src="blocks.js"></script>
<link rel="stylesheet" href="style.css">
<script>
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
function login() {
var y = document.getElementById("submit");
y.innerHTML="Logged In";
document.getElementById("email").disabled = true;
document.getElementById("pwd").disabled = true;
}
</script>
</head>
<body>
<div id="blocklyDivMain" style="position:fixed;top:0;left:0;right:0;bottom:0">
<div id="upperDiv" style="height:25%;width:100%;top:0;left:0;position:absolute;border: 1px solid #0099FF;"
ondrop="drop(event)" ondragover="allowDrop(event)">
<div id="login" style="height:30%;left:10%;width:50%;position:absolute;margin-left:15%; padding: 5px;">
<img src="logo.png" alt="Smiley face" height="70" width="120"/><br>
<input id="email" type="text" name="fname" value="usbuyer@abc.com" ><br>
<input id="pwd" type="text" name="lname" value="***********" style="margin-top:3px;"><br>
<button id="submit" type="submit" value="Submit" style="background-color:#009cde;width:131px;margin-top:13px;" onclick="login()">Submit</button><br>
</div>
<div id="centerDiv" style="height:30%;left:50%;width:15%;position:absolute;">
<br><br>
<input type="radio" name="gender" value="male" class="radioRight"/><br>
<input type="radio" name="gender" value="male" class="radioRight"/>
<input type="radio" name="gender" value="male" class="radioRight"/>
</div>
<div id="topRightDiv" style="height:60%;left:65%;width:34%;position:absolute;">
<img src="ryp.png" alt="Smiley face" height="35" width="120"/><br>
</div>
<div id="topRightDivBottom" style="height:10%;left:65%;width:50%;top:80%;position:absolute;">
<button id="submit" type="submit" value="Pay" style="background-color:#009cde;width:131px;margin-top:13px;" onclick="login()">Pay</button><br>
</div>
</div>
<div id="leftDiv" style="height:65%;width:50%;top:25%;left:0%;position:absolute;border: 1px solid #0099FF"></div>
<div id = "rightDiv" style="height:65%;width:50%;top:25%;left:50%;position:absolute;border: 1px solid #0099FF;"></div>
<button id="blocklyDivButton" style="text-align:center">
<div id="div1" style="height:10%;width:100%;top:90%;left:0%;position:absolute;border: 1px solid #0099FF;
background-color:#ffffb3;text-align:center;vertical-align: middle;line-height: 90px;
font-family: Arial, Helvetica, sans-serif;font-size:30px;font-weight:bold;">
<b>Payments Platform</b>
</div>
</button>
</div>
<xml id="toolbox">
<block type="payment_options_list"></block>
<block type="user_identifier"></block>
<block type="account_number" name="accnum">
<value name="MESSAGE">
<block type="text">
<field name="TEXT"></field>
</block>
</value>
</block>
<block type="email_address"></block>
<block type="amount"></block>
<block type="constraints"></block>
<block type="preferences"></block>
</xml>
<script>
var primaryWorkspace = Blockly.inject('leftDiv',
{
media: '../../media/',
toolbox: document.getElementById('toolbox'),
});
// Inject secondary workspace.
var secondaryWorkspace = Blockly.inject('rightDiv',
{media: '../../media/'});
// Inject secondary workspace.
var topRightWorkspace = Blockly.inject('topRightDiv',
{media: '../../media/'});
// Listen to events on primary workspace.
primaryWorkspace.addChangeListener(mirrorEvent);
secondaryWorkspace.addChangeListener(getCoordinates);
document.getElementById("blocklyDivButton").addEventListener("click", getJson);
var json = "";
function mirrorEvent(primaryEvent) {
if (primaryEvent.type == Blockly.Events.UI) {
return; // Don't mirror UI events.
}
// Convert event to JSON. This could then be transmitted across the net.
json = primaryEvent.toJson();
}
var blockId = "";
function getCoordinates(secondaryEvent) {
if (secondaryEvent.type == Blockly.Events.UI) {
return; // Don't mirror UI events.
}
if (secondaryEvent.type == Blockly.Events.BLOCK_MOVE) {
if(secondaryEvent.newCoordinate.y < -2) {
movedBlockId = secondaryWorkspace.getBlockById(secondaryEvent.blockId).type;
generateBlock(movedBlockId);
secondaryWorkspace.removeTopBlock(movedBlockId);
}
}
}
function generateBlock(blockId) {
var newBlockResponse =
{ "blockId" : "2",
"type" : "create",
"xml" : "<block type=\"" + blockId + "\"></block>"
};
var newEvent = Blockly.Events.fromJson(newBlockResponse, topRightWorkspace);
newEvent.run(true);
}
function getJson() {
var response =
{ "blockId" : "1",
"type" : "create",
"xml" : "<block type=\"options_response_list\"><value name=\"payment_option_id\"><block type=\"po_id\"\/></value><value name=\"funding_options\"><block type=\"funding_options_list\"><value name=\"mastercard\"><block type=\"mastercard\"\/></value><value name=\"visa\"><block type=\"visa\"\/></value><value name=\"balance\"><block type=\"balance\"\/></value><value name=\"boa\"><block type=\"boa\"\/></value><value name=\"chase\"><block type=\"chase\"\/></value></block></value></block>"
};
var secondaryEvent = Blockly.Events.fromJson(response, secondaryWorkspace);
secondaryEvent.run(true);
}
</script>
</body>
</html>