diff --git a/sumorobot.js b/sumorobot.js
index 1039d6b..be09058 100755
--- a/sumorobot.js
+++ b/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("");
- 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("");
- 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 */