Added custom code block
This commit is contained in:
parent
2b323470b4
commit
9d7efa89e4
29
src/blocks/custom.js
Normal file
29
src/blocks/custom.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
var events = require("../events.js");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "Custom Code",
|
||||||
|
inputs: {
|
||||||
|
inp1: "1",
|
||||||
|
inp2: "2",
|
||||||
|
inp3: "3",
|
||||||
|
inp4: "4",
|
||||||
|
inp5: "5"
|
||||||
|
},
|
||||||
|
output: true,
|
||||||
|
execute: function(inputs, block){
|
||||||
|
eval("customFunc = function(inp1, inp2, inp3, inp4, inp5){" + block.properties.code + "}");
|
||||||
|
return customFunc(inputs.inp1, inputs.inp2, inputs.inp3, inputs.inp4, inputs.inp5);
|
||||||
|
},
|
||||||
|
pageBlock: {
|
||||||
|
html: "To access inputs, use vars inp1, inp2, etc<br><textarea name='code'></textarea>",
|
||||||
|
js: function(block){
|
||||||
|
if(block.properties.code){
|
||||||
|
block.elem.find("textarea").val(block.properties.code);
|
||||||
|
}
|
||||||
|
$(block.elem).find("textarea").keyup(function(){
|
||||||
|
block.properties.code = block.elem.find("textarea").val();
|
||||||
|
events.emit("inputChanged");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ var blocks = [
|
|||||||
"transpositionReverse",
|
"transpositionReverse",
|
||||||
"substitution",
|
"substitution",
|
||||||
"frequency",
|
"frequency",
|
||||||
|
"custom",
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = blocks.reduce((blocks, block)=>{
|
module.exports = blocks.reduce((blocks, block)=>{
|
||||||
|
@ -14,10 +14,7 @@ function resolveOutput(block, cache){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var output = "";
|
var output = blocks[block.type].execute(inputValues, block);
|
||||||
if(Object.keys(blocks[block.type].inputs).length == Object.keys(inputValues).length){ //only execute if all inputs are present
|
|
||||||
output = blocks[block.type].execute(inputValues, block);
|
|
||||||
}
|
|
||||||
cache[block.id] = output;
|
cache[block.id] = output;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user