Added custom code block
This commit is contained in:
		
							
								
								
									
										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",
 | 
			
		||||
  "substitution",
 | 
			
		||||
  "frequency",
 | 
			
		||||
  "custom",
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
module.exports = blocks.reduce((blocks, block)=>{
 | 
			
		||||
 
 | 
			
		||||
@@ -14,10 +14,7 @@ function resolveOutput(block, cache){
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  var output = "";
 | 
			
		||||
  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);
 | 
			
		||||
  }
 | 
			
		||||
  var output = blocks[block.type].execute(inputValues, block);
 | 
			
		||||
  cache[block.id] = output;
 | 
			
		||||
 | 
			
		||||
  return output;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user