forked from marva/sumorobot-web
		
	fix toolbox update on touch screens
This commit is contained in:
		
							
								
								
									
										17
									
								
								sumorobot.js
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								sumorobot.js
									
									
									
									
									
								
							@@ -284,22 +284,17 @@ window.onload = function() {
 | 
				
			|||||||
    function onCodeChanged(event) {
 | 
					    function onCodeChanged(event) {
 | 
				
			||||||
        /* if the if condition block was created */
 | 
					        /* if the if condition block was created */
 | 
				
			||||||
        if (event.type == Blockly.Events.CREATE && event.xml.getAttributeNode("type").nodeValue == "controls_if") {
 | 
					        if (event.type == Blockly.Events.CREATE && event.xml.getAttributeNode("type").nodeValue == "controls_if") {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* remember the control_if block id */
 | 
					            /* remember the control_if block id */
 | 
				
			||||||
            controlBlockId = event.blockId;
 | 
					            controlBlockId = event.blockId;
 | 
				
			||||||
            /* automatically add the else statement input */
 | 
					            /* automatically add the else statement input */
 | 
				
			||||||
            var block = workspace.getBlockById(event.blockId);
 | 
					            var block = workspace.getBlockById(event.blockId);
 | 
				
			||||||
            block.elseCount_ = 1;
 | 
					            block.elseCount_ = 1;
 | 
				
			||||||
            block.updateShape_();
 | 
					            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 */
 | 
					        /* if the if condition block was removed */
 | 
				
			||||||
        } else if (event.type == Blockly.Events.DELETE && event.oldXml.getAttributeNode("type").nodeValue == "controls_if") {
 | 
					        } else if (event.type == Blockly.Events.DELETE && event.oldXml.getAttributeNode("type").nodeValue == "controls_if") {
 | 
				
			||||||
            /* remove the control_if block id */
 | 
					            /* remove the control_if block id */
 | 
				
			||||||
            controlBlockId = "";
 | 
					            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 */
 | 
					        /* only process change and move commands */
 | 
				
			||||||
@@ -313,6 +308,16 @@ window.onload = function() {
 | 
				
			|||||||
        /* save the code to the local storage */
 | 
					        /* save the code to the local storage */
 | 
				
			||||||
        var xml = Blockly.Xml.workspaceToDom(workspace);
 | 
					        var xml = Blockly.Xml.workspaceToDom(workspace);
 | 
				
			||||||
        localStorage.setItem("sumorobot.currentProgram", Blockly.Xml.domToText(xml));
 | 
					        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 */
 | 
					    /* add a change listener to Blockly */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user