forked from marva/sumorobot-web
fix toolbox update on touch screens
This commit is contained in:
parent
11e61d8f86
commit
79e9683918
17
sumorobot.js
17
sumorobot.js
@ -284,22 +284,17 @@ window.onload = function() {
|
||||
function onCodeChanged(event) {
|
||||
/* if the if condition block was created */
|
||||
if (event.type == Blockly.Events.CREATE && event.xml.getAttributeNode("type").nodeValue == "controls_if") {
|
||||
|
||||
/* remember the control_if block id */
|
||||
controlBlockId = event.blockId;
|
||||
/* automatically add the else statement input */
|
||||
var block = workspace.getBlockById(event.blockId);
|
||||
block.elseCount_ = 1;
|
||||
block.updateShape_();
|
||||
/* disable the if condition block */
|
||||
$("block[type=controls_if]").replaceWith("<block type='controls_if' disabled='true'></block>");
|
||||
workspace.updateToolbox(document.getElementById("toolbox"));
|
||||
/* if the if condition block was removed */
|
||||
} else if (event.type == Blockly.Events.DELETE && event.oldXml.getAttributeNode("type").nodeValue == "controls_if") {
|
||||
/* remove the control_if block id */
|
||||
controlBlockId = "";
|
||||
/* enable the if condition block */
|
||||
$("block[type=controls_if]").replaceWith("<block type='controls_if'></block>");
|
||||
workspace.updateToolbox(document.getElementById("toolbox"));
|
||||
}
|
||||
|
||||
/* only process change and move commands */
|
||||
@ -313,6 +308,16 @@ window.onload = function() {
|
||||
/* save the code to the local storage */
|
||||
var xml = Blockly.Xml.workspaceToDom(workspace);
|
||||
localStorage.setItem("sumorobot.currentProgram", Blockly.Xml.domToText(xml));
|
||||
|
||||
/* if control_if is used*/
|
||||
if (controlBlockId != "") {
|
||||
/* disable the if condition block */
|
||||
workspace.updateToolbox(document.getElementById("toolbox_no_if"));
|
||||
/* if no control_if is used */
|
||||
} else {
|
||||
/* enable the if condition block */
|
||||
workspace.updateToolbox(document.getElementById("toolbox"));
|
||||
}
|
||||
}
|
||||
|
||||
/* add a change listener to Blockly */
|
||||
|
Loading…
Reference in New Issue
Block a user