Blockly.inject('blocklyDiv', {
toolbox: document.getElementById('toolbox'),
scrollbars: false
});
function run() {
Blockly.JavaScript.addReservedWords('code');
var code = Blockly.JavaScript.workspaceToCode(workspace);
try {
eval(code);
} catch (e) {
alert(e);
}
}
Blockly.Blocks['if_then'] = {
init: function() {
this.appendValueInput("if")
.setCheck(null)
.appendField("if");
this.appendStatementInput("then")
.setCheck(null)
.appendField("then");
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(20);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks['if_then_else'] = {
init: function() {
this.appendValueInput("if")
.setCheck(null)
.appendField("if");
this.appendStatementInput("then")
.setCheck(null)
.appendField("then");
this.appendStatementInput("else")
.setCheck(null)
.appendField("else");
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(20);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks['for_each_number'] = {
init: function() {
this.appendValueInput("for")
.setCheck(null)
.appendField("for each")
.appendField(new Blockly.FieldTextInput("number"), "name")
.appendField("from");
this.appendValueInput("to")
.setCheck(null)
.setAlign(Blockly.ALIGN_RIGHT)
.appendField("to");
this.appendValueInput("by")
.setCheck(null)
.setAlign(Blockly.ALIGN_RIGHT)
.appendField("by");
this.appendStatementInput("NAME")
.setCheck(null)
.appendField("do");
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(20);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks['for_each_item'] = {
init: function() {
this.appendValueInput("for")
.setCheck(null)
.appendField("for each")
.appendField(new Blockly.FieldTextInput("item"), "name")
.appendField("in list");
this.appendStatementInput("NAME")
.setCheck(null)
.appendField("do");
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(20);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks['alert'] = {
init: function() {
this.appendDummyInput()
.appendField("alert")
.appendField(new Blockly.FieldTextInput("text"), "text");
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(20);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['alert'] = function(block) {
var text_text = block.getFieldValue('text');
var code = 'window.alert(Hii)';
return code;
};