id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
18,900
webduinoio/webduino-blockly
components/blockly-src/blocks/text.js
function() { var container = document.createElement('mutation'); var isAt1 = this.getInput('AT1').type == Blockly.INPUT_VALUE; container.setAttribute('at1', isAt1); var isAt2 = this.getInput('AT2').type == Blockly.INPUT_VALUE; container.setAttribute('at2', isAt2); return container; }
javascript
function() { var container = document.createElement('mutation'); var isAt1 = this.getInput('AT1').type == Blockly.INPUT_VALUE; container.setAttribute('at1', isAt1); var isAt2 = this.getInput('AT2').type == Blockly.INPUT_VALUE; container.setAttribute('at2', isAt2); return container; }
[ "function", "(", ")", "{", "var", "container", "=", "document", ".", "createElement", "(", "'mutation'", ")", ";", "var", "isAt1", "=", "this", ".", "getInput", "(", "'AT1'", ")", ".", "type", "==", "Blockly", ".", "INPUT_VALUE", ";", "container", ".", "setAttribute", "(", "'at1'", ",", "isAt1", ")", ";", "var", "isAt2", "=", "this", ".", "getInput", "(", "'AT2'", ")", ".", "type", "==", "Blockly", ".", "INPUT_VALUE", ";", "container", ".", "setAttribute", "(", "'at2'", ",", "isAt2", ")", ";", "return", "container", ";", "}" ]
Create XML to represent whether there are 'AT' inputs. @return {!Element} XML storage element. @this Blockly.Block
[ "Create", "XML", "to", "represent", "whether", "there", "are", "AT", "inputs", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/text.js#L450-L457
18,901
webduinoio/webduino-blockly
components/blockly-src/blocks/text.js
function(xmlElement) { var isAt1 = (xmlElement.getAttribute('at1') == 'true'); var isAt2 = (xmlElement.getAttribute('at2') == 'true'); this.updateAt_(1, isAt1); this.updateAt_(2, isAt2); }
javascript
function(xmlElement) { var isAt1 = (xmlElement.getAttribute('at1') == 'true'); var isAt2 = (xmlElement.getAttribute('at2') == 'true'); this.updateAt_(1, isAt1); this.updateAt_(2, isAt2); }
[ "function", "(", "xmlElement", ")", "{", "var", "isAt1", "=", "(", "xmlElement", ".", "getAttribute", "(", "'at1'", ")", "==", "'true'", ")", ";", "var", "isAt2", "=", "(", "xmlElement", ".", "getAttribute", "(", "'at2'", ")", "==", "'true'", ")", ";", "this", ".", "updateAt_", "(", "1", ",", "isAt1", ")", ";", "this", ".", "updateAt_", "(", "2", ",", "isAt2", ")", ";", "}" ]
Parse XML to restore the 'AT' inputs. @param {!Element} xmlElement XML storage element. @this Blockly.Block
[ "Parse", "XML", "to", "restore", "the", "AT", "inputs", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/text.js#L463-L468
18,902
webduinoio/webduino-blockly
components/blockly-src/blocks/text.js
function() { var OPERATORS = [[Blockly.Msg.TEXT_CHANGECASE_OPERATOR_UPPERCASE, 'UPPERCASE'], [Blockly.Msg.TEXT_CHANGECASE_OPERATOR_LOWERCASE, 'LOWERCASE'], [Blockly.Msg.TEXT_CHANGECASE_OPERATOR_TITLECASE, 'TITLECASE']]; this.setHelpUrl(Blockly.Msg.TEXT_CHANGECASE_HELPURL); this.setColour(Blockly.Blocks.texts.HUE); this.appendValueInput('TEXT') .setCheck('String') .appendField(new Blockly.FieldDropdown(OPERATORS), 'CASE'); this.setOutput(true, 'String'); this.setTooltip(Blockly.Msg.TEXT_CHANGECASE_TOOLTIP); }
javascript
function() { var OPERATORS = [[Blockly.Msg.TEXT_CHANGECASE_OPERATOR_UPPERCASE, 'UPPERCASE'], [Blockly.Msg.TEXT_CHANGECASE_OPERATOR_LOWERCASE, 'LOWERCASE'], [Blockly.Msg.TEXT_CHANGECASE_OPERATOR_TITLECASE, 'TITLECASE']]; this.setHelpUrl(Blockly.Msg.TEXT_CHANGECASE_HELPURL); this.setColour(Blockly.Blocks.texts.HUE); this.appendValueInput('TEXT') .setCheck('String') .appendField(new Blockly.FieldDropdown(OPERATORS), 'CASE'); this.setOutput(true, 'String'); this.setTooltip(Blockly.Msg.TEXT_CHANGECASE_TOOLTIP); }
[ "function", "(", ")", "{", "var", "OPERATORS", "=", "[", "[", "Blockly", ".", "Msg", ".", "TEXT_CHANGECASE_OPERATOR_UPPERCASE", ",", "'UPPERCASE'", "]", ",", "[", "Blockly", ".", "Msg", ".", "TEXT_CHANGECASE_OPERATOR_LOWERCASE", ",", "'LOWERCASE'", "]", ",", "[", "Blockly", ".", "Msg", ".", "TEXT_CHANGECASE_OPERATOR_TITLECASE", ",", "'TITLECASE'", "]", "]", ";", "this", ".", "setHelpUrl", "(", "Blockly", ".", "Msg", ".", "TEXT_CHANGECASE_HELPURL", ")", ";", "this", ".", "setColour", "(", "Blockly", ".", "Blocks", ".", "texts", ".", "HUE", ")", ";", "this", ".", "appendValueInput", "(", "'TEXT'", ")", ".", "setCheck", "(", "'String'", ")", ".", "appendField", "(", "new", "Blockly", ".", "FieldDropdown", "(", "OPERATORS", ")", ",", "'CASE'", ")", ";", "this", ".", "setOutput", "(", "true", ",", "'String'", ")", ";", "this", ".", "setTooltip", "(", "Blockly", ".", "Msg", ".", "TEXT_CHANGECASE_TOOLTIP", ")", ";", "}" ]
Block for changing capitalization. @this Blockly.Block
[ "Block", "for", "changing", "capitalization", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/text.js#L524-L536
18,903
webduinoio/webduino-blockly
components/blockly-src/blocks/text.js
function() { this.jsonInit({ "message0": Blockly.Msg.TEXT_PRINT_TITLE, "args0": [ { "type": "input_value", "name": "TEXT" } ], "previousStatement": null, "nextStatement": null, "colour": Blockly.Blocks.texts.HUE, "tooltip": Blockly.Msg.TEXT_PRINT_TOOLTIP, "helpUrl": Blockly.Msg.TEXT_PRINT_HELPURL }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.TEXT_PRINT_TITLE, "args0": [ { "type": "input_value", "name": "TEXT" } ], "previousStatement": null, "nextStatement": null, "colour": Blockly.Blocks.texts.HUE, "tooltip": Blockly.Msg.TEXT_PRINT_TOOLTIP, "helpUrl": Blockly.Msg.TEXT_PRINT_HELPURL }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "TEXT_PRINT_TITLE", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"TEXT\"", "}", "]", ",", "\"previousStatement\"", ":", "null", ",", "\"nextStatement\"", ":", "null", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "texts", ".", "HUE", ",", "\"tooltip\"", ":", "Blockly", ".", "Msg", ".", "TEXT_PRINT_TOOLTIP", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "TEXT_PRINT_HELPURL", "}", ")", ";", "}" ]
Block for print statement. @this Blockly.Block
[ "Block", "for", "print", "statement", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/text.js#L564-L579
18,904
webduinoio/webduino-blockly
components/blockly-src/blocks/logic.js
function(xmlElement) { this.elseifCount_ = parseInt(xmlElement.getAttribute('elseif'), 10) || 0; this.elseCount_ = parseInt(xmlElement.getAttribute('else'), 10) || 0; this.updateShape_(); }
javascript
function(xmlElement) { this.elseifCount_ = parseInt(xmlElement.getAttribute('elseif'), 10) || 0; this.elseCount_ = parseInt(xmlElement.getAttribute('else'), 10) || 0; this.updateShape_(); }
[ "function", "(", "xmlElement", ")", "{", "this", ".", "elseifCount_", "=", "parseInt", "(", "xmlElement", ".", "getAttribute", "(", "'elseif'", ")", ",", "10", ")", "||", "0", ";", "this", ".", "elseCount_", "=", "parseInt", "(", "xmlElement", ".", "getAttribute", "(", "'else'", ")", ",", "10", ")", "||", "0", ";", "this", ".", "updateShape_", "(", ")", ";", "}" ]
Parse XML to restore the else-if and else inputs. @param {!Element} xmlElement XML storage element. @this Blockly.Block
[ "Parse", "XML", "to", "restore", "the", "else", "-", "if", "and", "else", "inputs", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/logic.js#L94-L98
18,905
webduinoio/webduino-blockly
components/blockly-src/blocks/logic.js
function(containerBlock) { var clauseBlock = containerBlock.nextConnection.targetBlock(); var i = 1; while (clauseBlock) { switch (clauseBlock.type) { case 'controls_if_elseif': var inputIf = this.getInput('IF' + i); var inputDo = this.getInput('DO' + i); clauseBlock.valueConnection_ = inputIf && inputIf.connection.targetConnection; clauseBlock.statementConnection_ = inputDo && inputDo.connection.targetConnection; i++; break; case 'controls_if_else': var inputDo = this.getInput('ELSE'); clauseBlock.statementConnection_ = inputDo && inputDo.connection.targetConnection; break; default: throw 'Unknown block type.'; } clauseBlock = clauseBlock.nextConnection && clauseBlock.nextConnection.targetBlock(); } }
javascript
function(containerBlock) { var clauseBlock = containerBlock.nextConnection.targetBlock(); var i = 1; while (clauseBlock) { switch (clauseBlock.type) { case 'controls_if_elseif': var inputIf = this.getInput('IF' + i); var inputDo = this.getInput('DO' + i); clauseBlock.valueConnection_ = inputIf && inputIf.connection.targetConnection; clauseBlock.statementConnection_ = inputDo && inputDo.connection.targetConnection; i++; break; case 'controls_if_else': var inputDo = this.getInput('ELSE'); clauseBlock.statementConnection_ = inputDo && inputDo.connection.targetConnection; break; default: throw 'Unknown block type.'; } clauseBlock = clauseBlock.nextConnection && clauseBlock.nextConnection.targetBlock(); } }
[ "function", "(", "containerBlock", ")", "{", "var", "clauseBlock", "=", "containerBlock", ".", "nextConnection", ".", "targetBlock", "(", ")", ";", "var", "i", "=", "1", ";", "while", "(", "clauseBlock", ")", "{", "switch", "(", "clauseBlock", ".", "type", ")", "{", "case", "'controls_if_elseif'", ":", "var", "inputIf", "=", "this", ".", "getInput", "(", "'IF'", "+", "i", ")", ";", "var", "inputDo", "=", "this", ".", "getInput", "(", "'DO'", "+", "i", ")", ";", "clauseBlock", ".", "valueConnection_", "=", "inputIf", "&&", "inputIf", ".", "connection", ".", "targetConnection", ";", "clauseBlock", ".", "statementConnection_", "=", "inputDo", "&&", "inputDo", ".", "connection", ".", "targetConnection", ";", "i", "++", ";", "break", ";", "case", "'controls_if_else'", ":", "var", "inputDo", "=", "this", ".", "getInput", "(", "'ELSE'", ")", ";", "clauseBlock", ".", "statementConnection_", "=", "inputDo", "&&", "inputDo", ".", "connection", ".", "targetConnection", ";", "break", ";", "default", ":", "throw", "'Unknown block type.'", ";", "}", "clauseBlock", "=", "clauseBlock", ".", "nextConnection", "&&", "clauseBlock", ".", "nextConnection", ".", "targetBlock", "(", ")", ";", "}", "}" ]
Store pointers to any connected child blocks. @param {!Blockly.Block} containerBlock Root block in mutator. @this Blockly.Block
[ "Store", "pointers", "to", "any", "connected", "child", "blocks", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/logic.js#L165-L190
18,906
webduinoio/webduino-blockly
components/blockly-src/blocks/logic.js
function() { this.setColour(Blockly.Blocks.logic.HUE); this.appendDummyInput() .appendField(Blockly.Msg.CONTROLS_IF_IF_TITLE_IF); this.setNextStatement(true); this.setTooltip(Blockly.Msg.CONTROLS_IF_IF_TOOLTIP); this.contextMenu = false; }
javascript
function() { this.setColour(Blockly.Blocks.logic.HUE); this.appendDummyInput() .appendField(Blockly.Msg.CONTROLS_IF_IF_TITLE_IF); this.setNextStatement(true); this.setTooltip(Blockly.Msg.CONTROLS_IF_IF_TOOLTIP); this.contextMenu = false; }
[ "function", "(", ")", "{", "this", ".", "setColour", "(", "Blockly", ".", "Blocks", ".", "logic", ".", "HUE", ")", ";", "this", ".", "appendDummyInput", "(", ")", ".", "appendField", "(", "Blockly", ".", "Msg", ".", "CONTROLS_IF_IF_TITLE_IF", ")", ";", "this", ".", "setNextStatement", "(", "true", ")", ";", "this", ".", "setTooltip", "(", "Blockly", ".", "Msg", ".", "CONTROLS_IF_IF_TOOLTIP", ")", ";", "this", ".", "contextMenu", "=", "false", ";", "}" ]
Mutator block for if container. @this Blockly.Block
[ "Mutator", "block", "for", "if", "container", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/logic.js#L227-L234
18,907
webduinoio/webduino-blockly
components/blockly-src/blocks/logic.js
function() { this.setColour(Blockly.Blocks.logic.HUE); this.appendDummyInput() .appendField(Blockly.Msg.CONTROLS_IF_ELSEIF_TITLE_ELSEIF); this.setPreviousStatement(true); this.setNextStatement(true); this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSEIF_TOOLTIP); this.contextMenu = false; }
javascript
function() { this.setColour(Blockly.Blocks.logic.HUE); this.appendDummyInput() .appendField(Blockly.Msg.CONTROLS_IF_ELSEIF_TITLE_ELSEIF); this.setPreviousStatement(true); this.setNextStatement(true); this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSEIF_TOOLTIP); this.contextMenu = false; }
[ "function", "(", ")", "{", "this", ".", "setColour", "(", "Blockly", ".", "Blocks", ".", "logic", ".", "HUE", ")", ";", "this", ".", "appendDummyInput", "(", ")", ".", "appendField", "(", "Blockly", ".", "Msg", ".", "CONTROLS_IF_ELSEIF_TITLE_ELSEIF", ")", ";", "this", ".", "setPreviousStatement", "(", "true", ")", ";", "this", ".", "setNextStatement", "(", "true", ")", ";", "this", ".", "setTooltip", "(", "Blockly", ".", "Msg", ".", "CONTROLS_IF_ELSEIF_TOOLTIP", ")", ";", "this", ".", "contextMenu", "=", "false", ";", "}" ]
Mutator bolck for else-if condition. @this Blockly.Block
[ "Mutator", "bolck", "for", "else", "-", "if", "condition", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/logic.js#L242-L250
18,908
webduinoio/webduino-blockly
components/blockly-src/blocks/logic.js
function() { this.setColour(Blockly.Blocks.logic.HUE); this.appendDummyInput() .appendField(Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE); this.setPreviousStatement(true); this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSE_TOOLTIP); this.contextMenu = false; }
javascript
function() { this.setColour(Blockly.Blocks.logic.HUE); this.appendDummyInput() .appendField(Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE); this.setPreviousStatement(true); this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSE_TOOLTIP); this.contextMenu = false; }
[ "function", "(", ")", "{", "this", ".", "setColour", "(", "Blockly", ".", "Blocks", ".", "logic", ".", "HUE", ")", ";", "this", ".", "appendDummyInput", "(", ")", ".", "appendField", "(", "Blockly", ".", "Msg", ".", "CONTROLS_IF_ELSE_TITLE_ELSE", ")", ";", "this", ".", "setPreviousStatement", "(", "true", ")", ";", "this", ".", "setTooltip", "(", "Blockly", ".", "Msg", ".", "CONTROLS_IF_ELSE_TOOLTIP", ")", ";", "this", ".", "contextMenu", "=", "false", ";", "}" ]
Mutator block for else condition. @this Blockly.Block
[ "Mutator", "block", "for", "else", "condition", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/logic.js#L258-L265
18,909
webduinoio/webduino-blockly
components/blockly-src/blocks/logic.js
function() { var OPERATORS = this.RTL ? [ ['=', 'EQ'], ['\u2260', 'NEQ'], ['>', 'LT'], ['\u2265', 'LTE'], ['<', 'GT'], ['\u2264', 'GTE'] ] : [ ['=', 'EQ'], ['\u2260', 'NEQ'], ['<', 'LT'], ['\u2264', 'LTE'], ['>', 'GT'], ['\u2265', 'GTE'] ]; this.setHelpUrl(Blockly.Msg.LOGIC_COMPARE_HELPURL); this.setColour(Blockly.Blocks.logic.HUE); this.setOutput(true, 'Boolean'); this.appendValueInput('A'); this.appendValueInput('B') .appendField(new Blockly.FieldDropdown(OPERATORS), 'OP'); this.setInputsInline(true); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; this.setTooltip(function() { var op = thisBlock.getFieldValue('OP'); var TOOLTIPS = { 'EQ': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_EQ, 'NEQ': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_NEQ, 'LT': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LT, 'LTE': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LTE, 'GT': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GT, 'GTE': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GTE }; return TOOLTIPS[op]; }); this.prevBlocks_ = [null, null]; }
javascript
function() { var OPERATORS = this.RTL ? [ ['=', 'EQ'], ['\u2260', 'NEQ'], ['>', 'LT'], ['\u2265', 'LTE'], ['<', 'GT'], ['\u2264', 'GTE'] ] : [ ['=', 'EQ'], ['\u2260', 'NEQ'], ['<', 'LT'], ['\u2264', 'LTE'], ['>', 'GT'], ['\u2265', 'GTE'] ]; this.setHelpUrl(Blockly.Msg.LOGIC_COMPARE_HELPURL); this.setColour(Blockly.Blocks.logic.HUE); this.setOutput(true, 'Boolean'); this.appendValueInput('A'); this.appendValueInput('B') .appendField(new Blockly.FieldDropdown(OPERATORS), 'OP'); this.setInputsInline(true); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; this.setTooltip(function() { var op = thisBlock.getFieldValue('OP'); var TOOLTIPS = { 'EQ': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_EQ, 'NEQ': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_NEQ, 'LT': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LT, 'LTE': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LTE, 'GT': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GT, 'GTE': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GTE }; return TOOLTIPS[op]; }); this.prevBlocks_ = [null, null]; }
[ "function", "(", ")", "{", "var", "OPERATORS", "=", "this", ".", "RTL", "?", "[", "[", "'='", ",", "'EQ'", "]", ",", "[", "'\\u2260'", ",", "'NEQ'", "]", ",", "[", "'>'", ",", "'LT'", "]", ",", "[", "'\\u2265'", ",", "'LTE'", "]", ",", "[", "'<'", ",", "'GT'", "]", ",", "[", "'\\u2264'", ",", "'GTE'", "]", "]", ":", "[", "[", "'='", ",", "'EQ'", "]", ",", "[", "'\\u2260'", ",", "'NEQ'", "]", ",", "[", "'<'", ",", "'LT'", "]", ",", "[", "'\\u2264'", ",", "'LTE'", "]", ",", "[", "'>'", ",", "'GT'", "]", ",", "[", "'\\u2265'", ",", "'GTE'", "]", "]", ";", "this", ".", "setHelpUrl", "(", "Blockly", ".", "Msg", ".", "LOGIC_COMPARE_HELPURL", ")", ";", "this", ".", "setColour", "(", "Blockly", ".", "Blocks", ".", "logic", ".", "HUE", ")", ";", "this", ".", "setOutput", "(", "true", ",", "'Boolean'", ")", ";", "this", ".", "appendValueInput", "(", "'A'", ")", ";", "this", ".", "appendValueInput", "(", "'B'", ")", ".", "appendField", "(", "new", "Blockly", ".", "FieldDropdown", "(", "OPERATORS", ")", ",", "'OP'", ")", ";", "this", ".", "setInputsInline", "(", "true", ")", ";", "// Assign 'this' to a variable for use in the tooltip closure below.", "var", "thisBlock", "=", "this", ";", "this", ".", "setTooltip", "(", "function", "(", ")", "{", "var", "op", "=", "thisBlock", ".", "getFieldValue", "(", "'OP'", ")", ";", "var", "TOOLTIPS", "=", "{", "'EQ'", ":", "Blockly", ".", "Msg", ".", "LOGIC_COMPARE_TOOLTIP_EQ", ",", "'NEQ'", ":", "Blockly", ".", "Msg", ".", "LOGIC_COMPARE_TOOLTIP_NEQ", ",", "'LT'", ":", "Blockly", ".", "Msg", ".", "LOGIC_COMPARE_TOOLTIP_LT", ",", "'LTE'", ":", "Blockly", ".", "Msg", ".", "LOGIC_COMPARE_TOOLTIP_LTE", ",", "'GT'", ":", "Blockly", ".", "Msg", ".", "LOGIC_COMPARE_TOOLTIP_GT", ",", "'GTE'", ":", "Blockly", ".", "Msg", ".", "LOGIC_COMPARE_TOOLTIP_GTE", "}", ";", "return", "TOOLTIPS", "[", "op", "]", ";", "}", ")", ";", "this", ".", "prevBlocks_", "=", "[", "null", ",", "null", "]", ";", "}" ]
Block for comparison operator. @this Blockly.Block
[ "Block", "for", "comparison", "operator", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/logic.js#L273-L311
18,910
webduinoio/webduino-blockly
components/blockly-src/blocks/logic.js
function(e) { var blockA = this.getInputTargetBlock('A'); var blockB = this.getInputTargetBlock('B'); // Disconnect blocks that existed prior to this change if they don't match. if (blockA && blockB && !blockA.outputConnection.checkType_(blockB.outputConnection)) { // Mismatch between two inputs. Disconnect previous and bump it away. // Ensure that any disconnections are grouped with the causing event. Blockly.Events.setGroup(e.group); for (var i = 0; i < this.prevBlocks_.length; i++) { var block = this.prevBlocks_[i]; if (block === blockA || block === blockB) { block.unplug(); block.bumpNeighbours_(); } } Blockly.Events.setGroup(false); } this.prevBlocks_[0] = blockA; this.prevBlocks_[1] = blockB; }
javascript
function(e) { var blockA = this.getInputTargetBlock('A'); var blockB = this.getInputTargetBlock('B'); // Disconnect blocks that existed prior to this change if they don't match. if (blockA && blockB && !blockA.outputConnection.checkType_(blockB.outputConnection)) { // Mismatch between two inputs. Disconnect previous and bump it away. // Ensure that any disconnections are grouped with the causing event. Blockly.Events.setGroup(e.group); for (var i = 0; i < this.prevBlocks_.length; i++) { var block = this.prevBlocks_[i]; if (block === blockA || block === blockB) { block.unplug(); block.bumpNeighbours_(); } } Blockly.Events.setGroup(false); } this.prevBlocks_[0] = blockA; this.prevBlocks_[1] = blockB; }
[ "function", "(", "e", ")", "{", "var", "blockA", "=", "this", ".", "getInputTargetBlock", "(", "'A'", ")", ";", "var", "blockB", "=", "this", ".", "getInputTargetBlock", "(", "'B'", ")", ";", "// Disconnect blocks that existed prior to this change if they don't match.", "if", "(", "blockA", "&&", "blockB", "&&", "!", "blockA", ".", "outputConnection", ".", "checkType_", "(", "blockB", ".", "outputConnection", ")", ")", "{", "// Mismatch between two inputs. Disconnect previous and bump it away.", "// Ensure that any disconnections are grouped with the causing event.", "Blockly", ".", "Events", ".", "setGroup", "(", "e", ".", "group", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "this", ".", "prevBlocks_", ".", "length", ";", "i", "++", ")", "{", "var", "block", "=", "this", ".", "prevBlocks_", "[", "i", "]", ";", "if", "(", "block", "===", "blockA", "||", "block", "===", "blockB", ")", "{", "block", ".", "unplug", "(", ")", ";", "block", ".", "bumpNeighbours_", "(", ")", ";", "}", "}", "Blockly", ".", "Events", ".", "setGroup", "(", "false", ")", ";", "}", "this", ".", "prevBlocks_", "[", "0", "]", "=", "blockA", ";", "this", ".", "prevBlocks_", "[", "1", "]", "=", "blockB", ";", "}" ]
Called whenever anything on the workspace changes. Prevent mismatched types from being compared. @param {!Blockly.Events.Abstract} e Change event. @this Blockly.Block
[ "Called", "whenever", "anything", "on", "the", "workspace", "changes", ".", "Prevent", "mismatched", "types", "from", "being", "compared", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/logic.js#L318-L338
18,911
webduinoio/webduino-blockly
components/blockly-src/blocks/logic.js
function() { this.jsonInit({ "message0": Blockly.Msg.LOGIC_NEGATE_TITLE, "args0": [ { "type": "input_value", "name": "BOOL", "check": "Boolean" } ], "output": "Boolean", "colour": Blockly.Blocks.logic.HUE, "tooltip": Blockly.Msg.LOGIC_NEGATE_TOOLTIP, "helpUrl": Blockly.Msg.LOGIC_NEGATE_HELPURL }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.LOGIC_NEGATE_TITLE, "args0": [ { "type": "input_value", "name": "BOOL", "check": "Boolean" } ], "output": "Boolean", "colour": Blockly.Blocks.logic.HUE, "tooltip": Blockly.Msg.LOGIC_NEGATE_TOOLTIP, "helpUrl": Blockly.Msg.LOGIC_NEGATE_HELPURL }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "LOGIC_NEGATE_TITLE", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"BOOL\"", ",", "\"check\"", ":", "\"Boolean\"", "}", "]", ",", "\"output\"", ":", "\"Boolean\"", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "logic", ".", "HUE", ",", "\"tooltip\"", ":", "Blockly", ".", "Msg", ".", "LOGIC_NEGATE_TOOLTIP", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "LOGIC_NEGATE_HELPURL", "}", ")", ";", "}" ]
Block for negation. @this Blockly.Block
[ "Block", "for", "negation", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/logic.js#L377-L392
18,912
webduinoio/webduino-blockly
components/blockly-src/blocks/logic.js
function() { this.jsonInit({ "message0": Blockly.Msg.LOGIC_NULL, "output": null, "colour": Blockly.Blocks.logic.HUE, "tooltip": Blockly.Msg.LOGIC_NULL_TOOLTIP, "helpUrl": Blockly.Msg.LOGIC_NULL_HELPURL }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.LOGIC_NULL, "output": null, "colour": Blockly.Blocks.logic.HUE, "tooltip": Blockly.Msg.LOGIC_NULL_TOOLTIP, "helpUrl": Blockly.Msg.LOGIC_NULL_HELPURL }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "LOGIC_NULL", ",", "\"output\"", ":", "null", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "logic", ".", "HUE", ",", "\"tooltip\"", ":", "Blockly", ".", "Msg", ".", "LOGIC_NULL_TOOLTIP", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "LOGIC_NULL_HELPURL", "}", ")", ";", "}" ]
Block for null data type. @this Blockly.Block
[ "Block", "for", "null", "data", "type", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/logic.js#L426-L434
18,913
webduinoio/webduino-blockly
components/blockly-src/blocks/logic.js
function() { this.setHelpUrl(Blockly.Msg.LOGIC_TERNARY_HELPURL); this.setColour(Blockly.Blocks.logic.HUE); this.appendValueInput('IF') .setCheck('Boolean') .appendField(Blockly.Msg.LOGIC_TERNARY_CONDITION); this.appendValueInput('THEN') .appendField(Blockly.Msg.LOGIC_TERNARY_IF_TRUE); this.appendValueInput('ELSE') .appendField(Blockly.Msg.LOGIC_TERNARY_IF_FALSE); this.setOutput(true); this.setTooltip(Blockly.Msg.LOGIC_TERNARY_TOOLTIP); this.prevParentConnection_ = null; }
javascript
function() { this.setHelpUrl(Blockly.Msg.LOGIC_TERNARY_HELPURL); this.setColour(Blockly.Blocks.logic.HUE); this.appendValueInput('IF') .setCheck('Boolean') .appendField(Blockly.Msg.LOGIC_TERNARY_CONDITION); this.appendValueInput('THEN') .appendField(Blockly.Msg.LOGIC_TERNARY_IF_TRUE); this.appendValueInput('ELSE') .appendField(Blockly.Msg.LOGIC_TERNARY_IF_FALSE); this.setOutput(true); this.setTooltip(Blockly.Msg.LOGIC_TERNARY_TOOLTIP); this.prevParentConnection_ = null; }
[ "function", "(", ")", "{", "this", ".", "setHelpUrl", "(", "Blockly", ".", "Msg", ".", "LOGIC_TERNARY_HELPURL", ")", ";", "this", ".", "setColour", "(", "Blockly", ".", "Blocks", ".", "logic", ".", "HUE", ")", ";", "this", ".", "appendValueInput", "(", "'IF'", ")", ".", "setCheck", "(", "'Boolean'", ")", ".", "appendField", "(", "Blockly", ".", "Msg", ".", "LOGIC_TERNARY_CONDITION", ")", ";", "this", ".", "appendValueInput", "(", "'THEN'", ")", ".", "appendField", "(", "Blockly", ".", "Msg", ".", "LOGIC_TERNARY_IF_TRUE", ")", ";", "this", ".", "appendValueInput", "(", "'ELSE'", ")", ".", "appendField", "(", "Blockly", ".", "Msg", ".", "LOGIC_TERNARY_IF_FALSE", ")", ";", "this", ".", "setOutput", "(", "true", ")", ";", "this", ".", "setTooltip", "(", "Blockly", ".", "Msg", ".", "LOGIC_TERNARY_TOOLTIP", ")", ";", "this", ".", "prevParentConnection_", "=", "null", ";", "}" ]
Block for ternary operator. @this Blockly.Block
[ "Block", "for", "ternary", "operator", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/logic.js#L442-L455
18,914
webduinoio/webduino-blockly
components/blockly-src/blocks/logic.js
function(e) { var blockA = this.getInputTargetBlock('THEN'); var blockB = this.getInputTargetBlock('ELSE'); var parentConnection = this.outputConnection.targetConnection; // Disconnect blocks that existed prior to this change if they don't match. if ((blockA || blockB) && parentConnection) { for (var i = 0; i < 2; i++) { var block = (i == 1) ? blockA : blockB; if (block && !block.outputConnection.checkType_(parentConnection)) { // Ensure that any disconnections are grouped with the causing event. Blockly.Events.setGroup(e.group); if (parentConnection === this.prevParentConnection_) { this.unplug(); parentConnection.getSourceBlock().bumpNeighbours_(); } else { block.unplug(); block.bumpNeighbours_(); } Blockly.Events.setGroup(false); } } } this.prevParentConnection_ = parentConnection; }
javascript
function(e) { var blockA = this.getInputTargetBlock('THEN'); var blockB = this.getInputTargetBlock('ELSE'); var parentConnection = this.outputConnection.targetConnection; // Disconnect blocks that existed prior to this change if they don't match. if ((blockA || blockB) && parentConnection) { for (var i = 0; i < 2; i++) { var block = (i == 1) ? blockA : blockB; if (block && !block.outputConnection.checkType_(parentConnection)) { // Ensure that any disconnections are grouped with the causing event. Blockly.Events.setGroup(e.group); if (parentConnection === this.prevParentConnection_) { this.unplug(); parentConnection.getSourceBlock().bumpNeighbours_(); } else { block.unplug(); block.bumpNeighbours_(); } Blockly.Events.setGroup(false); } } } this.prevParentConnection_ = parentConnection; }
[ "function", "(", "e", ")", "{", "var", "blockA", "=", "this", ".", "getInputTargetBlock", "(", "'THEN'", ")", ";", "var", "blockB", "=", "this", ".", "getInputTargetBlock", "(", "'ELSE'", ")", ";", "var", "parentConnection", "=", "this", ".", "outputConnection", ".", "targetConnection", ";", "// Disconnect blocks that existed prior to this change if they don't match.", "if", "(", "(", "blockA", "||", "blockB", ")", "&&", "parentConnection", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "2", ";", "i", "++", ")", "{", "var", "block", "=", "(", "i", "==", "1", ")", "?", "blockA", ":", "blockB", ";", "if", "(", "block", "&&", "!", "block", ".", "outputConnection", ".", "checkType_", "(", "parentConnection", ")", ")", "{", "// Ensure that any disconnections are grouped with the causing event.", "Blockly", ".", "Events", ".", "setGroup", "(", "e", ".", "group", ")", ";", "if", "(", "parentConnection", "===", "this", ".", "prevParentConnection_", ")", "{", "this", ".", "unplug", "(", ")", ";", "parentConnection", ".", "getSourceBlock", "(", ")", ".", "bumpNeighbours_", "(", ")", ";", "}", "else", "{", "block", ".", "unplug", "(", ")", ";", "block", ".", "bumpNeighbours_", "(", ")", ";", "}", "Blockly", ".", "Events", ".", "setGroup", "(", "false", ")", ";", "}", "}", "}", "this", ".", "prevParentConnection_", "=", "parentConnection", ";", "}" ]
Called whenever anything on the workspace changes. Prevent mismatched types. @param {!Blockly.Events.Abstract} e Change event. @this Blockly.Block
[ "Called", "whenever", "anything", "on", "the", "workspace", "changes", ".", "Prevent", "mismatched", "types", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/logic.js#L462-L485
18,915
webduinoio/webduino-blockly
components/blockly-src/core/flyout.js
function(e) { var blocks = this.workspace_.getTopBlocks(false); for (var i = 0, block; block = blocks[i]; i++) { block.removeSelect(); } }
javascript
function(e) { var blocks = this.workspace_.getTopBlocks(false); for (var i = 0, block; block = blocks[i]; i++) { block.removeSelect(); } }
[ "function", "(", "e", ")", "{", "var", "blocks", "=", "this", ".", "workspace_", ".", "getTopBlocks", "(", "false", ")", ";", "for", "(", "var", "i", "=", "0", ",", "block", ";", "block", "=", "blocks", "[", "i", "]", ";", "i", "++", ")", "{", "block", ".", "removeSelect", "(", ")", ";", "}", "}" ]
IE 11 is an incompetant browser that fails to fire mouseout events. When the mouse is over the background, deselect all blocks.
[ "IE", "11", "is", "an", "incompetant", "browser", "that", "fails", "to", "fire", "mouseout", "events", ".", "When", "the", "mouse", "is", "over", "the", "background", "deselect", "all", "blocks", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/core/flyout.js#L455-L460
18,916
webduinoio/webduino-blockly
components/blockly-src/demos/plane/blocks.js
function() { this.setHelpUrl(Blockly.Msg.VARIABLES_SET_HELPURL); this.setColour(330); this.appendValueInput('VALUE') .appendField(Plane.getMsg('Plane_setSeats')); this.setTooltip(Blockly.Msg.VARIABLES_SET_TOOLTIP); this.setDeletable(false); }
javascript
function() { this.setHelpUrl(Blockly.Msg.VARIABLES_SET_HELPURL); this.setColour(330); this.appendValueInput('VALUE') .appendField(Plane.getMsg('Plane_setSeats')); this.setTooltip(Blockly.Msg.VARIABLES_SET_TOOLTIP); this.setDeletable(false); }
[ "function", "(", ")", "{", "this", ".", "setHelpUrl", "(", "Blockly", ".", "Msg", ".", "VARIABLES_SET_HELPURL", ")", ";", "this", ".", "setColour", "(", "330", ")", ";", "this", ".", "appendValueInput", "(", "'VALUE'", ")", ".", "appendField", "(", "Plane", ".", "getMsg", "(", "'Plane_setSeats'", ")", ")", ";", "this", ".", "setTooltip", "(", "Blockly", ".", "Msg", ".", "VARIABLES_SET_TOOLTIP", ")", ";", "this", ".", "setDeletable", "(", "false", ")", ";", "}" ]
Block seat variable setter.
[ "Block", "seat", "variable", "setter", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/demos/plane/blocks.js#L28-L35
18,917
webduinoio/webduino-blockly
components/blockly-src/demos/plane/blocks.js
function() { this.setHelpUrl(Blockly.Msg.VARIABLES_GET_HELPURL); this.setColour(330); this.appendDummyInput() .appendField(Plane.getMsg('Plane_getRows2'), 'title'); this.setOutput(true, 'Number'); }
javascript
function() { this.setHelpUrl(Blockly.Msg.VARIABLES_GET_HELPURL); this.setColour(330); this.appendDummyInput() .appendField(Plane.getMsg('Plane_getRows2'), 'title'); this.setOutput(true, 'Number'); }
[ "function", "(", ")", "{", "this", ".", "setHelpUrl", "(", "Blockly", ".", "Msg", ".", "VARIABLES_GET_HELPURL", ")", ";", "this", ".", "setColour", "(", "330", ")", ";", "this", ".", "appendDummyInput", "(", ")", ".", "appendField", "(", "Plane", ".", "getMsg", "(", "'Plane_getRows2'", ")", ",", "'title'", ")", ";", "this", ".", "setOutput", "(", "true", ",", "'Number'", ")", ";", "}" ]
Block for second class row variable getter.
[ "Block", "for", "second", "class", "row", "variable", "getter", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/demos/plane/blocks.js#L87-L93
18,918
webduinoio/webduino-blockly
components/blockly-src/demos/blockfactory/factory.js
formatChange
function formatChange() { var mask = document.getElementById('blocklyMask'); var languagePre = document.getElementById('languagePre'); var languageTA = document.getElementById('languageTA'); if (document.getElementById('format').value == 'Manual') { Blockly.hideChaff(); mask.style.display = 'block'; languagePre.style.display = 'none'; languageTA.style.display = 'block'; var code = languagePre.textContent.trim(); languageTA.value = code; languageTA.focus(); updatePreview(); } else { mask.style.display = 'none'; languageTA.style.display = 'none'; languagePre.style.display = 'block'; updateLanguage(); } disableEnableLink(); }
javascript
function formatChange() { var mask = document.getElementById('blocklyMask'); var languagePre = document.getElementById('languagePre'); var languageTA = document.getElementById('languageTA'); if (document.getElementById('format').value == 'Manual') { Blockly.hideChaff(); mask.style.display = 'block'; languagePre.style.display = 'none'; languageTA.style.display = 'block'; var code = languagePre.textContent.trim(); languageTA.value = code; languageTA.focus(); updatePreview(); } else { mask.style.display = 'none'; languageTA.style.display = 'none'; languagePre.style.display = 'block'; updateLanguage(); } disableEnableLink(); }
[ "function", "formatChange", "(", ")", "{", "var", "mask", "=", "document", ".", "getElementById", "(", "'blocklyMask'", ")", ";", "var", "languagePre", "=", "document", ".", "getElementById", "(", "'languagePre'", ")", ";", "var", "languageTA", "=", "document", ".", "getElementById", "(", "'languageTA'", ")", ";", "if", "(", "document", ".", "getElementById", "(", "'format'", ")", ".", "value", "==", "'Manual'", ")", "{", "Blockly", ".", "hideChaff", "(", ")", ";", "mask", ".", "style", ".", "display", "=", "'block'", ";", "languagePre", ".", "style", ".", "display", "=", "'none'", ";", "languageTA", ".", "style", ".", "display", "=", "'block'", ";", "var", "code", "=", "languagePre", ".", "textContent", ".", "trim", "(", ")", ";", "languageTA", ".", "value", "=", "code", ";", "languageTA", ".", "focus", "(", ")", ";", "updatePreview", "(", ")", ";", "}", "else", "{", "mask", ".", "style", ".", "display", "=", "'none'", ";", "languageTA", ".", "style", ".", "display", "=", "'none'", ";", "languagePre", ".", "style", ".", "display", "=", "'block'", ";", "updateLanguage", "(", ")", ";", "}", "disableEnableLink", "(", ")", ";", "}" ]
Change the language code format.
[ "Change", "the", "language", "code", "format", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/demos/blockfactory/factory.js#L46-L66
18,919
webduinoio/webduino-blockly
components/blockly-src/demos/blockfactory/factory.js
updateLanguage
function updateLanguage() { var rootBlock = getRootBlock(); if (!rootBlock) { return; } var blockType = rootBlock.getFieldValue('NAME').trim().toLowerCase(); if (!blockType) { blockType = UNNAMED; } blockType = blockType.replace(/\W/g, '_').replace(/^(\d)/, '_\\1'); switch (document.getElementById('format').value) { case 'JSON': var code = formatJson_(blockType, rootBlock); break; case 'JavaScript': var code = formatJavaScript_(blockType, rootBlock); break; } injectCode(code, 'languagePre'); updatePreview(); }
javascript
function updateLanguage() { var rootBlock = getRootBlock(); if (!rootBlock) { return; } var blockType = rootBlock.getFieldValue('NAME').trim().toLowerCase(); if (!blockType) { blockType = UNNAMED; } blockType = blockType.replace(/\W/g, '_').replace(/^(\d)/, '_\\1'); switch (document.getElementById('format').value) { case 'JSON': var code = formatJson_(blockType, rootBlock); break; case 'JavaScript': var code = formatJavaScript_(blockType, rootBlock); break; } injectCode(code, 'languagePre'); updatePreview(); }
[ "function", "updateLanguage", "(", ")", "{", "var", "rootBlock", "=", "getRootBlock", "(", ")", ";", "if", "(", "!", "rootBlock", ")", "{", "return", ";", "}", "var", "blockType", "=", "rootBlock", ".", "getFieldValue", "(", "'NAME'", ")", ".", "trim", "(", ")", ".", "toLowerCase", "(", ")", ";", "if", "(", "!", "blockType", ")", "{", "blockType", "=", "UNNAMED", ";", "}", "blockType", "=", "blockType", ".", "replace", "(", "/", "\\W", "/", "g", ",", "'_'", ")", ".", "replace", "(", "/", "^(\\d)", "/", ",", "'_\\\\1'", ")", ";", "switch", "(", "document", ".", "getElementById", "(", "'format'", ")", ".", "value", ")", "{", "case", "'JSON'", ":", "var", "code", "=", "formatJson_", "(", "blockType", ",", "rootBlock", ")", ";", "break", ";", "case", "'JavaScript'", ":", "var", "code", "=", "formatJavaScript_", "(", "blockType", ",", "rootBlock", ")", ";", "break", ";", "}", "injectCode", "(", "code", ",", "'languagePre'", ")", ";", "updatePreview", "(", ")", ";", "}" ]
Update the language code based on constructs made in Blockly.
[ "Update", "the", "language", "code", "based", "on", "constructs", "made", "in", "Blockly", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/demos/blockfactory/factory.js#L71-L91
18,920
webduinoio/webduino-blockly
components/blockly-src/demos/blockfactory/factory.js
formatJavaScript_
function formatJavaScript_(blockType, rootBlock) { var code = []; code.push("Blockly.Blocks['" + blockType + "'] = {"); code.push(" init: function() {"); // Generate inputs. var TYPES = {'input_value': 'appendValueInput', 'input_statement': 'appendStatementInput', 'input_dummy': 'appendDummyInput'}; var contentsBlock = rootBlock.getInputTargetBlock('INPUTS'); while (contentsBlock) { if (!contentsBlock.disabled && !contentsBlock.getInheritedDisabled()) { var name = ''; // Dummy inputs don't have names. Other inputs do. if (contentsBlock.type != 'input_dummy') { name = escapeString(contentsBlock.getFieldValue('INPUTNAME')); } code.push(' this.' + TYPES[contentsBlock.type] + '(' + name + ')'); var check = getOptTypesFrom(contentsBlock, 'TYPE'); if (check) { code.push(' .setCheck(' + check + ')'); } var align = contentsBlock.getFieldValue('ALIGN'); if (align != 'LEFT') { code.push(' .setAlign(Blockly.ALIGN_' + align + ')'); } var fields = getFieldsJs_(contentsBlock.getInputTargetBlock('FIELDS')); for (var i = 0; i < fields.length; i++) { code.push(' .appendField(' + fields[i] + ')'); } // Add semicolon to last line to finish the statement. code[code.length - 1] += ';'; } contentsBlock = contentsBlock.nextConnection && contentsBlock.nextConnection.targetBlock(); } // Generate inline/external switch. if (rootBlock.getFieldValue('INLINE') == 'EXT') { code.push(' this.setInputsInline(false);'); } else if (rootBlock.getFieldValue('INLINE') == 'INT') { code.push(' this.setInputsInline(true);'); } // Generate output, or next/previous connections. switch (rootBlock.getFieldValue('CONNECTIONS')) { case 'LEFT': code.push(connectionLineJs_('setOutput', 'OUTPUTTYPE')); break; case 'BOTH': code.push(connectionLineJs_('setPreviousStatement', 'TOPTYPE')); code.push(connectionLineJs_('setNextStatement', 'BOTTOMTYPE')); break; case 'TOP': code.push(connectionLineJs_('setPreviousStatement', 'TOPTYPE')); break; case 'BOTTOM': code.push(connectionLineJs_('setNextStatement', 'BOTTOMTYPE')); break; } // Generate colour. var colourBlock = rootBlock.getInputTargetBlock('COLOUR'); if (colourBlock && !colourBlock.disabled) { var hue = parseInt(colourBlock.getFieldValue('HUE'), 10); if (!isNaN(hue)) { code.push(' this.setColour(' + hue + ');'); } } code.push(" this.setTooltip('');"); code.push(" this.setHelpUrl('http://www.example.com/');"); code.push(' }'); code.push('};'); return code.join('\n'); }
javascript
function formatJavaScript_(blockType, rootBlock) { var code = []; code.push("Blockly.Blocks['" + blockType + "'] = {"); code.push(" init: function() {"); // Generate inputs. var TYPES = {'input_value': 'appendValueInput', 'input_statement': 'appendStatementInput', 'input_dummy': 'appendDummyInput'}; var contentsBlock = rootBlock.getInputTargetBlock('INPUTS'); while (contentsBlock) { if (!contentsBlock.disabled && !contentsBlock.getInheritedDisabled()) { var name = ''; // Dummy inputs don't have names. Other inputs do. if (contentsBlock.type != 'input_dummy') { name = escapeString(contentsBlock.getFieldValue('INPUTNAME')); } code.push(' this.' + TYPES[contentsBlock.type] + '(' + name + ')'); var check = getOptTypesFrom(contentsBlock, 'TYPE'); if (check) { code.push(' .setCheck(' + check + ')'); } var align = contentsBlock.getFieldValue('ALIGN'); if (align != 'LEFT') { code.push(' .setAlign(Blockly.ALIGN_' + align + ')'); } var fields = getFieldsJs_(contentsBlock.getInputTargetBlock('FIELDS')); for (var i = 0; i < fields.length; i++) { code.push(' .appendField(' + fields[i] + ')'); } // Add semicolon to last line to finish the statement. code[code.length - 1] += ';'; } contentsBlock = contentsBlock.nextConnection && contentsBlock.nextConnection.targetBlock(); } // Generate inline/external switch. if (rootBlock.getFieldValue('INLINE') == 'EXT') { code.push(' this.setInputsInline(false);'); } else if (rootBlock.getFieldValue('INLINE') == 'INT') { code.push(' this.setInputsInline(true);'); } // Generate output, or next/previous connections. switch (rootBlock.getFieldValue('CONNECTIONS')) { case 'LEFT': code.push(connectionLineJs_('setOutput', 'OUTPUTTYPE')); break; case 'BOTH': code.push(connectionLineJs_('setPreviousStatement', 'TOPTYPE')); code.push(connectionLineJs_('setNextStatement', 'BOTTOMTYPE')); break; case 'TOP': code.push(connectionLineJs_('setPreviousStatement', 'TOPTYPE')); break; case 'BOTTOM': code.push(connectionLineJs_('setNextStatement', 'BOTTOMTYPE')); break; } // Generate colour. var colourBlock = rootBlock.getInputTargetBlock('COLOUR'); if (colourBlock && !colourBlock.disabled) { var hue = parseInt(colourBlock.getFieldValue('HUE'), 10); if (!isNaN(hue)) { code.push(' this.setColour(' + hue + ');'); } } code.push(" this.setTooltip('');"); code.push(" this.setHelpUrl('http://www.example.com/');"); code.push(' }'); code.push('};'); return code.join('\n'); }
[ "function", "formatJavaScript_", "(", "blockType", ",", "rootBlock", ")", "{", "var", "code", "=", "[", "]", ";", "code", ".", "push", "(", "\"Blockly.Blocks['\"", "+", "blockType", "+", "\"'] = {\"", ")", ";", "code", ".", "push", "(", "\" init: function() {\"", ")", ";", "// Generate inputs.", "var", "TYPES", "=", "{", "'input_value'", ":", "'appendValueInput'", ",", "'input_statement'", ":", "'appendStatementInput'", ",", "'input_dummy'", ":", "'appendDummyInput'", "}", ";", "var", "contentsBlock", "=", "rootBlock", ".", "getInputTargetBlock", "(", "'INPUTS'", ")", ";", "while", "(", "contentsBlock", ")", "{", "if", "(", "!", "contentsBlock", ".", "disabled", "&&", "!", "contentsBlock", ".", "getInheritedDisabled", "(", ")", ")", "{", "var", "name", "=", "''", ";", "// Dummy inputs don't have names. Other inputs do.", "if", "(", "contentsBlock", ".", "type", "!=", "'input_dummy'", ")", "{", "name", "=", "escapeString", "(", "contentsBlock", ".", "getFieldValue", "(", "'INPUTNAME'", ")", ")", ";", "}", "code", ".", "push", "(", "' this.'", "+", "TYPES", "[", "contentsBlock", ".", "type", "]", "+", "'('", "+", "name", "+", "')'", ")", ";", "var", "check", "=", "getOptTypesFrom", "(", "contentsBlock", ",", "'TYPE'", ")", ";", "if", "(", "check", ")", "{", "code", ".", "push", "(", "' .setCheck('", "+", "check", "+", "')'", ")", ";", "}", "var", "align", "=", "contentsBlock", ".", "getFieldValue", "(", "'ALIGN'", ")", ";", "if", "(", "align", "!=", "'LEFT'", ")", "{", "code", ".", "push", "(", "' .setAlign(Blockly.ALIGN_'", "+", "align", "+", "')'", ")", ";", "}", "var", "fields", "=", "getFieldsJs_", "(", "contentsBlock", ".", "getInputTargetBlock", "(", "'FIELDS'", ")", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "fields", ".", "length", ";", "i", "++", ")", "{", "code", ".", "push", "(", "' .appendField('", "+", "fields", "[", "i", "]", "+", "')'", ")", ";", "}", "// Add semicolon to last line to finish the statement.", "code", "[", "code", ".", "length", "-", "1", "]", "+=", "';'", ";", "}", "contentsBlock", "=", "contentsBlock", ".", "nextConnection", "&&", "contentsBlock", ".", "nextConnection", ".", "targetBlock", "(", ")", ";", "}", "// Generate inline/external switch.", "if", "(", "rootBlock", ".", "getFieldValue", "(", "'INLINE'", ")", "==", "'EXT'", ")", "{", "code", ".", "push", "(", "' this.setInputsInline(false);'", ")", ";", "}", "else", "if", "(", "rootBlock", ".", "getFieldValue", "(", "'INLINE'", ")", "==", "'INT'", ")", "{", "code", ".", "push", "(", "' this.setInputsInline(true);'", ")", ";", "}", "// Generate output, or next/previous connections.", "switch", "(", "rootBlock", ".", "getFieldValue", "(", "'CONNECTIONS'", ")", ")", "{", "case", "'LEFT'", ":", "code", ".", "push", "(", "connectionLineJs_", "(", "'setOutput'", ",", "'OUTPUTTYPE'", ")", ")", ";", "break", ";", "case", "'BOTH'", ":", "code", ".", "push", "(", "connectionLineJs_", "(", "'setPreviousStatement'", ",", "'TOPTYPE'", ")", ")", ";", "code", ".", "push", "(", "connectionLineJs_", "(", "'setNextStatement'", ",", "'BOTTOMTYPE'", ")", ")", ";", "break", ";", "case", "'TOP'", ":", "code", ".", "push", "(", "connectionLineJs_", "(", "'setPreviousStatement'", ",", "'TOPTYPE'", ")", ")", ";", "break", ";", "case", "'BOTTOM'", ":", "code", ".", "push", "(", "connectionLineJs_", "(", "'setNextStatement'", ",", "'BOTTOMTYPE'", ")", ")", ";", "break", ";", "}", "// Generate colour.", "var", "colourBlock", "=", "rootBlock", ".", "getInputTargetBlock", "(", "'COLOUR'", ")", ";", "if", "(", "colourBlock", "&&", "!", "colourBlock", ".", "disabled", ")", "{", "var", "hue", "=", "parseInt", "(", "colourBlock", ".", "getFieldValue", "(", "'HUE'", ")", ",", "10", ")", ";", "if", "(", "!", "isNaN", "(", "hue", ")", ")", "{", "code", ".", "push", "(", "' this.setColour('", "+", "hue", "+", "');'", ")", ";", "}", "}", "code", ".", "push", "(", "\" this.setTooltip('');\"", ")", ";", "code", ".", "push", "(", "\" this.setHelpUrl('http://www.example.com/');\"", ")", ";", "code", ".", "push", "(", "' }'", ")", ";", "code", ".", "push", "(", "'};'", ")", ";", "return", "code", ".", "join", "(", "'\\n'", ")", ";", "}" ]
Update the language code as JavaScript. @param {string} blockType Name of block. @param {!Blockly.Block} rootBlock Factory_base block. @return {string} Generanted language code. @private
[ "Update", "the", "language", "code", "as", "JavaScript", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/demos/blockfactory/factory.js#L202-L272
18,921
webduinoio/webduino-blockly
components/blockly-src/demos/blockfactory/factory.js
connectionLineJs_
function connectionLineJs_(functionName, typeName) { var type = getOptTypesFrom(getRootBlock(), typeName); if (type) { type = ', ' + type; } else { type = ''; } return ' this.' + functionName + '(true' + type + ');'; }
javascript
function connectionLineJs_(functionName, typeName) { var type = getOptTypesFrom(getRootBlock(), typeName); if (type) { type = ', ' + type; } else { type = ''; } return ' this.' + functionName + '(true' + type + ');'; }
[ "function", "connectionLineJs_", "(", "functionName", ",", "typeName", ")", "{", "var", "type", "=", "getOptTypesFrom", "(", "getRootBlock", "(", ")", ",", "typeName", ")", ";", "if", "(", "type", ")", "{", "type", "=", "', '", "+", "type", ";", "}", "else", "{", "type", "=", "''", ";", "}", "return", "' this.'", "+", "functionName", "+", "'(true'", "+", "type", "+", "');'", ";", "}" ]
Create JS code required to create a top, bottom, or value connection. @param {string} functionName JavaScript function name. @param {string} typeName Name of type input. @return {string} Line of JavaScript code to create connection. @private
[ "Create", "JS", "code", "required", "to", "create", "a", "top", "bottom", "or", "value", "connection", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/demos/blockfactory/factory.js#L281-L289
18,922
webduinoio/webduino-blockly
components/blockly-src/demos/blockfactory/factory.js
updatePreview
function updatePreview() { // Toggle between LTR/RTL if needed (also used in first display). var newDir = document.getElementById('direction').value; if (oldDir != newDir) { if (previewWorkspace) { previewWorkspace.dispose(); } var rtl = newDir == 'rtl'; previewWorkspace = Blockly.inject('preview', {rtl: rtl, media: '../../media/', scrollbars: true}); oldDir = newDir; } previewWorkspace.clear(); // Fetch the code and determine its format (JSON or JavaScript). var format = document.getElementById('format').value; if (format == 'Manual') { var code = document.getElementById('languageTA').value; // If the code is JSON, it will parse, otherwise treat as JS. try { JSON.parse(code); format = 'JSON'; } catch (e) { format = 'JavaScript'; } } else { var code = document.getElementById('languagePre').textContent; } if (!code.trim()) { // Nothing to render. Happens while cloud storage is loading. return; } // Backup Blockly.Blocks object so that main workspace and preview don't // collide if user creates a 'factory_base' block, for instance. var backupBlocks = Blockly.Blocks; try { // Make a shallow copy. Blockly.Blocks = {}; for (var prop in backupBlocks) { Blockly.Blocks[prop] = backupBlocks[prop]; } if (format == 'JSON') { var json = JSON.parse(code); Blockly.Blocks[json.id || UNNAMED] = { init: function() { this.jsonInit(json); } }; } else if (format == 'JavaScript') { eval(code); } else { throw 'Unknown format: ' + format; } // Look for a block on Blockly.Blocks that does not match the backup. var blockType = null; for (var type in Blockly.Blocks) { if (typeof Blockly.Blocks[type].init == 'function' && Blockly.Blocks[type] != backupBlocks[type]) { blockType = type; break; } } if (!blockType) { return; } // Create the preview block. var previewBlock = previewWorkspace.newBlock(blockType); previewBlock.initSvg(); previewBlock.render(); previewBlock.setMovable(false); previewBlock.setDeletable(false); previewBlock.moveBy(15, 10); previewWorkspace.clearUndo(); updateGenerator(previewBlock); } finally { Blockly.Blocks = backupBlocks; } }
javascript
function updatePreview() { // Toggle between LTR/RTL if needed (also used in first display). var newDir = document.getElementById('direction').value; if (oldDir != newDir) { if (previewWorkspace) { previewWorkspace.dispose(); } var rtl = newDir == 'rtl'; previewWorkspace = Blockly.inject('preview', {rtl: rtl, media: '../../media/', scrollbars: true}); oldDir = newDir; } previewWorkspace.clear(); // Fetch the code and determine its format (JSON or JavaScript). var format = document.getElementById('format').value; if (format == 'Manual') { var code = document.getElementById('languageTA').value; // If the code is JSON, it will parse, otherwise treat as JS. try { JSON.parse(code); format = 'JSON'; } catch (e) { format = 'JavaScript'; } } else { var code = document.getElementById('languagePre').textContent; } if (!code.trim()) { // Nothing to render. Happens while cloud storage is loading. return; } // Backup Blockly.Blocks object so that main workspace and preview don't // collide if user creates a 'factory_base' block, for instance. var backupBlocks = Blockly.Blocks; try { // Make a shallow copy. Blockly.Blocks = {}; for (var prop in backupBlocks) { Blockly.Blocks[prop] = backupBlocks[prop]; } if (format == 'JSON') { var json = JSON.parse(code); Blockly.Blocks[json.id || UNNAMED] = { init: function() { this.jsonInit(json); } }; } else if (format == 'JavaScript') { eval(code); } else { throw 'Unknown format: ' + format; } // Look for a block on Blockly.Blocks that does not match the backup. var blockType = null; for (var type in Blockly.Blocks) { if (typeof Blockly.Blocks[type].init == 'function' && Blockly.Blocks[type] != backupBlocks[type]) { blockType = type; break; } } if (!blockType) { return; } // Create the preview block. var previewBlock = previewWorkspace.newBlock(blockType); previewBlock.initSvg(); previewBlock.render(); previewBlock.setMovable(false); previewBlock.setDeletable(false); previewBlock.moveBy(15, 10); previewWorkspace.clearUndo(); updateGenerator(previewBlock); } finally { Blockly.Blocks = backupBlocks; } }
[ "function", "updatePreview", "(", ")", "{", "// Toggle between LTR/RTL if needed (also used in first display).", "var", "newDir", "=", "document", ".", "getElementById", "(", "'direction'", ")", ".", "value", ";", "if", "(", "oldDir", "!=", "newDir", ")", "{", "if", "(", "previewWorkspace", ")", "{", "previewWorkspace", ".", "dispose", "(", ")", ";", "}", "var", "rtl", "=", "newDir", "==", "'rtl'", ";", "previewWorkspace", "=", "Blockly", ".", "inject", "(", "'preview'", ",", "{", "rtl", ":", "rtl", ",", "media", ":", "'../../media/'", ",", "scrollbars", ":", "true", "}", ")", ";", "oldDir", "=", "newDir", ";", "}", "previewWorkspace", ".", "clear", "(", ")", ";", "// Fetch the code and determine its format (JSON or JavaScript).", "var", "format", "=", "document", ".", "getElementById", "(", "'format'", ")", ".", "value", ";", "if", "(", "format", "==", "'Manual'", ")", "{", "var", "code", "=", "document", ".", "getElementById", "(", "'languageTA'", ")", ".", "value", ";", "// If the code is JSON, it will parse, otherwise treat as JS.", "try", "{", "JSON", ".", "parse", "(", "code", ")", ";", "format", "=", "'JSON'", ";", "}", "catch", "(", "e", ")", "{", "format", "=", "'JavaScript'", ";", "}", "}", "else", "{", "var", "code", "=", "document", ".", "getElementById", "(", "'languagePre'", ")", ".", "textContent", ";", "}", "if", "(", "!", "code", ".", "trim", "(", ")", ")", "{", "// Nothing to render. Happens while cloud storage is loading.", "return", ";", "}", "// Backup Blockly.Blocks object so that main workspace and preview don't", "// collide if user creates a 'factory_base' block, for instance.", "var", "backupBlocks", "=", "Blockly", ".", "Blocks", ";", "try", "{", "// Make a shallow copy.", "Blockly", ".", "Blocks", "=", "{", "}", ";", "for", "(", "var", "prop", "in", "backupBlocks", ")", "{", "Blockly", ".", "Blocks", "[", "prop", "]", "=", "backupBlocks", "[", "prop", "]", ";", "}", "if", "(", "format", "==", "'JSON'", ")", "{", "var", "json", "=", "JSON", ".", "parse", "(", "code", ")", ";", "Blockly", ".", "Blocks", "[", "json", ".", "id", "||", "UNNAMED", "]", "=", "{", "init", ":", "function", "(", ")", "{", "this", ".", "jsonInit", "(", "json", ")", ";", "}", "}", ";", "}", "else", "if", "(", "format", "==", "'JavaScript'", ")", "{", "eval", "(", "code", ")", ";", "}", "else", "{", "throw", "'Unknown format: '", "+", "format", ";", "}", "// Look for a block on Blockly.Blocks that does not match the backup.", "var", "blockType", "=", "null", ";", "for", "(", "var", "type", "in", "Blockly", ".", "Blocks", ")", "{", "if", "(", "typeof", "Blockly", ".", "Blocks", "[", "type", "]", ".", "init", "==", "'function'", "&&", "Blockly", ".", "Blocks", "[", "type", "]", "!=", "backupBlocks", "[", "type", "]", ")", "{", "blockType", "=", "type", ";", "break", ";", "}", "}", "if", "(", "!", "blockType", ")", "{", "return", ";", "}", "// Create the preview block.", "var", "previewBlock", "=", "previewWorkspace", ".", "newBlock", "(", "blockType", ")", ";", "previewBlock", ".", "initSvg", "(", ")", ";", "previewBlock", ".", "render", "(", ")", ";", "previewBlock", ".", "setMovable", "(", "false", ")", ";", "previewBlock", ".", "setDeletable", "(", "false", ")", ";", "previewBlock", ".", "moveBy", "(", "15", ",", "10", ")", ";", "previewWorkspace", ".", "clearUndo", "(", ")", ";", "updateGenerator", "(", "previewBlock", ")", ";", "}", "finally", "{", "Blockly", ".", "Blocks", "=", "backupBlocks", ";", "}", "}" ]
Update the preview display.
[ "Update", "the", "preview", "display", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/demos/blockfactory/factory.js#L612-L696
18,923
webduinoio/webduino-blockly
components/blockly-src/demos/blockfactory/factory.js
getRootBlock
function getRootBlock() { var blocks = mainWorkspace.getTopBlocks(false); for (var i = 0, block; block = blocks[i]; i++) { if (block.type == 'factory_base') { return block; } } return null; }
javascript
function getRootBlock() { var blocks = mainWorkspace.getTopBlocks(false); for (var i = 0, block; block = blocks[i]; i++) { if (block.type == 'factory_base') { return block; } } return null; }
[ "function", "getRootBlock", "(", ")", "{", "var", "blocks", "=", "mainWorkspace", ".", "getTopBlocks", "(", "false", ")", ";", "for", "(", "var", "i", "=", "0", ",", "block", ";", "block", "=", "blocks", "[", "i", "]", ";", "i", "++", ")", "{", "if", "(", "block", ".", "type", "==", "'factory_base'", ")", "{", "return", "block", ";", "}", "}", "return", "null", ";", "}" ]
Return the uneditable container block that everything else attaches to. @return {Blockly.Block}
[ "Return", "the", "uneditable", "container", "block", "that", "everything", "else", "attaches", "to", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/demos/blockfactory/factory.js#L716-L724
18,924
webduinoio/webduino-blockly
components/blockly-src/demos/blockfactory/factory.js
init
function init() { if ('BlocklyStorage' in window) { BlocklyStorage.HTTPREQUEST_ERROR = 'There was a problem with the request.\n'; BlocklyStorage.LINK_ALERT = 'Share your blocks with this link:\n\n%1'; BlocklyStorage.HASH_ERROR = 'Sorry, "%1" doesn\'t correspond with any saved Blockly file.'; BlocklyStorage.XML_ERROR = 'Could not load your saved file.\n'+ 'Perhaps it was created with a different version of Blockly?'; var linkButton = document.getElementById('linkButton'); linkButton.style.display = 'inline-block'; linkButton.addEventListener('click', function() {BlocklyStorage.link(mainWorkspace);}); disableEnableLink(); } document.getElementById('helpButton').addEventListener('click', function() { open('https://developers.google.com/blockly/custom-blocks/block-factory', 'BlockFactoryHelp'); }); var expandList = [ document.getElementById('blockly'), document.getElementById('blocklyMask'), document.getElementById('preview'), document.getElementById('languagePre'), document.getElementById('languageTA'), document.getElementById('generatorPre') ]; var onresize = function(e) { for (var i = 0, expand; expand = expandList[i]; i++) { expand.style.width = (expand.parentNode.offsetWidth - 2) + 'px'; expand.style.height = (expand.parentNode.offsetHeight - 2) + 'px'; } }; onresize(); window.addEventListener('resize', onresize); var toolbox = document.getElementById('toolbox'); mainWorkspace = Blockly.inject('blockly', {collapse: false, toolbox: toolbox, media: '../../media/'}); // Create the root block. if ('BlocklyStorage' in window && window.location.hash.length > 1) { BlocklyStorage.retrieveXml(window.location.hash.substring(1), mainWorkspace); } else { var xml = '<xml><block type="factory_base" deletable="false" movable="false"></block></xml>'; Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), mainWorkspace); } mainWorkspace.clearUndo(); mainWorkspace.addChangeListener(updateLanguage); document.getElementById('direction') .addEventListener('change', updatePreview); document.getElementById('languageTA') .addEventListener('change', updatePreview); document.getElementById('languageTA') .addEventListener('keyup', updatePreview); document.getElementById('format') .addEventListener('change', formatChange); document.getElementById('language') .addEventListener('change', updatePreview); }
javascript
function init() { if ('BlocklyStorage' in window) { BlocklyStorage.HTTPREQUEST_ERROR = 'There was a problem with the request.\n'; BlocklyStorage.LINK_ALERT = 'Share your blocks with this link:\n\n%1'; BlocklyStorage.HASH_ERROR = 'Sorry, "%1" doesn\'t correspond with any saved Blockly file.'; BlocklyStorage.XML_ERROR = 'Could not load your saved file.\n'+ 'Perhaps it was created with a different version of Blockly?'; var linkButton = document.getElementById('linkButton'); linkButton.style.display = 'inline-block'; linkButton.addEventListener('click', function() {BlocklyStorage.link(mainWorkspace);}); disableEnableLink(); } document.getElementById('helpButton').addEventListener('click', function() { open('https://developers.google.com/blockly/custom-blocks/block-factory', 'BlockFactoryHelp'); }); var expandList = [ document.getElementById('blockly'), document.getElementById('blocklyMask'), document.getElementById('preview'), document.getElementById('languagePre'), document.getElementById('languageTA'), document.getElementById('generatorPre') ]; var onresize = function(e) { for (var i = 0, expand; expand = expandList[i]; i++) { expand.style.width = (expand.parentNode.offsetWidth - 2) + 'px'; expand.style.height = (expand.parentNode.offsetHeight - 2) + 'px'; } }; onresize(); window.addEventListener('resize', onresize); var toolbox = document.getElementById('toolbox'); mainWorkspace = Blockly.inject('blockly', {collapse: false, toolbox: toolbox, media: '../../media/'}); // Create the root block. if ('BlocklyStorage' in window && window.location.hash.length > 1) { BlocklyStorage.retrieveXml(window.location.hash.substring(1), mainWorkspace); } else { var xml = '<xml><block type="factory_base" deletable="false" movable="false"></block></xml>'; Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), mainWorkspace); } mainWorkspace.clearUndo(); mainWorkspace.addChangeListener(updateLanguage); document.getElementById('direction') .addEventListener('change', updatePreview); document.getElementById('languageTA') .addEventListener('change', updatePreview); document.getElementById('languageTA') .addEventListener('keyup', updatePreview); document.getElementById('format') .addEventListener('change', formatChange); document.getElementById('language') .addEventListener('change', updatePreview); }
[ "function", "init", "(", ")", "{", "if", "(", "'BlocklyStorage'", "in", "window", ")", "{", "BlocklyStorage", ".", "HTTPREQUEST_ERROR", "=", "'There was a problem with the request.\\n'", ";", "BlocklyStorage", ".", "LINK_ALERT", "=", "'Share your blocks with this link:\\n\\n%1'", ";", "BlocklyStorage", ".", "HASH_ERROR", "=", "'Sorry, \"%1\" doesn\\'t correspond with any saved Blockly file.'", ";", "BlocklyStorage", ".", "XML_ERROR", "=", "'Could not load your saved file.\\n'", "+", "'Perhaps it was created with a different version of Blockly?'", ";", "var", "linkButton", "=", "document", ".", "getElementById", "(", "'linkButton'", ")", ";", "linkButton", ".", "style", ".", "display", "=", "'inline-block'", ";", "linkButton", ".", "addEventListener", "(", "'click'", ",", "function", "(", ")", "{", "BlocklyStorage", ".", "link", "(", "mainWorkspace", ")", ";", "}", ")", ";", "disableEnableLink", "(", ")", ";", "}", "document", ".", "getElementById", "(", "'helpButton'", ")", ".", "addEventListener", "(", "'click'", ",", "function", "(", ")", "{", "open", "(", "'https://developers.google.com/blockly/custom-blocks/block-factory'", ",", "'BlockFactoryHelp'", ")", ";", "}", ")", ";", "var", "expandList", "=", "[", "document", ".", "getElementById", "(", "'blockly'", ")", ",", "document", ".", "getElementById", "(", "'blocklyMask'", ")", ",", "document", ".", "getElementById", "(", "'preview'", ")", ",", "document", ".", "getElementById", "(", "'languagePre'", ")", ",", "document", ".", "getElementById", "(", "'languageTA'", ")", ",", "document", ".", "getElementById", "(", "'generatorPre'", ")", "]", ";", "var", "onresize", "=", "function", "(", "e", ")", "{", "for", "(", "var", "i", "=", "0", ",", "expand", ";", "expand", "=", "expandList", "[", "i", "]", ";", "i", "++", ")", "{", "expand", ".", "style", ".", "width", "=", "(", "expand", ".", "parentNode", ".", "offsetWidth", "-", "2", ")", "+", "'px'", ";", "expand", ".", "style", ".", "height", "=", "(", "expand", ".", "parentNode", ".", "offsetHeight", "-", "2", ")", "+", "'px'", ";", "}", "}", ";", "onresize", "(", ")", ";", "window", ".", "addEventListener", "(", "'resize'", ",", "onresize", ")", ";", "var", "toolbox", "=", "document", ".", "getElementById", "(", "'toolbox'", ")", ";", "mainWorkspace", "=", "Blockly", ".", "inject", "(", "'blockly'", ",", "{", "collapse", ":", "false", ",", "toolbox", ":", "toolbox", ",", "media", ":", "'../../media/'", "}", ")", ";", "// Create the root block.", "if", "(", "'BlocklyStorage'", "in", "window", "&&", "window", ".", "location", ".", "hash", ".", "length", ">", "1", ")", "{", "BlocklyStorage", ".", "retrieveXml", "(", "window", ".", "location", ".", "hash", ".", "substring", "(", "1", ")", ",", "mainWorkspace", ")", ";", "}", "else", "{", "var", "xml", "=", "'<xml><block type=\"factory_base\" deletable=\"false\" movable=\"false\"></block></xml>'", ";", "Blockly", ".", "Xml", ".", "domToWorkspace", "(", "Blockly", ".", "Xml", ".", "textToDom", "(", "xml", ")", ",", "mainWorkspace", ")", ";", "}", "mainWorkspace", ".", "clearUndo", "(", ")", ";", "mainWorkspace", ".", "addChangeListener", "(", "updateLanguage", ")", ";", "document", ".", "getElementById", "(", "'direction'", ")", ".", "addEventListener", "(", "'change'", ",", "updatePreview", ")", ";", "document", ".", "getElementById", "(", "'languageTA'", ")", ".", "addEventListener", "(", "'change'", ",", "updatePreview", ")", ";", "document", ".", "getElementById", "(", "'languageTA'", ")", ".", "addEventListener", "(", "'keyup'", ",", "updatePreview", ")", ";", "document", ".", "getElementById", "(", "'format'", ")", ".", "addEventListener", "(", "'change'", ",", "formatChange", ")", ";", "document", ".", "getElementById", "(", "'language'", ")", ".", "addEventListener", "(", "'change'", ",", "updatePreview", ")", ";", "}" ]
Initialize Blockly and layout. Called on page load.
[ "Initialize", "Blockly", "and", "layout", ".", "Called", "on", "page", "load", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/demos/blockfactory/factory.js#L737-L804
18,925
webduinoio/webduino-blockly
components/blockly-src/blocks/math.js
function() { this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL); this.setColour(Blockly.Blocks.math.HUE); this.appendDummyInput() .appendField(new Blockly.FieldTextInput('0', Blockly.FieldTextInput.numberValidator), 'NUM'); this.setOutput(true, 'Number'); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; // Number block is trivial. Use tooltip of parent block if it exists. this.setTooltip(function() { var parent = thisBlock.getParent(); return (parent && parent.tooltip) || Blockly.Msg.MATH_NUMBER_TOOLTIP; }); }
javascript
function() { this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL); this.setColour(Blockly.Blocks.math.HUE); this.appendDummyInput() .appendField(new Blockly.FieldTextInput('0', Blockly.FieldTextInput.numberValidator), 'NUM'); this.setOutput(true, 'Number'); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; // Number block is trivial. Use tooltip of parent block if it exists. this.setTooltip(function() { var parent = thisBlock.getParent(); return (parent && parent.tooltip) || Blockly.Msg.MATH_NUMBER_TOOLTIP; }); }
[ "function", "(", ")", "{", "this", ".", "setHelpUrl", "(", "Blockly", ".", "Msg", ".", "MATH_NUMBER_HELPURL", ")", ";", "this", ".", "setColour", "(", "Blockly", ".", "Blocks", ".", "math", ".", "HUE", ")", ";", "this", ".", "appendDummyInput", "(", ")", ".", "appendField", "(", "new", "Blockly", ".", "FieldTextInput", "(", "'0'", ",", "Blockly", ".", "FieldTextInput", ".", "numberValidator", ")", ",", "'NUM'", ")", ";", "this", ".", "setOutput", "(", "true", ",", "'Number'", ")", ";", "// Assign 'this' to a variable for use in the tooltip closure below.", "var", "thisBlock", "=", "this", ";", "// Number block is trivial. Use tooltip of parent block if it exists.", "this", ".", "setTooltip", "(", "function", "(", ")", "{", "var", "parent", "=", "thisBlock", ".", "getParent", "(", ")", ";", "return", "(", "parent", "&&", "parent", ".", "tooltip", ")", "||", "Blockly", ".", "Msg", ".", "MATH_NUMBER_TOOLTIP", ";", "}", ")", ";", "}" ]
Block for numeric value. @this Blockly.Block
[ "Block", "for", "numeric", "value", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/math.js#L42-L56
18,926
webduinoio/webduino-blockly
components/blockly-src/blocks/math.js
function() { this.jsonInit({ "message0": "%1 %2 %3", "args0": [ { "type": "input_value", "name": "A", "check": "Number" }, { "type": "field_dropdown", "name": "OP", "options": [[Blockly.Msg.MATH_ADDITION_SYMBOL, 'ADD'], [Blockly.Msg.MATH_SUBTRACTION_SYMBOL, 'MINUS'], [Blockly.Msg.MATH_MULTIPLICATION_SYMBOL, 'MULTIPLY'], [Blockly.Msg.MATH_DIVISION_SYMBOL, 'DIVIDE'], [Blockly.Msg.MATH_POWER_SYMBOL, 'POWER']] }, { "type": "input_value", "name": "B", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": Blockly.Blocks.math.HUE, "helpUrl": Blockly.Msg.MATH_ARITHMETIC_HELPURL }); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; this.setTooltip(function() { var mode = thisBlock.getFieldValue('OP'); var TOOLTIPS = { 'ADD': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_ADD, 'MINUS': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MINUS, 'MULTIPLY': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MULTIPLY, 'DIVIDE': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_DIVIDE, 'POWER': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_POWER }; return TOOLTIPS[mode]; }); }
javascript
function() { this.jsonInit({ "message0": "%1 %2 %3", "args0": [ { "type": "input_value", "name": "A", "check": "Number" }, { "type": "field_dropdown", "name": "OP", "options": [[Blockly.Msg.MATH_ADDITION_SYMBOL, 'ADD'], [Blockly.Msg.MATH_SUBTRACTION_SYMBOL, 'MINUS'], [Blockly.Msg.MATH_MULTIPLICATION_SYMBOL, 'MULTIPLY'], [Blockly.Msg.MATH_DIVISION_SYMBOL, 'DIVIDE'], [Blockly.Msg.MATH_POWER_SYMBOL, 'POWER']] }, { "type": "input_value", "name": "B", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": Blockly.Blocks.math.HUE, "helpUrl": Blockly.Msg.MATH_ARITHMETIC_HELPURL }); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; this.setTooltip(function() { var mode = thisBlock.getFieldValue('OP'); var TOOLTIPS = { 'ADD': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_ADD, 'MINUS': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MINUS, 'MULTIPLY': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MULTIPLY, 'DIVIDE': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_DIVIDE, 'POWER': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_POWER }; return TOOLTIPS[mode]; }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1 %2 %3\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"A\"", ",", "\"check\"", ":", "\"Number\"", "}", ",", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"OP\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "MATH_ADDITION_SYMBOL", ",", "'ADD'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_SUBTRACTION_SYMBOL", ",", "'MINUS'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_MULTIPLICATION_SYMBOL", ",", "'MULTIPLY'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_DIVISION_SYMBOL", ",", "'DIVIDE'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_POWER_SYMBOL", ",", "'POWER'", "]", "]", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"B\"", ",", "\"check\"", ":", "\"Number\"", "}", "]", ",", "\"inputsInline\"", ":", "true", ",", "\"output\"", ":", "\"Number\"", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "math", ".", "HUE", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "MATH_ARITHMETIC_HELPURL", "}", ")", ";", "// Assign 'this' to a variable for use in the tooltip closure below.", "var", "thisBlock", "=", "this", ";", "this", ".", "setTooltip", "(", "function", "(", ")", "{", "var", "mode", "=", "thisBlock", ".", "getFieldValue", "(", "'OP'", ")", ";", "var", "TOOLTIPS", "=", "{", "'ADD'", ":", "Blockly", ".", "Msg", ".", "MATH_ARITHMETIC_TOOLTIP_ADD", ",", "'MINUS'", ":", "Blockly", ".", "Msg", ".", "MATH_ARITHMETIC_TOOLTIP_MINUS", ",", "'MULTIPLY'", ":", "Blockly", ".", "Msg", ".", "MATH_ARITHMETIC_TOOLTIP_MULTIPLY", ",", "'DIVIDE'", ":", "Blockly", ".", "Msg", ".", "MATH_ARITHMETIC_TOOLTIP_DIVIDE", ",", "'POWER'", ":", "Blockly", ".", "Msg", ".", "MATH_ARITHMETIC_TOOLTIP_POWER", "}", ";", "return", "TOOLTIPS", "[", "mode", "]", ";", "}", ")", ";", "}" ]
Block for basic arithmetic operator. @this Blockly.Block
[ "Block", "for", "basic", "arithmetic", "operator", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/math.js#L64-L107
18,927
webduinoio/webduino-blockly
components/blockly-src/blocks/math.js
function() { this.jsonInit({ "message0": "%1 %2", "args0": [ { "type": "field_dropdown", "name": "OP", "options": [ [Blockly.Msg.MATH_SINGLE_OP_ROOT, 'ROOT'], [Blockly.Msg.MATH_SINGLE_OP_ABSOLUTE, 'ABS'], ['-', 'NEG'], ['ln', 'LN'], ['log10', 'LOG10'], ['e^', 'EXP'], ['10^', 'POW10'] ] }, { "type": "input_value", "name": "NUM", "check": "Number" } ], "output": "Number", "colour": Blockly.Blocks.math.HUE, "helpUrl": Blockly.Msg.MATH_SINGLE_HELPURL }); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; this.setTooltip(function() { var mode = thisBlock.getFieldValue('OP'); var TOOLTIPS = { 'ROOT': Blockly.Msg.MATH_SINGLE_TOOLTIP_ROOT, 'ABS': Blockly.Msg.MATH_SINGLE_TOOLTIP_ABS, 'NEG': Blockly.Msg.MATH_SINGLE_TOOLTIP_NEG, 'LN': Blockly.Msg.MATH_SINGLE_TOOLTIP_LN, 'LOG10': Blockly.Msg.MATH_SINGLE_TOOLTIP_LOG10, 'EXP': Blockly.Msg.MATH_SINGLE_TOOLTIP_EXP, 'POW10': Blockly.Msg.MATH_SINGLE_TOOLTIP_POW10 }; return TOOLTIPS[mode]; }); }
javascript
function() { this.jsonInit({ "message0": "%1 %2", "args0": [ { "type": "field_dropdown", "name": "OP", "options": [ [Blockly.Msg.MATH_SINGLE_OP_ROOT, 'ROOT'], [Blockly.Msg.MATH_SINGLE_OP_ABSOLUTE, 'ABS'], ['-', 'NEG'], ['ln', 'LN'], ['log10', 'LOG10'], ['e^', 'EXP'], ['10^', 'POW10'] ] }, { "type": "input_value", "name": "NUM", "check": "Number" } ], "output": "Number", "colour": Blockly.Blocks.math.HUE, "helpUrl": Blockly.Msg.MATH_SINGLE_HELPURL }); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; this.setTooltip(function() { var mode = thisBlock.getFieldValue('OP'); var TOOLTIPS = { 'ROOT': Blockly.Msg.MATH_SINGLE_TOOLTIP_ROOT, 'ABS': Blockly.Msg.MATH_SINGLE_TOOLTIP_ABS, 'NEG': Blockly.Msg.MATH_SINGLE_TOOLTIP_NEG, 'LN': Blockly.Msg.MATH_SINGLE_TOOLTIP_LN, 'LOG10': Blockly.Msg.MATH_SINGLE_TOOLTIP_LOG10, 'EXP': Blockly.Msg.MATH_SINGLE_TOOLTIP_EXP, 'POW10': Blockly.Msg.MATH_SINGLE_TOOLTIP_POW10 }; return TOOLTIPS[mode]; }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1 %2\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"OP\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "MATH_SINGLE_OP_ROOT", ",", "'ROOT'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_SINGLE_OP_ABSOLUTE", ",", "'ABS'", "]", ",", "[", "'-'", ",", "'NEG'", "]", ",", "[", "'ln'", ",", "'LN'", "]", ",", "[", "'log10'", ",", "'LOG10'", "]", ",", "[", "'e^'", ",", "'EXP'", "]", ",", "[", "'10^'", ",", "'POW10'", "]", "]", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"NUM\"", ",", "\"check\"", ":", "\"Number\"", "}", "]", ",", "\"output\"", ":", "\"Number\"", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "math", ".", "HUE", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "MATH_SINGLE_HELPURL", "}", ")", ";", "// Assign 'this' to a variable for use in the tooltip closure below.", "var", "thisBlock", "=", "this", ";", "this", ".", "setTooltip", "(", "function", "(", ")", "{", "var", "mode", "=", "thisBlock", ".", "getFieldValue", "(", "'OP'", ")", ";", "var", "TOOLTIPS", "=", "{", "'ROOT'", ":", "Blockly", ".", "Msg", ".", "MATH_SINGLE_TOOLTIP_ROOT", ",", "'ABS'", ":", "Blockly", ".", "Msg", ".", "MATH_SINGLE_TOOLTIP_ABS", ",", "'NEG'", ":", "Blockly", ".", "Msg", ".", "MATH_SINGLE_TOOLTIP_NEG", ",", "'LN'", ":", "Blockly", ".", "Msg", ".", "MATH_SINGLE_TOOLTIP_LN", ",", "'LOG10'", ":", "Blockly", ".", "Msg", ".", "MATH_SINGLE_TOOLTIP_LOG10", ",", "'EXP'", ":", "Blockly", ".", "Msg", ".", "MATH_SINGLE_TOOLTIP_EXP", ",", "'POW10'", ":", "Blockly", ".", "Msg", ".", "MATH_SINGLE_TOOLTIP_POW10", "}", ";", "return", "TOOLTIPS", "[", "mode", "]", ";", "}", ")", ";", "}" ]
Block for advanced math operators with single operand. @this Blockly.Block
[ "Block", "for", "advanced", "math", "operators", "with", "single", "operand", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/math.js#L115-L157
18,928
webduinoio/webduino-blockly
components/blockly-src/blocks/math.js
function() { this.jsonInit({ "message0": "%1 %2", "args0": [ { "type": "field_dropdown", "name": "OP", "options": [ [Blockly.Msg.MATH_TRIG_SIN, 'SIN'], [Blockly.Msg.MATH_TRIG_COS, 'COS'], [Blockly.Msg.MATH_TRIG_TAN, 'TAN'], [Blockly.Msg.MATH_TRIG_ASIN, 'ASIN'], [Blockly.Msg.MATH_TRIG_ACOS, 'ACOS'], [Blockly.Msg.MATH_TRIG_ATAN, 'ATAN'] ] }, { "type": "input_value", "name": "NUM", "check": "Number" } ], "output": "Number", "colour": Blockly.Blocks.math.HUE, "helpUrl": Blockly.Msg.MATH_TRIG_HELPURL }); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; this.setTooltip(function() { var mode = thisBlock.getFieldValue('OP'); var TOOLTIPS = { 'SIN': Blockly.Msg.MATH_TRIG_TOOLTIP_SIN, 'COS': Blockly.Msg.MATH_TRIG_TOOLTIP_COS, 'TAN': Blockly.Msg.MATH_TRIG_TOOLTIP_TAN, 'ASIN': Blockly.Msg.MATH_TRIG_TOOLTIP_ASIN, 'ACOS': Blockly.Msg.MATH_TRIG_TOOLTIP_ACOS, 'ATAN': Blockly.Msg.MATH_TRIG_TOOLTIP_ATAN }; return TOOLTIPS[mode]; }); }
javascript
function() { this.jsonInit({ "message0": "%1 %2", "args0": [ { "type": "field_dropdown", "name": "OP", "options": [ [Blockly.Msg.MATH_TRIG_SIN, 'SIN'], [Blockly.Msg.MATH_TRIG_COS, 'COS'], [Blockly.Msg.MATH_TRIG_TAN, 'TAN'], [Blockly.Msg.MATH_TRIG_ASIN, 'ASIN'], [Blockly.Msg.MATH_TRIG_ACOS, 'ACOS'], [Blockly.Msg.MATH_TRIG_ATAN, 'ATAN'] ] }, { "type": "input_value", "name": "NUM", "check": "Number" } ], "output": "Number", "colour": Blockly.Blocks.math.HUE, "helpUrl": Blockly.Msg.MATH_TRIG_HELPURL }); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; this.setTooltip(function() { var mode = thisBlock.getFieldValue('OP'); var TOOLTIPS = { 'SIN': Blockly.Msg.MATH_TRIG_TOOLTIP_SIN, 'COS': Blockly.Msg.MATH_TRIG_TOOLTIP_COS, 'TAN': Blockly.Msg.MATH_TRIG_TOOLTIP_TAN, 'ASIN': Blockly.Msg.MATH_TRIG_TOOLTIP_ASIN, 'ACOS': Blockly.Msg.MATH_TRIG_TOOLTIP_ACOS, 'ATAN': Blockly.Msg.MATH_TRIG_TOOLTIP_ATAN }; return TOOLTIPS[mode]; }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1 %2\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"OP\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "MATH_TRIG_SIN", ",", "'SIN'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_TRIG_COS", ",", "'COS'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_TRIG_TAN", ",", "'TAN'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_TRIG_ASIN", ",", "'ASIN'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_TRIG_ACOS", ",", "'ACOS'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_TRIG_ATAN", ",", "'ATAN'", "]", "]", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"NUM\"", ",", "\"check\"", ":", "\"Number\"", "}", "]", ",", "\"output\"", ":", "\"Number\"", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "math", ".", "HUE", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "MATH_TRIG_HELPURL", "}", ")", ";", "// Assign 'this' to a variable for use in the tooltip closure below.", "var", "thisBlock", "=", "this", ";", "this", ".", "setTooltip", "(", "function", "(", ")", "{", "var", "mode", "=", "thisBlock", ".", "getFieldValue", "(", "'OP'", ")", ";", "var", "TOOLTIPS", "=", "{", "'SIN'", ":", "Blockly", ".", "Msg", ".", "MATH_TRIG_TOOLTIP_SIN", ",", "'COS'", ":", "Blockly", ".", "Msg", ".", "MATH_TRIG_TOOLTIP_COS", ",", "'TAN'", ":", "Blockly", ".", "Msg", ".", "MATH_TRIG_TOOLTIP_TAN", ",", "'ASIN'", ":", "Blockly", ".", "Msg", ".", "MATH_TRIG_TOOLTIP_ASIN", ",", "'ACOS'", ":", "Blockly", ".", "Msg", ".", "MATH_TRIG_TOOLTIP_ACOS", ",", "'ATAN'", ":", "Blockly", ".", "Msg", ".", "MATH_TRIG_TOOLTIP_ATAN", "}", ";", "return", "TOOLTIPS", "[", "mode", "]", ";", "}", ")", ";", "}" ]
Block for trigonometry operators. @this Blockly.Block
[ "Block", "for", "trigonometry", "operators", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/math.js#L165-L205
18,929
webduinoio/webduino-blockly
components/blockly-src/blocks/math.js
function() { var PROPERTIES = [[Blockly.Msg.MATH_IS_EVEN, 'EVEN'], [Blockly.Msg.MATH_IS_ODD, 'ODD'], [Blockly.Msg.MATH_IS_PRIME, 'PRIME'], [Blockly.Msg.MATH_IS_WHOLE, 'WHOLE'], [Blockly.Msg.MATH_IS_POSITIVE, 'POSITIVE'], [Blockly.Msg.MATH_IS_NEGATIVE, 'NEGATIVE'], [Blockly.Msg.MATH_IS_DIVISIBLE_BY, 'DIVISIBLE_BY']]; this.setColour(Blockly.Blocks.math.HUE); this.appendValueInput('NUMBER_TO_CHECK') .setCheck('Number'); var dropdown = new Blockly.FieldDropdown(PROPERTIES, function(option) { var divisorInput = (option == 'DIVISIBLE_BY'); this.sourceBlock_.updateShape_(divisorInput); }); this.appendDummyInput() .appendField(dropdown, 'PROPERTY'); this.setInputsInline(true); this.setOutput(true, 'Boolean'); this.setTooltip(Blockly.Msg.MATH_IS_TOOLTIP); }
javascript
function() { var PROPERTIES = [[Blockly.Msg.MATH_IS_EVEN, 'EVEN'], [Blockly.Msg.MATH_IS_ODD, 'ODD'], [Blockly.Msg.MATH_IS_PRIME, 'PRIME'], [Blockly.Msg.MATH_IS_WHOLE, 'WHOLE'], [Blockly.Msg.MATH_IS_POSITIVE, 'POSITIVE'], [Blockly.Msg.MATH_IS_NEGATIVE, 'NEGATIVE'], [Blockly.Msg.MATH_IS_DIVISIBLE_BY, 'DIVISIBLE_BY']]; this.setColour(Blockly.Blocks.math.HUE); this.appendValueInput('NUMBER_TO_CHECK') .setCheck('Number'); var dropdown = new Blockly.FieldDropdown(PROPERTIES, function(option) { var divisorInput = (option == 'DIVISIBLE_BY'); this.sourceBlock_.updateShape_(divisorInput); }); this.appendDummyInput() .appendField(dropdown, 'PROPERTY'); this.setInputsInline(true); this.setOutput(true, 'Boolean'); this.setTooltip(Blockly.Msg.MATH_IS_TOOLTIP); }
[ "function", "(", ")", "{", "var", "PROPERTIES", "=", "[", "[", "Blockly", ".", "Msg", ".", "MATH_IS_EVEN", ",", "'EVEN'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_IS_ODD", ",", "'ODD'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_IS_PRIME", ",", "'PRIME'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_IS_WHOLE", ",", "'WHOLE'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_IS_POSITIVE", ",", "'POSITIVE'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_IS_NEGATIVE", ",", "'NEGATIVE'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_IS_DIVISIBLE_BY", ",", "'DIVISIBLE_BY'", "]", "]", ";", "this", ".", "setColour", "(", "Blockly", ".", "Blocks", ".", "math", ".", "HUE", ")", ";", "this", ".", "appendValueInput", "(", "'NUMBER_TO_CHECK'", ")", ".", "setCheck", "(", "'Number'", ")", ";", "var", "dropdown", "=", "new", "Blockly", ".", "FieldDropdown", "(", "PROPERTIES", ",", "function", "(", "option", ")", "{", "var", "divisorInput", "=", "(", "option", "==", "'DIVISIBLE_BY'", ")", ";", "this", ".", "sourceBlock_", ".", "updateShape_", "(", "divisorInput", ")", ";", "}", ")", ";", "this", ".", "appendDummyInput", "(", ")", ".", "appendField", "(", "dropdown", ",", "'PROPERTY'", ")", ";", "this", ".", "setInputsInline", "(", "true", ")", ";", "this", ".", "setOutput", "(", "true", ",", "'Boolean'", ")", ";", "this", ".", "setTooltip", "(", "Blockly", ".", "Msg", ".", "MATH_IS_TOOLTIP", ")", ";", "}" ]
Block for checking if a number is even, odd, prime, whole, positive, negative or if it is divisible by certain number. @this Blockly.Block
[ "Block", "for", "checking", "if", "a", "number", "is", "even", "odd", "prime", "whole", "positive", "negative", "or", "if", "it", "is", "divisible", "by", "certain", "number", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/math.js#L244-L265
18,930
webduinoio/webduino-blockly
components/blockly-src/blocks/math.js
function() { this.jsonInit({ "message0": Blockly.Msg.MATH_CHANGE_TITLE, "args0": [ { "type": "field_variable", "name": "VAR", "variable": Blockly.Msg.MATH_CHANGE_TITLE_ITEM }, { "type": "input_value", "name": "DELTA", "check": "Number" } ], "previousStatement": null, "nextStatement": null, "colour": Blockly.Blocks.math.HUE, "helpUrl": Blockly.Msg.MATH_CHANGE_HELPURL }); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; this.setTooltip(function() { return Blockly.Msg.MATH_CHANGE_TOOLTIP.replace('%1', thisBlock.getFieldValue('VAR')); }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.MATH_CHANGE_TITLE, "args0": [ { "type": "field_variable", "name": "VAR", "variable": Blockly.Msg.MATH_CHANGE_TITLE_ITEM }, { "type": "input_value", "name": "DELTA", "check": "Number" } ], "previousStatement": null, "nextStatement": null, "colour": Blockly.Blocks.math.HUE, "helpUrl": Blockly.Msg.MATH_CHANGE_HELPURL }); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; this.setTooltip(function() { return Blockly.Msg.MATH_CHANGE_TOOLTIP.replace('%1', thisBlock.getFieldValue('VAR')); }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "MATH_CHANGE_TITLE", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_variable\"", ",", "\"name\"", ":", "\"VAR\"", ",", "\"variable\"", ":", "Blockly", ".", "Msg", ".", "MATH_CHANGE_TITLE_ITEM", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"DELTA\"", ",", "\"check\"", ":", "\"Number\"", "}", "]", ",", "\"previousStatement\"", ":", "null", ",", "\"nextStatement\"", ":", "null", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "math", ".", "HUE", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "MATH_CHANGE_HELPURL", "}", ")", ";", "// Assign 'this' to a variable for use in the tooltip closure below.", "var", "thisBlock", "=", "this", ";", "this", ".", "setTooltip", "(", "function", "(", ")", "{", "return", "Blockly", ".", "Msg", ".", "MATH_CHANGE_TOOLTIP", ".", "replace", "(", "'%1'", ",", "thisBlock", ".", "getFieldValue", "(", "'VAR'", ")", ")", ";", "}", ")", ";", "}" ]
Block for adding to a variable in place. @this Blockly.Block
[ "Block", "for", "adding", "to", "a", "variable", "in", "place", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/math.js#L311-L337
18,931
webduinoio/webduino-blockly
components/blockly-src/blocks/math.js
function() { this.jsonInit({ "message0": "%1 %2", "args0": [ { "type": "field_dropdown", "name": "OP", "options": [ [Blockly.Msg.MATH_ROUND_OPERATOR_ROUND, 'ROUND'], [Blockly.Msg.MATH_ROUND_OPERATOR_ROUNDUP, 'ROUNDUP'], [Blockly.Msg.MATH_ROUND_OPERATOR_ROUNDDOWN, 'ROUNDDOWN'] ] }, { "type": "input_value", "name": "NUM", "check": "Number" } ], "output": "Number", "colour": Blockly.Blocks.math.HUE, "tooltip": Blockly.Msg.MATH_ROUND_TOOLTIP, "helpUrl": Blockly.Msg.MATH_ROUND_HELPURL }); }
javascript
function() { this.jsonInit({ "message0": "%1 %2", "args0": [ { "type": "field_dropdown", "name": "OP", "options": [ [Blockly.Msg.MATH_ROUND_OPERATOR_ROUND, 'ROUND'], [Blockly.Msg.MATH_ROUND_OPERATOR_ROUNDUP, 'ROUNDUP'], [Blockly.Msg.MATH_ROUND_OPERATOR_ROUNDDOWN, 'ROUNDDOWN'] ] }, { "type": "input_value", "name": "NUM", "check": "Number" } ], "output": "Number", "colour": Blockly.Blocks.math.HUE, "tooltip": Blockly.Msg.MATH_ROUND_TOOLTIP, "helpUrl": Blockly.Msg.MATH_ROUND_HELPURL }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1 %2\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"OP\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "MATH_ROUND_OPERATOR_ROUND", ",", "'ROUND'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_ROUND_OPERATOR_ROUNDUP", ",", "'ROUNDUP'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MATH_ROUND_OPERATOR_ROUNDDOWN", ",", "'ROUNDDOWN'", "]", "]", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"NUM\"", ",", "\"check\"", ":", "\"Number\"", "}", "]", ",", "\"output\"", ":", "\"Number\"", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "math", ".", "HUE", ",", "\"tooltip\"", ":", "Blockly", ".", "Msg", ".", "MATH_ROUND_TOOLTIP", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "MATH_ROUND_HELPURL", "}", ")", ";", "}" ]
Block for rounding functions. @this Blockly.Block
[ "Block", "for", "rounding", "functions", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/math.js#L345-L369
18,932
webduinoio/webduino-blockly
components/blockly-src/blocks/math.js
function() { this.jsonInit({ "message0": Blockly.Msg.MATH_MODULO_TITLE, "args0": [ { "type": "input_value", "name": "DIVIDEND", "check": "Number" }, { "type": "input_value", "name": "DIVISOR", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": Blockly.Blocks.math.HUE, "tooltip": Blockly.Msg.MATH_MODULO_TOOLTIP, "helpUrl": Blockly.Msg.MATH_MODULO_HELPURL }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.MATH_MODULO_TITLE, "args0": [ { "type": "input_value", "name": "DIVIDEND", "check": "Number" }, { "type": "input_value", "name": "DIVISOR", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": Blockly.Blocks.math.HUE, "tooltip": Blockly.Msg.MATH_MODULO_TOOLTIP, "helpUrl": Blockly.Msg.MATH_MODULO_HELPURL }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "MATH_MODULO_TITLE", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"DIVIDEND\"", ",", "\"check\"", ":", "\"Number\"", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"DIVISOR\"", ",", "\"check\"", ":", "\"Number\"", "}", "]", ",", "\"inputsInline\"", ":", "true", ",", "\"output\"", ":", "\"Number\"", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "math", ".", "HUE", ",", "\"tooltip\"", ":", "Blockly", ".", "Msg", ".", "MATH_MODULO_TOOLTIP", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "MATH_MODULO_HELPURL", "}", ")", ";", "}" ]
Block for remainder of a division. @this Blockly.Block
[ "Block", "for", "remainder", "of", "a", "division", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/math.js#L452-L473
18,933
webduinoio/webduino-blockly
components/blockly-src/blocks/math.js
function() { this.jsonInit({ "message0": Blockly.Msg.MATH_CONSTRAIN_TITLE, "args0": [ { "type": "input_value", "name": "VALUE", "check": "Number" }, { "type": "input_value", "name": "LOW", "check": "Number" }, { "type": "input_value", "name": "HIGH", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": Blockly.Blocks.math.HUE, "tooltip": Blockly.Msg.MATH_CONSTRAIN_TOOLTIP, "helpUrl": Blockly.Msg.MATH_CONSTRAIN_HELPURL }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.MATH_CONSTRAIN_TITLE, "args0": [ { "type": "input_value", "name": "VALUE", "check": "Number" }, { "type": "input_value", "name": "LOW", "check": "Number" }, { "type": "input_value", "name": "HIGH", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": Blockly.Blocks.math.HUE, "tooltip": Blockly.Msg.MATH_CONSTRAIN_TOOLTIP, "helpUrl": Blockly.Msg.MATH_CONSTRAIN_HELPURL }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "MATH_CONSTRAIN_TITLE", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"VALUE\"", ",", "\"check\"", ":", "\"Number\"", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"LOW\"", ",", "\"check\"", ":", "\"Number\"", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"HIGH\"", ",", "\"check\"", ":", "\"Number\"", "}", "]", ",", "\"inputsInline\"", ":", "true", ",", "\"output\"", ":", "\"Number\"", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "math", ".", "HUE", ",", "\"tooltip\"", ":", "Blockly", ".", "Msg", ".", "MATH_CONSTRAIN_TOOLTIP", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "MATH_CONSTRAIN_HELPURL", "}", ")", ";", "}" ]
Block for constraining a number between two limits. @this Blockly.Block
[ "Block", "for", "constraining", "a", "number", "between", "two", "limits", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/math.js#L481-L507
18,934
webduinoio/webduino-blockly
components/blockly-src/blocks/math.js
function() { this.jsonInit({ "message0": Blockly.Msg.MATH_RANDOM_FLOAT_TITLE_RANDOM, "output": "Number", "colour": Blockly.Blocks.math.HUE, "tooltip": Blockly.Msg.MATH_RANDOM_FLOAT_TOOLTIP, "helpUrl": Blockly.Msg.MATH_RANDOM_FLOAT_HELPURL }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.MATH_RANDOM_FLOAT_TITLE_RANDOM, "output": "Number", "colour": Blockly.Blocks.math.HUE, "tooltip": Blockly.Msg.MATH_RANDOM_FLOAT_TOOLTIP, "helpUrl": Blockly.Msg.MATH_RANDOM_FLOAT_HELPURL }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "MATH_RANDOM_FLOAT_TITLE_RANDOM", ",", "\"output\"", ":", "\"Number\"", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "math", ".", "HUE", ",", "\"tooltip\"", ":", "Blockly", ".", "Msg", ".", "MATH_RANDOM_FLOAT_TOOLTIP", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "MATH_RANDOM_FLOAT_HELPURL", "}", ")", ";", "}" ]
Block for random fraction between 0 and 1. @this Blockly.Block
[ "Block", "for", "random", "fraction", "between", "0", "and", "1", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/math.js#L544-L552
18,935
webduinoio/webduino-blockly
components/blockly-src/generators/php/lists.js
cacheList
function cacheList() { if (list.match(/^\w+$/)) { return ''; } var listVar = Blockly.PHP.variableDB_.getDistinctName( 'tmp_list', Blockly.Variables.NAME_TYPE); var code = listVar + ' = &' + list + ';\n'; list = listVar; return code; }
javascript
function cacheList() { if (list.match(/^\w+$/)) { return ''; } var listVar = Blockly.PHP.variableDB_.getDistinctName( 'tmp_list', Blockly.Variables.NAME_TYPE); var code = listVar + ' = &' + list + ';\n'; list = listVar; return code; }
[ "function", "cacheList", "(", ")", "{", "if", "(", "list", ".", "match", "(", "/", "^\\w+$", "/", ")", ")", "{", "return", "''", ";", "}", "var", "listVar", "=", "Blockly", ".", "PHP", ".", "variableDB_", ".", "getDistinctName", "(", "'tmp_list'", ",", "Blockly", ".", "Variables", ".", "NAME_TYPE", ")", ";", "var", "code", "=", "listVar", "+", "' = &'", "+", "list", "+", "';\\n'", ";", "list", "=", "listVar", ";", "return", "code", ";", "}" ]
Cache non-trivial values to variables to prevent repeated look-ups. Closure, which accesses and modifies 'list'.
[ "Cache", "non", "-", "trivial", "values", "to", "variables", "to", "prevent", "repeated", "look", "-", "ups", ".", "Closure", "which", "accesses", "and", "modifies", "list", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/generators/php/lists.js#L236-L245
18,936
webduinoio/webduino-blockly
components/blockly-src/blocks/lists.js
function() { this.setHelpUrl(Blockly.Msg.LISTS_CREATE_WITH_HELPURL); this.setColour(Blockly.Blocks.lists.HUE); this.itemCount_ = 3; this.updateShape_(); this.setOutput(true, 'Array'); this.setMutator(new Blockly.Mutator(['lists_create_with_item'])); this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_TOOLTIP); }
javascript
function() { this.setHelpUrl(Blockly.Msg.LISTS_CREATE_WITH_HELPURL); this.setColour(Blockly.Blocks.lists.HUE); this.itemCount_ = 3; this.updateShape_(); this.setOutput(true, 'Array'); this.setMutator(new Blockly.Mutator(['lists_create_with_item'])); this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_TOOLTIP); }
[ "function", "(", ")", "{", "this", ".", "setHelpUrl", "(", "Blockly", ".", "Msg", ".", "LISTS_CREATE_WITH_HELPURL", ")", ";", "this", ".", "setColour", "(", "Blockly", ".", "Blocks", ".", "lists", ".", "HUE", ")", ";", "this", ".", "itemCount_", "=", "3", ";", "this", ".", "updateShape_", "(", ")", ";", "this", ".", "setOutput", "(", "true", ",", "'Array'", ")", ";", "this", ".", "setMutator", "(", "new", "Blockly", ".", "Mutator", "(", "[", "'lists_create_with_item'", "]", ")", ")", ";", "this", ".", "setTooltip", "(", "Blockly", ".", "Msg", ".", "LISTS_CREATE_WITH_TOOLTIP", ")", ";", "}" ]
Block for creating a list with any number of elements of any type. @this Blockly.Block
[ "Block", "for", "creating", "a", "list", "with", "any", "number", "of", "elements", "of", "any", "type", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/lists.js#L62-L70
18,937
webduinoio/webduino-blockly
components/blockly-src/blocks/lists.js
function() { this.setColour(Blockly.Blocks.lists.HUE); this.appendDummyInput() .appendField(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TITLE); this.setPreviousStatement(true); this.setNextStatement(true); this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TOOLTIP); this.contextMenu = false; }
javascript
function() { this.setColour(Blockly.Blocks.lists.HUE); this.appendDummyInput() .appendField(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TITLE); this.setPreviousStatement(true); this.setNextStatement(true); this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TOOLTIP); this.contextMenu = false; }
[ "function", "(", ")", "{", "this", ".", "setColour", "(", "Blockly", ".", "Blocks", ".", "lists", ".", "HUE", ")", ";", "this", ".", "appendDummyInput", "(", ")", ".", "appendField", "(", "Blockly", ".", "Msg", ".", "LISTS_CREATE_WITH_ITEM_TITLE", ")", ";", "this", ".", "setPreviousStatement", "(", "true", ")", ";", "this", ".", "setNextStatement", "(", "true", ")", ";", "this", ".", "setTooltip", "(", "Blockly", ".", "Msg", ".", "LISTS_CREATE_WITH_ITEM_TOOLTIP", ")", ";", "this", ".", "contextMenu", "=", "false", ";", "}" ]
Mutator bolck for adding items. @this Blockly.Block
[ "Mutator", "bolck", "for", "adding", "items", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/lists.js#L201-L209
18,938
webduinoio/webduino-blockly
components/blockly-src/blocks/lists.js
function() { this.jsonInit({ "message0": Blockly.Msg.LISTS_REPEAT_TITLE, "args0": [ { "type": "input_value", "name": "ITEM" }, { "type": "input_value", "name": "NUM", "check": "Number" } ], "output": "Array", "colour": Blockly.Blocks.lists.HUE, "tooltip": Blockly.Msg.LISTS_REPEAT_TOOLTIP, "helpUrl": Blockly.Msg.LISTS_REPEAT_HELPURL }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.LISTS_REPEAT_TITLE, "args0": [ { "type": "input_value", "name": "ITEM" }, { "type": "input_value", "name": "NUM", "check": "Number" } ], "output": "Array", "colour": Blockly.Blocks.lists.HUE, "tooltip": Blockly.Msg.LISTS_REPEAT_TOOLTIP, "helpUrl": Blockly.Msg.LISTS_REPEAT_HELPURL }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "LISTS_REPEAT_TITLE", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"ITEM\"", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"NUM\"", ",", "\"check\"", ":", "\"Number\"", "}", "]", ",", "\"output\"", ":", "\"Array\"", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "lists", ".", "HUE", ",", "\"tooltip\"", ":", "Blockly", ".", "Msg", ".", "LISTS_REPEAT_TOOLTIP", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "LISTS_REPEAT_HELPURL", "}", ")", ";", "}" ]
Block for creating a list with one element repeated. @this Blockly.Block
[ "Block", "for", "creating", "a", "list", "with", "one", "element", "repeated", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/lists.js#L217-L236
18,939
webduinoio/webduino-blockly
components/blockly-src/blocks/lists.js
function() { this.jsonInit({ "message0": Blockly.Msg.LISTS_LENGTH_TITLE, "args0": [ { "type": "input_value", "name": "VALUE", "check": ['String', 'Array'] } ], "output": 'Number', "colour": Blockly.Blocks.lists.HUE, "tooltip": Blockly.Msg.LISTS_LENGTH_TOOLTIP, "helpUrl": Blockly.Msg.LISTS_LENGTH_HELPURL }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.LISTS_LENGTH_TITLE, "args0": [ { "type": "input_value", "name": "VALUE", "check": ['String', 'Array'] } ], "output": 'Number', "colour": Blockly.Blocks.lists.HUE, "tooltip": Blockly.Msg.LISTS_LENGTH_TOOLTIP, "helpUrl": Blockly.Msg.LISTS_LENGTH_HELPURL }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "LISTS_LENGTH_TITLE", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"VALUE\"", ",", "\"check\"", ":", "[", "'String'", ",", "'Array'", "]", "}", "]", ",", "\"output\"", ":", "'Number'", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "lists", ".", "HUE", ",", "\"tooltip\"", ":", "Blockly", ".", "Msg", ".", "LISTS_LENGTH_TOOLTIP", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "LISTS_LENGTH_HELPURL", "}", ")", ";", "}" ]
Block for list length. @this Blockly.Block
[ "Block", "for", "list", "length", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/lists.js#L244-L259
18,940
webduinoio/webduino-blockly
components/blockly-src/blocks/lists.js
function() { this.jsonInit({ "message0": Blockly.Msg.LISTS_ISEMPTY_TITLE, "args0": [ { "type": "input_value", "name": "VALUE", "check": ['String', 'Array'] } ], "output": 'Boolean', "colour": Blockly.Blocks.lists.HUE, "tooltip": Blockly.Msg.LISTS_ISEMPTY_TOOLTIP, "helpUrl": Blockly.Msg.LISTS_ISEMPTY_HELPURL }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.LISTS_ISEMPTY_TITLE, "args0": [ { "type": "input_value", "name": "VALUE", "check": ['String', 'Array'] } ], "output": 'Boolean', "colour": Blockly.Blocks.lists.HUE, "tooltip": Blockly.Msg.LISTS_ISEMPTY_TOOLTIP, "helpUrl": Blockly.Msg.LISTS_ISEMPTY_HELPURL }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "LISTS_ISEMPTY_TITLE", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"VALUE\"", ",", "\"check\"", ":", "[", "'String'", ",", "'Array'", "]", "}", "]", ",", "\"output\"", ":", "'Boolean'", ",", "\"colour\"", ":", "Blockly", ".", "Blocks", ".", "lists", ".", "HUE", ",", "\"tooltip\"", ":", "Blockly", ".", "Msg", ".", "LISTS_ISEMPTY_TOOLTIP", ",", "\"helpUrl\"", ":", "Blockly", ".", "Msg", ".", "LISTS_ISEMPTY_HELPURL", "}", ")", ";", "}" ]
Block for is the list empty? @this Blockly.Block
[ "Block", "for", "is", "the", "list", "empty?" ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/lists.js#L267-L282
18,941
webduinoio/webduino-blockly
components/blockly-src/blocks/lists.js
function() { var MODE = [[Blockly.Msg.LISTS_GET_INDEX_GET, 'GET'], [Blockly.Msg.LISTS_GET_INDEX_GET_REMOVE, 'GET_REMOVE'], [Blockly.Msg.LISTS_GET_INDEX_REMOVE, 'REMOVE']]; this.WHERE_OPTIONS = [[Blockly.Msg.LISTS_GET_INDEX_FROM_START, 'FROM_START'], [Blockly.Msg.LISTS_GET_INDEX_FROM_END, 'FROM_END'], [Blockly.Msg.LISTS_GET_INDEX_FIRST, 'FIRST'], [Blockly.Msg.LISTS_GET_INDEX_LAST, 'LAST'], [Blockly.Msg.LISTS_GET_INDEX_RANDOM, 'RANDOM']]; this.setHelpUrl(Blockly.Msg.LISTS_GET_INDEX_HELPURL); this.setColour(Blockly.Blocks.lists.HUE); var modeMenu = new Blockly.FieldDropdown(MODE, function(value) { var isStatement = (value == 'REMOVE'); this.sourceBlock_.updateStatement_(isStatement); }); this.appendValueInput('VALUE') .setCheck('Array') .appendField(Blockly.Msg.LISTS_GET_INDEX_INPUT_IN_LIST); this.appendDummyInput() .appendField(modeMenu, 'MODE') .appendField('', 'SPACE'); this.appendDummyInput('AT'); if (Blockly.Msg.LISTS_GET_INDEX_TAIL) { this.appendDummyInput('TAIL') .appendField(Blockly.Msg.LISTS_GET_INDEX_TAIL); } this.setInputsInline(true); this.setOutput(true); this.updateAt_(true); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; this.setTooltip(function() { var combo = thisBlock.getFieldValue('MODE') + '_' + thisBlock.getFieldValue('WHERE'); return Blockly.Msg['LISTS_GET_INDEX_TOOLTIP_' + combo]; }); }
javascript
function() { var MODE = [[Blockly.Msg.LISTS_GET_INDEX_GET, 'GET'], [Blockly.Msg.LISTS_GET_INDEX_GET_REMOVE, 'GET_REMOVE'], [Blockly.Msg.LISTS_GET_INDEX_REMOVE, 'REMOVE']]; this.WHERE_OPTIONS = [[Blockly.Msg.LISTS_GET_INDEX_FROM_START, 'FROM_START'], [Blockly.Msg.LISTS_GET_INDEX_FROM_END, 'FROM_END'], [Blockly.Msg.LISTS_GET_INDEX_FIRST, 'FIRST'], [Blockly.Msg.LISTS_GET_INDEX_LAST, 'LAST'], [Blockly.Msg.LISTS_GET_INDEX_RANDOM, 'RANDOM']]; this.setHelpUrl(Blockly.Msg.LISTS_GET_INDEX_HELPURL); this.setColour(Blockly.Blocks.lists.HUE); var modeMenu = new Blockly.FieldDropdown(MODE, function(value) { var isStatement = (value == 'REMOVE'); this.sourceBlock_.updateStatement_(isStatement); }); this.appendValueInput('VALUE') .setCheck('Array') .appendField(Blockly.Msg.LISTS_GET_INDEX_INPUT_IN_LIST); this.appendDummyInput() .appendField(modeMenu, 'MODE') .appendField('', 'SPACE'); this.appendDummyInput('AT'); if (Blockly.Msg.LISTS_GET_INDEX_TAIL) { this.appendDummyInput('TAIL') .appendField(Blockly.Msg.LISTS_GET_INDEX_TAIL); } this.setInputsInline(true); this.setOutput(true); this.updateAt_(true); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; this.setTooltip(function() { var combo = thisBlock.getFieldValue('MODE') + '_' + thisBlock.getFieldValue('WHERE'); return Blockly.Msg['LISTS_GET_INDEX_TOOLTIP_' + combo]; }); }
[ "function", "(", ")", "{", "var", "MODE", "=", "[", "[", "Blockly", ".", "Msg", ".", "LISTS_GET_INDEX_GET", ",", "'GET'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LISTS_GET_INDEX_GET_REMOVE", ",", "'GET_REMOVE'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LISTS_GET_INDEX_REMOVE", ",", "'REMOVE'", "]", "]", ";", "this", ".", "WHERE_OPTIONS", "=", "[", "[", "Blockly", ".", "Msg", ".", "LISTS_GET_INDEX_FROM_START", ",", "'FROM_START'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LISTS_GET_INDEX_FROM_END", ",", "'FROM_END'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LISTS_GET_INDEX_FIRST", ",", "'FIRST'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LISTS_GET_INDEX_LAST", ",", "'LAST'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LISTS_GET_INDEX_RANDOM", ",", "'RANDOM'", "]", "]", ";", "this", ".", "setHelpUrl", "(", "Blockly", ".", "Msg", ".", "LISTS_GET_INDEX_HELPURL", ")", ";", "this", ".", "setColour", "(", "Blockly", ".", "Blocks", ".", "lists", ".", "HUE", ")", ";", "var", "modeMenu", "=", "new", "Blockly", ".", "FieldDropdown", "(", "MODE", ",", "function", "(", "value", ")", "{", "var", "isStatement", "=", "(", "value", "==", "'REMOVE'", ")", ";", "this", ".", "sourceBlock_", ".", "updateStatement_", "(", "isStatement", ")", ";", "}", ")", ";", "this", ".", "appendValueInput", "(", "'VALUE'", ")", ".", "setCheck", "(", "'Array'", ")", ".", "appendField", "(", "Blockly", ".", "Msg", ".", "LISTS_GET_INDEX_INPUT_IN_LIST", ")", ";", "this", ".", "appendDummyInput", "(", ")", ".", "appendField", "(", "modeMenu", ",", "'MODE'", ")", ".", "appendField", "(", "''", ",", "'SPACE'", ")", ";", "this", ".", "appendDummyInput", "(", "'AT'", ")", ";", "if", "(", "Blockly", ".", "Msg", ".", "LISTS_GET_INDEX_TAIL", ")", "{", "this", ".", "appendDummyInput", "(", "'TAIL'", ")", ".", "appendField", "(", "Blockly", ".", "Msg", ".", "LISTS_GET_INDEX_TAIL", ")", ";", "}", "this", ".", "setInputsInline", "(", "true", ")", ";", "this", ".", "setOutput", "(", "true", ")", ";", "this", ".", "updateAt_", "(", "true", ")", ";", "// Assign 'this' to a variable for use in the tooltip closure below.", "var", "thisBlock", "=", "this", ";", "this", ".", "setTooltip", "(", "function", "(", ")", "{", "var", "combo", "=", "thisBlock", ".", "getFieldValue", "(", "'MODE'", ")", "+", "'_'", "+", "thisBlock", ".", "getFieldValue", "(", "'WHERE'", ")", ";", "return", "Blockly", ".", "Msg", "[", "'LISTS_GET_INDEX_TOOLTIP_'", "+", "combo", "]", ";", "}", ")", ";", "}" ]
Block for getting element at index. @this Blockly.Block
[ "Block", "for", "getting", "element", "at", "index", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/lists.js#L312-L350
18,942
webduinoio/webduino-blockly
components/blockly-src/blocks/lists.js
function() { var container = document.createElement('mutation'); var isStatement = !this.outputConnection; container.setAttribute('statement', isStatement); var isAt = this.getInput('AT').type == Blockly.INPUT_VALUE; container.setAttribute('at', isAt); return container; }
javascript
function() { var container = document.createElement('mutation'); var isStatement = !this.outputConnection; container.setAttribute('statement', isStatement); var isAt = this.getInput('AT').type == Blockly.INPUT_VALUE; container.setAttribute('at', isAt); return container; }
[ "function", "(", ")", "{", "var", "container", "=", "document", ".", "createElement", "(", "'mutation'", ")", ";", "var", "isStatement", "=", "!", "this", ".", "outputConnection", ";", "container", ".", "setAttribute", "(", "'statement'", ",", "isStatement", ")", ";", "var", "isAt", "=", "this", ".", "getInput", "(", "'AT'", ")", ".", "type", "==", "Blockly", ".", "INPUT_VALUE", ";", "container", ".", "setAttribute", "(", "'at'", ",", "isAt", ")", ";", "return", "container", ";", "}" ]
Create XML to represent whether the block is a statement or a value. Also represent whether there is an 'AT' input. @return {Element} XML storage element. @this Blockly.Block
[ "Create", "XML", "to", "represent", "whether", "the", "block", "is", "a", "statement", "or", "a", "value", ".", "Also", "represent", "whether", "there", "is", "an", "AT", "input", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/lists.js#L357-L364
18,943
webduinoio/webduino-blockly
components/blockly-src/blocks/lists.js
function(xmlElement) { // Note: Until January 2013 this block did not have mutations, // so 'statement' defaults to false and 'at' defaults to true. var isStatement = (xmlElement.getAttribute('statement') == 'true'); this.updateStatement_(isStatement); var isAt = (xmlElement.getAttribute('at') != 'false'); this.updateAt_(isAt); }
javascript
function(xmlElement) { // Note: Until January 2013 this block did not have mutations, // so 'statement' defaults to false and 'at' defaults to true. var isStatement = (xmlElement.getAttribute('statement') == 'true'); this.updateStatement_(isStatement); var isAt = (xmlElement.getAttribute('at') != 'false'); this.updateAt_(isAt); }
[ "function", "(", "xmlElement", ")", "{", "// Note: Until January 2013 this block did not have mutations,", "// so 'statement' defaults to false and 'at' defaults to true.", "var", "isStatement", "=", "(", "xmlElement", ".", "getAttribute", "(", "'statement'", ")", "==", "'true'", ")", ";", "this", ".", "updateStatement_", "(", "isStatement", ")", ";", "var", "isAt", "=", "(", "xmlElement", ".", "getAttribute", "(", "'at'", ")", "!=", "'false'", ")", ";", "this", ".", "updateAt_", "(", "isAt", ")", ";", "}" ]
Parse XML to restore the 'AT' input. @param {!Element} xmlElement XML storage element. @this Blockly.Block
[ "Parse", "XML", "to", "restore", "the", "AT", "input", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/lists.js#L370-L377
18,944
webduinoio/webduino-blockly
components/blockly-src/blocks/lists.js
function(newStatement) { var oldStatement = !this.outputConnection; if (newStatement != oldStatement) { this.unplug(true, true); if (newStatement) { this.setOutput(false); this.setPreviousStatement(true); this.setNextStatement(true); } else { this.setPreviousStatement(false); this.setNextStatement(false); this.setOutput(true); } } }
javascript
function(newStatement) { var oldStatement = !this.outputConnection; if (newStatement != oldStatement) { this.unplug(true, true); if (newStatement) { this.setOutput(false); this.setPreviousStatement(true); this.setNextStatement(true); } else { this.setPreviousStatement(false); this.setNextStatement(false); this.setOutput(true); } } }
[ "function", "(", "newStatement", ")", "{", "var", "oldStatement", "=", "!", "this", ".", "outputConnection", ";", "if", "(", "newStatement", "!=", "oldStatement", ")", "{", "this", ".", "unplug", "(", "true", ",", "true", ")", ";", "if", "(", "newStatement", ")", "{", "this", ".", "setOutput", "(", "false", ")", ";", "this", ".", "setPreviousStatement", "(", "true", ")", ";", "this", ".", "setNextStatement", "(", "true", ")", ";", "}", "else", "{", "this", ".", "setPreviousStatement", "(", "false", ")", ";", "this", ".", "setNextStatement", "(", "false", ")", ";", "this", ".", "setOutput", "(", "true", ")", ";", "}", "}", "}" ]
Switch between a value block and a statement block. @param {boolean} newStatement True if the block should be a statement. False if the block should be a value. @private @this Blockly.Block
[ "Switch", "between", "a", "value", "block", "and", "a", "statement", "block", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/lists.js#L385-L399
18,945
webduinoio/webduino-blockly
components/blockly-src/blocks/lists.js
function() { // Assign 'this' to a variable for use in the closures below. var thisBlock = this; var dropdown = new Blockly.FieldDropdown( [[Blockly.Msg.LISTS_SPLIT_LIST_FROM_TEXT, 'SPLIT'], [Blockly.Msg.LISTS_SPLIT_TEXT_FROM_LIST, 'JOIN']], function(newMode) { thisBlock.updateType_(newMode); }); this.setHelpUrl(Blockly.Msg.LISTS_SPLIT_HELPURL); this.setColour(Blockly.Blocks.lists.HUE); this.appendValueInput('INPUT') .setCheck('String') .appendField(dropdown, 'MODE'); this.appendValueInput('DELIM') .setCheck('String') .appendField(Blockly.Msg.LISTS_SPLIT_WITH_DELIMITER); this.setInputsInline(true); this.setOutput(true, 'Array'); this.setTooltip(function() { var mode = thisBlock.getFieldValue('MODE'); if (mode == 'SPLIT') { return Blockly.Msg.LISTS_SPLIT_TOOLTIP_SPLIT; } else if (mode == 'JOIN') { return Blockly.Msg.LISTS_SPLIT_TOOLTIP_JOIN; } throw 'Unknown mode: ' + mode; }); }
javascript
function() { // Assign 'this' to a variable for use in the closures below. var thisBlock = this; var dropdown = new Blockly.FieldDropdown( [[Blockly.Msg.LISTS_SPLIT_LIST_FROM_TEXT, 'SPLIT'], [Blockly.Msg.LISTS_SPLIT_TEXT_FROM_LIST, 'JOIN']], function(newMode) { thisBlock.updateType_(newMode); }); this.setHelpUrl(Blockly.Msg.LISTS_SPLIT_HELPURL); this.setColour(Blockly.Blocks.lists.HUE); this.appendValueInput('INPUT') .setCheck('String') .appendField(dropdown, 'MODE'); this.appendValueInput('DELIM') .setCheck('String') .appendField(Blockly.Msg.LISTS_SPLIT_WITH_DELIMITER); this.setInputsInline(true); this.setOutput(true, 'Array'); this.setTooltip(function() { var mode = thisBlock.getFieldValue('MODE'); if (mode == 'SPLIT') { return Blockly.Msg.LISTS_SPLIT_TOOLTIP_SPLIT; } else if (mode == 'JOIN') { return Blockly.Msg.LISTS_SPLIT_TOOLTIP_JOIN; } throw 'Unknown mode: ' + mode; }); }
[ "function", "(", ")", "{", "// Assign 'this' to a variable for use in the closures below.", "var", "thisBlock", "=", "this", ";", "var", "dropdown", "=", "new", "Blockly", ".", "FieldDropdown", "(", "[", "[", "Blockly", ".", "Msg", ".", "LISTS_SPLIT_LIST_FROM_TEXT", ",", "'SPLIT'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LISTS_SPLIT_TEXT_FROM_LIST", ",", "'JOIN'", "]", "]", ",", "function", "(", "newMode", ")", "{", "thisBlock", ".", "updateType_", "(", "newMode", ")", ";", "}", ")", ";", "this", ".", "setHelpUrl", "(", "Blockly", ".", "Msg", ".", "LISTS_SPLIT_HELPURL", ")", ";", "this", ".", "setColour", "(", "Blockly", ".", "Blocks", ".", "lists", ".", "HUE", ")", ";", "this", ".", "appendValueInput", "(", "'INPUT'", ")", ".", "setCheck", "(", "'String'", ")", ".", "appendField", "(", "dropdown", ",", "'MODE'", ")", ";", "this", ".", "appendValueInput", "(", "'DELIM'", ")", ".", "setCheck", "(", "'String'", ")", ".", "appendField", "(", "Blockly", ".", "Msg", ".", "LISTS_SPLIT_WITH_DELIMITER", ")", ";", "this", ".", "setInputsInline", "(", "true", ")", ";", "this", ".", "setOutput", "(", "true", ",", "'Array'", ")", ";", "this", ".", "setTooltip", "(", "function", "(", ")", "{", "var", "mode", "=", "thisBlock", ".", "getFieldValue", "(", "'MODE'", ")", ";", "if", "(", "mode", "==", "'SPLIT'", ")", "{", "return", "Blockly", ".", "Msg", ".", "LISTS_SPLIT_TOOLTIP_SPLIT", ";", "}", "else", "if", "(", "mode", "==", "'JOIN'", ")", "{", "return", "Blockly", ".", "Msg", ".", "LISTS_SPLIT_TOOLTIP_JOIN", ";", "}", "throw", "'Unknown mode: '", "+", "mode", ";", "}", ")", ";", "}" ]
Block for splitting text into a list, or joining a list into text. @this Blockly.Block
[ "Block", "for", "splitting", "text", "into", "a", "list", "or", "joining", "a", "list", "into", "text", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/lists.js#L651-L679
18,946
webduinoio/webduino-blockly
components/blockly-src/blocks/lists.js
function(newMode) { if (newMode == 'SPLIT') { this.outputConnection.setCheck('Array'); this.getInput('INPUT').setCheck('String'); } else { this.outputConnection.setCheck('String'); this.getInput('INPUT').setCheck('Array'); } }
javascript
function(newMode) { if (newMode == 'SPLIT') { this.outputConnection.setCheck('Array'); this.getInput('INPUT').setCheck('String'); } else { this.outputConnection.setCheck('String'); this.getInput('INPUT').setCheck('Array'); } }
[ "function", "(", "newMode", ")", "{", "if", "(", "newMode", "==", "'SPLIT'", ")", "{", "this", ".", "outputConnection", ".", "setCheck", "(", "'Array'", ")", ";", "this", ".", "getInput", "(", "'INPUT'", ")", ".", "setCheck", "(", "'String'", ")", ";", "}", "else", "{", "this", ".", "outputConnection", ".", "setCheck", "(", "'String'", ")", ";", "this", ".", "getInput", "(", "'INPUT'", ")", ".", "setCheck", "(", "'Array'", ")", ";", "}", "}" ]
Modify this block to have the correct input and output types. @param {string} newMode Either 'SPLIT' or 'JOIN'. @private @this Blockly.Block
[ "Modify", "this", "block", "to", "have", "the", "correct", "input", "and", "output", "types", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/blocks/lists.js#L686-L694
18,947
webduinoio/webduino-blockly
components/blockly-src/generators/python/loops.js
function(arg, suffix) { if (Blockly.isNumber(arg)) { // Simple number. arg = parseFloat(arg); } else if (arg.match(/^\w+$/)) { // Variable. arg = 'float(' + arg + ')'; } else { // It's complicated. var varName = Blockly.Python.variableDB_.getDistinctName( variable0 + suffix, Blockly.Variables.NAME_TYPE); code += varName + ' = float(' + arg + ')\n'; arg = varName; } return arg; }
javascript
function(arg, suffix) { if (Blockly.isNumber(arg)) { // Simple number. arg = parseFloat(arg); } else if (arg.match(/^\w+$/)) { // Variable. arg = 'float(' + arg + ')'; } else { // It's complicated. var varName = Blockly.Python.variableDB_.getDistinctName( variable0 + suffix, Blockly.Variables.NAME_TYPE); code += varName + ' = float(' + arg + ')\n'; arg = varName; } return arg; }
[ "function", "(", "arg", ",", "suffix", ")", "{", "if", "(", "Blockly", ".", "isNumber", "(", "arg", ")", ")", "{", "// Simple number.", "arg", "=", "parseFloat", "(", "arg", ")", ";", "}", "else", "if", "(", "arg", ".", "match", "(", "/", "^\\w+$", "/", ")", ")", "{", "// Variable.", "arg", "=", "'float('", "+", "arg", "+", "')'", ";", "}", "else", "{", "// It's complicated.", "var", "varName", "=", "Blockly", ".", "Python", ".", "variableDB_", ".", "getDistinctName", "(", "variable0", "+", "suffix", ",", "Blockly", ".", "Variables", ".", "NAME_TYPE", ")", ";", "code", "+=", "varName", "+", "' = float('", "+", "arg", "+", "')\\n'", ";", "arg", "=", "varName", ";", "}", "return", "arg", ";", "}" ]
Cache non-trivial values to variables to prevent repeated look-ups.
[ "Cache", "non", "-", "trivial", "values", "to", "variables", "to", "prevent", "repeated", "look", "-", "ups", "." ]
f656474c6e4ba1fc12fda217280714c3ca044bbe
https://github.com/webduinoio/webduino-blockly/blob/f656474c6e4ba1fc12fda217280714c3ca044bbe/components/blockly-src/generators/python/loops.js#L154-L169
18,948
h2non/rocky
lib/rocky.js
Rocky
function Rocky (opts) { if (!(this instanceof Rocky)) return new Rocky(opts) opts = opts || {} Base.call(this, opts) this.server = null this.router = router(opts.router) this._setupMiddleware() }
javascript
function Rocky (opts) { if (!(this instanceof Rocky)) return new Rocky(opts) opts = opts || {} Base.call(this, opts) this.server = null this.router = router(opts.router) this._setupMiddleware() }
[ "function", "Rocky", "(", "opts", ")", "{", "if", "(", "!", "(", "this", "instanceof", "Rocky", ")", ")", "return", "new", "Rocky", "(", "opts", ")", "opts", "=", "opts", "||", "{", "}", "Base", ".", "call", "(", "this", ",", "opts", ")", "this", ".", "server", "=", "null", "this", ".", "router", "=", "router", "(", "opts", ".", "router", ")", "this", ".", "_setupMiddleware", "(", ")", "}" ]
Rocky implements an HTTP and WebSocket proxy with built-in router and hierarchical middleware layer. @param {Object} opts @class Rocky @extend Base @constructor
[ "Rocky", "implements", "an", "HTTP", "and", "WebSocket", "proxy", "with", "built", "-", "in", "router", "and", "hierarchical", "middleware", "layer", "." ]
10053ae457e169be0f118d599e1fd0919ba59331
https://github.com/h2non/rocky/blob/10053ae457e169be0f118d599e1fd0919ba59331/lib/rocky.js#L21-L29
18,949
lsm/alfa
src/store.js
setSingle
function setSingle(store, key, value, flag) { const { _store, _subscriptions } = store // Uncurry alfa action functions if (typeof value === 'function' && value.alfaAction) { value = value.alfaAction(store) } // Save the value to the store. _store[key] = value if (flag === 'merge') { return } // Call subscribed functions if we have. const subs = _subscriptions[key] if (subs) { var changed = { [key]: value } subs.forEach(function(subFn) { // Make sure the subFn is still legit at the time we are calling it since // all subscribing functions are actually `setStat`. And previous // `setState` calls could trigger unmount component which later `setState` // belongs to. // Need to make the below code reproducible by test. // var _subs = subscriptions[key] // if (_subs.indexOf(subFn) === -1) { // return // } if (subFn.maps) { var maps = subFn.maps Object.keys(maps).some(function(injectKey) { const realKey = maps[injectKey] if (realKey === key) { changed = { [injectKey]: value } return true } return false }) } subFn(changed) }) } }
javascript
function setSingle(store, key, value, flag) { const { _store, _subscriptions } = store // Uncurry alfa action functions if (typeof value === 'function' && value.alfaAction) { value = value.alfaAction(store) } // Save the value to the store. _store[key] = value if (flag === 'merge') { return } // Call subscribed functions if we have. const subs = _subscriptions[key] if (subs) { var changed = { [key]: value } subs.forEach(function(subFn) { // Make sure the subFn is still legit at the time we are calling it since // all subscribing functions are actually `setStat`. And previous // `setState` calls could trigger unmount component which later `setState` // belongs to. // Need to make the below code reproducible by test. // var _subs = subscriptions[key] // if (_subs.indexOf(subFn) === -1) { // return // } if (subFn.maps) { var maps = subFn.maps Object.keys(maps).some(function(injectKey) { const realKey = maps[injectKey] if (realKey === key) { changed = { [injectKey]: value } return true } return false }) } subFn(changed) }) } }
[ "function", "setSingle", "(", "store", ",", "key", ",", "value", ",", "flag", ")", "{", "const", "{", "_store", ",", "_subscriptions", "}", "=", "store", "// Uncurry alfa action functions", "if", "(", "typeof", "value", "===", "'function'", "&&", "value", ".", "alfaAction", ")", "{", "value", "=", "value", ".", "alfaAction", "(", "store", ")", "}", "// Save the value to the store.", "_store", "[", "key", "]", "=", "value", "if", "(", "flag", "===", "'merge'", ")", "{", "return", "}", "// Call subscribed functions if we have.", "const", "subs", "=", "_subscriptions", "[", "key", "]", "if", "(", "subs", ")", "{", "var", "changed", "=", "{", "[", "key", "]", ":", "value", "}", "subs", ".", "forEach", "(", "function", "(", "subFn", ")", "{", "// Make sure the subFn is still legit at the time we are calling it since", "// all subscribing functions are actually `setStat`. And previous", "// `setState` calls could trigger unmount component which later `setState`", "// belongs to.", "// Need to make the below code reproducible by test.", "// var _subs = subscriptions[key]", "// if (_subs.indexOf(subFn) === -1) {", "// return", "// }", "if", "(", "subFn", ".", "maps", ")", "{", "var", "maps", "=", "subFn", ".", "maps", "Object", ".", "keys", "(", "maps", ")", ".", "some", "(", "function", "(", "injectKey", ")", "{", "const", "realKey", "=", "maps", "[", "injectKey", "]", "if", "(", "realKey", "===", "key", ")", "{", "changed", "=", "{", "[", "injectKey", "]", ":", "value", "}", "return", "true", "}", "return", "false", "}", ")", "}", "subFn", "(", "changed", ")", "}", ")", "}", "}" ]
Set a single value to an object.
[ "Set", "a", "single", "value", "to", "an", "object", "." ]
a3ba606502ec4da5f86cfc7d1b3e964bb884028c
https://github.com/lsm/alfa/blob/a3ba606502ec4da5f86cfc7d1b3e964bb884028c/src/store.js#L181-L231
18,950
lsm/alfa
src/injection.js
getDynamicProps
function getDynamicProps({ keys, maps, inputs }, outputs, alfaStore) { const _props = getInjectedProps(inputs, outputs, alfaStore) if (maps) { keys.forEach(key => { _props[key] = _props[maps[key]] }) // Map outputs if (outputs && 'function' === typeof _props.set) { // The `set` of `props` which is obtained from calling // `alfaStore.setWithOutputs(outputs)` const _setWithOutputs = _props.set // Call `_setWithOutputs` with maps if _props.set = function(key, value) { _setWithOutputs(key, value, maps) } } return _props } else { // No mapped props return _props } }
javascript
function getDynamicProps({ keys, maps, inputs }, outputs, alfaStore) { const _props = getInjectedProps(inputs, outputs, alfaStore) if (maps) { keys.forEach(key => { _props[key] = _props[maps[key]] }) // Map outputs if (outputs && 'function' === typeof _props.set) { // The `set` of `props` which is obtained from calling // `alfaStore.setWithOutputs(outputs)` const _setWithOutputs = _props.set // Call `_setWithOutputs` with maps if _props.set = function(key, value) { _setWithOutputs(key, value, maps) } } return _props } else { // No mapped props return _props } }
[ "function", "getDynamicProps", "(", "{", "keys", ",", "maps", ",", "inputs", "}", ",", "outputs", ",", "alfaStore", ")", "{", "const", "_props", "=", "getInjectedProps", "(", "inputs", ",", "outputs", ",", "alfaStore", ")", "if", "(", "maps", ")", "{", "keys", ".", "forEach", "(", "key", "=>", "{", "_props", "[", "key", "]", "=", "_props", "[", "maps", "[", "key", "]", "]", "}", ")", "// Map outputs", "if", "(", "outputs", "&&", "'function'", "===", "typeof", "_props", ".", "set", ")", "{", "// The `set` of `props` which is obtained from calling", "// `alfaStore.setWithOutputs(outputs)`", "const", "_setWithOutputs", "=", "_props", ".", "set", "// Call `_setWithOutputs` with maps if", "_props", ".", "set", "=", "function", "(", "key", ",", "value", ")", "{", "_setWithOutputs", "(", "key", ",", "value", ",", "maps", ")", "}", "}", "return", "_props", "}", "else", "{", "// No mapped props", "return", "_props", "}", "}" ]
Load dependencies with the result of calling `keys` function of the component. This gives people the ability to load dynamic dependencies based on the props of the component at runtime. It makes a map between the dynamic names of the dependencies and the names of the properties injected in `state` of the component. That helps maintaining a simple naming system in the application code. @param {Function} keys @param {Object} props @param {Array} outputs @param {Object} alfaStore @return {Object}
[ "Load", "dependencies", "with", "the", "result", "of", "calling", "keys", "function", "of", "the", "component", "." ]
a3ba606502ec4da5f86cfc7d1b3e964bb884028c
https://github.com/lsm/alfa/blob/a3ba606502ec4da5f86cfc7d1b3e964bb884028c/src/injection.js#L205-L227
18,951
chrisdickinson/beefy
lib/setup-bundlers.js
setupBundler
function setupBundler(cwd, entryPoints, flags, noWatchify, ready) { noWatchify ? onlocalwatchify() : resolve('watchify', {basedir: cwd}, onlocalwatchify) function onlocalwatchify(err, localDir) { if(err || !localDir) { return resolve('browserify', {basedir: cwd}, onlocalbrowserify) } setupWatchify(path.dirname(localDir), entryPoints, flags, ready) } function onlocalbrowserify(err, localDir) { if(err || !localDir) { return findGlobals(onglobals) } setupBrowserify(path.dirname(localDir), entryPoints, flags, ready) } function onglobals(err, dirs) { if(err) { return ready(err) } dirs = dirs.sort() for(var i = 0, len = dirs.length; i < len; ++i) { if(!noWatchify && path.basename(dirs[i]) === 'watchify') { return setupWatchify(dirs[i], entryPoints, flags, ready) } if(path.basename(dirs[i]) === 'browserify') { return setupBrowserify(dirs[i], entryPoints, flags, ready) } } return ready(new Error('Could not find a suitable bundler!')) } }
javascript
function setupBundler(cwd, entryPoints, flags, noWatchify, ready) { noWatchify ? onlocalwatchify() : resolve('watchify', {basedir: cwd}, onlocalwatchify) function onlocalwatchify(err, localDir) { if(err || !localDir) { return resolve('browserify', {basedir: cwd}, onlocalbrowserify) } setupWatchify(path.dirname(localDir), entryPoints, flags, ready) } function onlocalbrowserify(err, localDir) { if(err || !localDir) { return findGlobals(onglobals) } setupBrowserify(path.dirname(localDir), entryPoints, flags, ready) } function onglobals(err, dirs) { if(err) { return ready(err) } dirs = dirs.sort() for(var i = 0, len = dirs.length; i < len; ++i) { if(!noWatchify && path.basename(dirs[i]) === 'watchify') { return setupWatchify(dirs[i], entryPoints, flags, ready) } if(path.basename(dirs[i]) === 'browserify') { return setupBrowserify(dirs[i], entryPoints, flags, ready) } } return ready(new Error('Could not find a suitable bundler!')) } }
[ "function", "setupBundler", "(", "cwd", ",", "entryPoints", ",", "flags", ",", "noWatchify", ",", "ready", ")", "{", "noWatchify", "?", "onlocalwatchify", "(", ")", ":", "resolve", "(", "'watchify'", ",", "{", "basedir", ":", "cwd", "}", ",", "onlocalwatchify", ")", "function", "onlocalwatchify", "(", "err", ",", "localDir", ")", "{", "if", "(", "err", "||", "!", "localDir", ")", "{", "return", "resolve", "(", "'browserify'", ",", "{", "basedir", ":", "cwd", "}", ",", "onlocalbrowserify", ")", "}", "setupWatchify", "(", "path", ".", "dirname", "(", "localDir", ")", ",", "entryPoints", ",", "flags", ",", "ready", ")", "}", "function", "onlocalbrowserify", "(", "err", ",", "localDir", ")", "{", "if", "(", "err", "||", "!", "localDir", ")", "{", "return", "findGlobals", "(", "onglobals", ")", "}", "setupBrowserify", "(", "path", ".", "dirname", "(", "localDir", ")", ",", "entryPoints", ",", "flags", ",", "ready", ")", "}", "function", "onglobals", "(", "err", ",", "dirs", ")", "{", "if", "(", "err", ")", "{", "return", "ready", "(", "err", ")", "}", "dirs", "=", "dirs", ".", "sort", "(", ")", "for", "(", "var", "i", "=", "0", ",", "len", "=", "dirs", ".", "length", ";", "i", "<", "len", ";", "++", "i", ")", "{", "if", "(", "!", "noWatchify", "&&", "path", ".", "basename", "(", "dirs", "[", "i", "]", ")", "===", "'watchify'", ")", "{", "return", "setupWatchify", "(", "dirs", "[", "i", "]", ",", "entryPoints", ",", "flags", ",", "ready", ")", "}", "if", "(", "path", ".", "basename", "(", "dirs", "[", "i", "]", ")", "===", "'browserify'", ")", "{", "return", "setupBrowserify", "(", "dirs", "[", "i", "]", ",", "entryPoints", ",", "flags", ",", "ready", ")", "}", "}", "return", "ready", "(", "new", "Error", "(", "'Could not find a suitable bundler!'", ")", ")", "}", "}" ]
local watchify, local browserify -> global watchify, global browserify
[ "local", "watchify", "local", "browserify", "-", ">", "global", "watchify", "global", "browserify" ]
7a4727851c3c318d8a866d14c4c2f9b93a064b08
https://github.com/chrisdickinson/beefy/blob/7a4727851c3c318d8a866d14c4c2f9b93a064b08/lib/setup-bundlers.js#L12-L52
18,952
danielpigott/cloudflare-cli
lib/formatters.js
TableFormatter
function TableFormatter(options) { const table = new Table(options); this.format = format; function format(result, formatOptions) { let data = []; _.each(result, function (item) { data.push(_.values(_.pick(item, options.values))); }); if (formatOptions.format === 'csv') { _.each(data, function(row) { console.log(row.join(',')); }); } else if ( formatOptions.format === 'json') { console.log(JSON.stringify(result)); } else { table.push.apply(table, data); console.log(table.toString()); } } }
javascript
function TableFormatter(options) { const table = new Table(options); this.format = format; function format(result, formatOptions) { let data = []; _.each(result, function (item) { data.push(_.values(_.pick(item, options.values))); }); if (formatOptions.format === 'csv') { _.each(data, function(row) { console.log(row.join(',')); }); } else if ( formatOptions.format === 'json') { console.log(JSON.stringify(result)); } else { table.push.apply(table, data); console.log(table.toString()); } } }
[ "function", "TableFormatter", "(", "options", ")", "{", "const", "table", "=", "new", "Table", "(", "options", ")", ";", "this", ".", "format", "=", "format", ";", "function", "format", "(", "result", ",", "formatOptions", ")", "{", "let", "data", "=", "[", "]", ";", "_", ".", "each", "(", "result", ",", "function", "(", "item", ")", "{", "data", ".", "push", "(", "_", ".", "values", "(", "_", ".", "pick", "(", "item", ",", "options", ".", "values", ")", ")", ")", ";", "}", ")", ";", "if", "(", "formatOptions", ".", "format", "===", "'csv'", ")", "{", "_", ".", "each", "(", "data", ",", "function", "(", "row", ")", "{", "console", ".", "log", "(", "row", ".", "join", "(", "','", ")", ")", ";", "}", ")", ";", "}", "else", "if", "(", "formatOptions", ".", "format", "===", "'json'", ")", "{", "console", ".", "log", "(", "JSON", ".", "stringify", "(", "result", ")", ")", ";", "}", "else", "{", "table", ".", "push", ".", "apply", "(", "table", ",", "data", ")", ";", "console", ".", "log", "(", "table", ".", "toString", "(", ")", ")", ";", "}", "}", "}" ]
Formatter to output tabular data @param options @constructor
[ "Formatter", "to", "output", "tabular", "data" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/lib/formatters.js#L9-L28
18,953
danielpigott/cloudflare-cli
lib/formatters.js
MessageFormatter
function MessageFormatter() { this.format = format; function format(result) { _.each(result, function(message) { console.log(message); }); } }
javascript
function MessageFormatter() { this.format = format; function format(result) { _.each(result, function(message) { console.log(message); }); } }
[ "function", "MessageFormatter", "(", ")", "{", "this", ".", "format", "=", "format", ";", "function", "format", "(", "result", ")", "{", "_", ".", "each", "(", "result", ",", "function", "(", "message", ")", "{", "console", ".", "log", "(", "message", ")", ";", "}", ")", ";", "}", "}" ]
Log plain messages @constructor
[ "Log", "plain", "messages" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/lib/formatters.js#L34-L41
18,954
danielpigott/cloudflare-cli
index.js
init
function init(options) { self.email = options.email; self.key = options.token; self.cloudflareClient = new CloudFlareClient(options.email, options.token); }
javascript
function init(options) { self.email = options.email; self.key = options.token; self.cloudflareClient = new CloudFlareClient(options.email, options.token); }
[ "function", "init", "(", "options", ")", "{", "self", ".", "email", "=", "options", ".", "email", ";", "self", ".", "key", "=", "options", ".", "token", ";", "self", ".", "cloudflareClient", "=", "new", "CloudFlareClient", "(", "options", ".", "email", ",", "options", ".", "token", ")", ";", "}" ]
Set up client @param options
[ "Set", "up", "client" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/index.js#L163-L167
18,955
danielpigott/cloudflare-cli
index.js
runCommand
function runCommand(command, options) { let cmd = getCommand(command); if (!cmd || command === 'help') { cmd = getCommand('help'); } else { try { validateConfig(options); } catch (error) { console.log(error.message); process.exit(1); } } let fn = cmd.callback; let opts = mapParams(cmd, options); fn(opts).then(function (result) { if (cmd.formatter) { cmd.formatter.format(result.messages, options); } else { console.log(result); } }).catch(function (error) { let formatter = new formatters.MessageFormatter(); if (error.response) { console.log(error); formatter.format(['Error response received: ' + error.response.data.errors[0].message]); } else { formatter.format([error.message]); } process.exit(1); }); }
javascript
function runCommand(command, options) { let cmd = getCommand(command); if (!cmd || command === 'help') { cmd = getCommand('help'); } else { try { validateConfig(options); } catch (error) { console.log(error.message); process.exit(1); } } let fn = cmd.callback; let opts = mapParams(cmd, options); fn(opts).then(function (result) { if (cmd.formatter) { cmd.formatter.format(result.messages, options); } else { console.log(result); } }).catch(function (error) { let formatter = new formatters.MessageFormatter(); if (error.response) { console.log(error); formatter.format(['Error response received: ' + error.response.data.errors[0].message]); } else { formatter.format([error.message]); } process.exit(1); }); }
[ "function", "runCommand", "(", "command", ",", "options", ")", "{", "let", "cmd", "=", "getCommand", "(", "command", ")", ";", "if", "(", "!", "cmd", "||", "command", "===", "'help'", ")", "{", "cmd", "=", "getCommand", "(", "'help'", ")", ";", "}", "else", "{", "try", "{", "validateConfig", "(", "options", ")", ";", "}", "catch", "(", "error", ")", "{", "console", ".", "log", "(", "error", ".", "message", ")", ";", "process", ".", "exit", "(", "1", ")", ";", "}", "}", "let", "fn", "=", "cmd", ".", "callback", ";", "let", "opts", "=", "mapParams", "(", "cmd", ",", "options", ")", ";", "fn", "(", "opts", ")", ".", "then", "(", "function", "(", "result", ")", "{", "if", "(", "cmd", ".", "formatter", ")", "{", "cmd", ".", "formatter", ".", "format", "(", "result", ".", "messages", ",", "options", ")", ";", "}", "else", "{", "console", ".", "log", "(", "result", ")", ";", "}", "}", ")", ".", "catch", "(", "function", "(", "error", ")", "{", "let", "formatter", "=", "new", "formatters", ".", "MessageFormatter", "(", ")", ";", "if", "(", "error", ".", "response", ")", "{", "console", ".", "log", "(", "error", ")", ";", "formatter", ".", "format", "(", "[", "'Error response received: '", "+", "error", ".", "response", ".", "data", ".", "errors", "[", "0", "]", ".", "message", "]", ")", ";", "}", "else", "{", "formatter", ".", "format", "(", "[", "error", ".", "message", "]", ")", ";", "}", "process", ".", "exit", "(", "1", ")", ";", "}", ")", ";", "}" ]
Run the given command and output the result @param command @param options
[ "Run", "the", "given", "command", "and", "output", "the", "result" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/index.js#L174-L205
18,956
danielpigott/cloudflare-cli
index.js
addRecord
function addRecord(options) { options.type = options.type || 'CNAME'; return getZone(options.domain) .then(function (zone) { return self.cloudflareClient.addRecord( zone.id, _.extend({ttl: 1}, mapRecordOptions(options))); }) .then(function (response) { return new Result([ format( 'Added %s record %s -> %s', response.data.result.type, response.data.result.name, response.data.result.content ) ]); } ) }
javascript
function addRecord(options) { options.type = options.type || 'CNAME'; return getZone(options.domain) .then(function (zone) { return self.cloudflareClient.addRecord( zone.id, _.extend({ttl: 1}, mapRecordOptions(options))); }) .then(function (response) { return new Result([ format( 'Added %s record %s -> %s', response.data.result.type, response.data.result.name, response.data.result.content ) ]); } ) }
[ "function", "addRecord", "(", "options", ")", "{", "options", ".", "type", "=", "options", ".", "type", "||", "'CNAME'", ";", "return", "getZone", "(", "options", ".", "domain", ")", ".", "then", "(", "function", "(", "zone", ")", "{", "return", "self", ".", "cloudflareClient", ".", "addRecord", "(", "zone", ".", "id", ",", "_", ".", "extend", "(", "{", "ttl", ":", "1", "}", ",", "mapRecordOptions", "(", "options", ")", ")", ")", ";", "}", ")", ".", "then", "(", "function", "(", "response", ")", "{", "return", "new", "Result", "(", "[", "format", "(", "'Added %s record %s -> %s'", ",", "response", ".", "data", ".", "result", ".", "type", ",", "response", ".", "data", ".", "result", ".", "name", ",", "response", ".", "data", ".", "result", ".", "content", ")", "]", ")", ";", "}", ")", "}" ]
Create a new record of the given type @param options @return {*}
[ "Create", "a", "new", "record", "of", "the", "given", "type" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/index.js#L212-L231
18,957
danielpigott/cloudflare-cli
index.js
editRecord
function editRecord(options) { return find(options.domain, getQueryParams(options, ['name', 'type', 'query'])).then(function (response) { const records = response.data.result; //Properties that are editable options = mapRecordOptions(options); if (records.length === 0) { throw new Error('No matching records found'); } else if (records.length === 1) { let record = records[0]; options.type = options.type || record.type; options.content = options.content || record.content; return self.cloudflareClient.editRecord(record.zone_id, record.id, options); } else { throw new Error(format('%d matching records found, unable to update', records.count)); } }).then(function (response) { let record = response.data.result; return new Result([ format('Updated %s record %s (id: %s)', record.type, record.name, record.id) ]); }); }
javascript
function editRecord(options) { return find(options.domain, getQueryParams(options, ['name', 'type', 'query'])).then(function (response) { const records = response.data.result; //Properties that are editable options = mapRecordOptions(options); if (records.length === 0) { throw new Error('No matching records found'); } else if (records.length === 1) { let record = records[0]; options.type = options.type || record.type; options.content = options.content || record.content; return self.cloudflareClient.editRecord(record.zone_id, record.id, options); } else { throw new Error(format('%d matching records found, unable to update', records.count)); } }).then(function (response) { let record = response.data.result; return new Result([ format('Updated %s record %s (id: %s)', record.type, record.name, record.id) ]); }); }
[ "function", "editRecord", "(", "options", ")", "{", "return", "find", "(", "options", ".", "domain", ",", "getQueryParams", "(", "options", ",", "[", "'name'", ",", "'type'", ",", "'query'", "]", ")", ")", ".", "then", "(", "function", "(", "response", ")", "{", "const", "records", "=", "response", ".", "data", ".", "result", ";", "//Properties that are editable", "options", "=", "mapRecordOptions", "(", "options", ")", ";", "if", "(", "records", ".", "length", "===", "0", ")", "{", "throw", "new", "Error", "(", "'No matching records found'", ")", ";", "}", "else", "if", "(", "records", ".", "length", "===", "1", ")", "{", "let", "record", "=", "records", "[", "0", "]", ";", "options", ".", "type", "=", "options", ".", "type", "||", "record", ".", "type", ";", "options", ".", "content", "=", "options", ".", "content", "||", "record", ".", "content", ";", "return", "self", ".", "cloudflareClient", ".", "editRecord", "(", "record", ".", "zone_id", ",", "record", ".", "id", ",", "options", ")", ";", "}", "else", "{", "throw", "new", "Error", "(", "format", "(", "'%d matching records found, unable to update'", ",", "records", ".", "count", ")", ")", ";", "}", "}", ")", ".", "then", "(", "function", "(", "response", ")", "{", "let", "record", "=", "response", ".", "data", ".", "result", ";", "return", "new", "Result", "(", "[", "format", "(", "'Updated %s record %s (id: %s)'", ",", "record", ".", "type", ",", "record", ".", "name", ",", "record", ".", "id", ")", "]", ")", ";", "}", ")", ";", "}" ]
Edit a record @param options @returns {Promise}
[ "Edit", "a", "record" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/index.js#L258-L279
18,958
danielpigott/cloudflare-cli
index.js
find
function find(domain, query) { if (query.name && !query.name.includes(domain)) { query.name = query.name + '.' + domain; } if (query.query) { query = _.extend(query, query.query); delete query.query; } return getZone(domain).then(function (zone) { return self.cloudflareClient.findRecord(zone.id, query); }); }
javascript
function find(domain, query) { if (query.name && !query.name.includes(domain)) { query.name = query.name + '.' + domain; } if (query.query) { query = _.extend(query, query.query); delete query.query; } return getZone(domain).then(function (zone) { return self.cloudflareClient.findRecord(zone.id, query); }); }
[ "function", "find", "(", "domain", ",", "query", ")", "{", "if", "(", "query", ".", "name", "&&", "!", "query", ".", "name", ".", "includes", "(", "domain", ")", ")", "{", "query", ".", "name", "=", "query", ".", "name", "+", "'.'", "+", "domain", ";", "}", "if", "(", "query", ".", "query", ")", "{", "query", "=", "_", ".", "extend", "(", "query", ",", "query", ".", "query", ")", ";", "delete", "query", ".", "query", ";", "}", "return", "getZone", "(", "domain", ")", ".", "then", "(", "function", "(", "zone", ")", "{", "return", "self", ".", "cloudflareClient", ".", "findRecord", "(", "zone", ".", "id", ",", "query", ")", ";", "}", ")", ";", "}" ]
Find a given record @param domain @param query @return {Promise}
[ "Find", "a", "given", "record" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/index.js#L324-L335
18,959
danielpigott/cloudflare-cli
index.js
listRecords
function listRecords(options) { return getZone(options.domain).then(function (zone) { return self.cloudflareClient.findRecord(zone.id, {page: 1, per_page: self.perPage}) .then(function (response) { let promises = [Promise.resolve(response)]; for (let i = 2; i <= response.data['result_info']['total_pages']; i++) { promises.push(self.cloudflareClient.findRecord(zone.id, {page: i, per_page: self.perPage})); } return Promise.all(promises); }); }).then(function (responses) { let rows = []; _.each(responses, function (response) { _.each(response.data.result, function (item) { item.ttl = (item.ttl === 1) ? 'Auto' : item.ttl; rows.push(item); }); }); return new Result(rows); }); }
javascript
function listRecords(options) { return getZone(options.domain).then(function (zone) { return self.cloudflareClient.findRecord(zone.id, {page: 1, per_page: self.perPage}) .then(function (response) { let promises = [Promise.resolve(response)]; for (let i = 2; i <= response.data['result_info']['total_pages']; i++) { promises.push(self.cloudflareClient.findRecord(zone.id, {page: i, per_page: self.perPage})); } return Promise.all(promises); }); }).then(function (responses) { let rows = []; _.each(responses, function (response) { _.each(response.data.result, function (item) { item.ttl = (item.ttl === 1) ? 'Auto' : item.ttl; rows.push(item); }); }); return new Result(rows); }); }
[ "function", "listRecords", "(", "options", ")", "{", "return", "getZone", "(", "options", ".", "domain", ")", ".", "then", "(", "function", "(", "zone", ")", "{", "return", "self", ".", "cloudflareClient", ".", "findRecord", "(", "zone", ".", "id", ",", "{", "page", ":", "1", ",", "per_page", ":", "self", ".", "perPage", "}", ")", ".", "then", "(", "function", "(", "response", ")", "{", "let", "promises", "=", "[", "Promise", ".", "resolve", "(", "response", ")", "]", ";", "for", "(", "let", "i", "=", "2", ";", "i", "<=", "response", ".", "data", "[", "'result_info'", "]", "[", "'total_pages'", "]", ";", "i", "++", ")", "{", "promises", ".", "push", "(", "self", ".", "cloudflareClient", ".", "findRecord", "(", "zone", ".", "id", ",", "{", "page", ":", "i", ",", "per_page", ":", "self", ".", "perPage", "}", ")", ")", ";", "}", "return", "Promise", ".", "all", "(", "promises", ")", ";", "}", ")", ";", "}", ")", ".", "then", "(", "function", "(", "responses", ")", "{", "let", "rows", "=", "[", "]", ";", "_", ".", "each", "(", "responses", ",", "function", "(", "response", ")", "{", "_", ".", "each", "(", "response", ".", "data", ".", "result", ",", "function", "(", "item", ")", "{", "item", ".", "ttl", "=", "(", "item", ".", "ttl", "===", "1", ")", "?", "'Auto'", ":", "item", ".", "ttl", ";", "rows", ".", "push", "(", "item", ")", ";", "}", ")", ";", "}", ")", ";", "return", "new", "Result", "(", "rows", ")", ";", "}", ")", ";", "}" ]
List records for given domain @param options @returns {Promise}
[ "List", "records", "for", "given", "domain" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/index.js#L342-L362
18,960
danielpigott/cloudflare-cli
index.js
listZones
function listZones() { return self.cloudflareClient.findZones({page: 1, per_page: self.perPage}) .then(function (response) { let promises = [Promise.resolve(response)]; for (let i = 2; i <= response.data['result_info']['total_pages']; i++) { promises.push(self.cloudflareClient.findZones({page: i, per_page: self.perPage})); } return Promise.all(promises); }) .then(function (responses) { let rows = []; _.each(responses, function (response) { _.each(response.data.result, function (item) { rows.push(_.extend( item, { planName: item.plan.name, accountName: item.account.name } )); }) }); return new Result(rows); }); }
javascript
function listZones() { return self.cloudflareClient.findZones({page: 1, per_page: self.perPage}) .then(function (response) { let promises = [Promise.resolve(response)]; for (let i = 2; i <= response.data['result_info']['total_pages']; i++) { promises.push(self.cloudflareClient.findZones({page: i, per_page: self.perPage})); } return Promise.all(promises); }) .then(function (responses) { let rows = []; _.each(responses, function (response) { _.each(response.data.result, function (item) { rows.push(_.extend( item, { planName: item.plan.name, accountName: item.account.name } )); }) }); return new Result(rows); }); }
[ "function", "listZones", "(", ")", "{", "return", "self", ".", "cloudflareClient", ".", "findZones", "(", "{", "page", ":", "1", ",", "per_page", ":", "self", ".", "perPage", "}", ")", ".", "then", "(", "function", "(", "response", ")", "{", "let", "promises", "=", "[", "Promise", ".", "resolve", "(", "response", ")", "]", ";", "for", "(", "let", "i", "=", "2", ";", "i", "<=", "response", ".", "data", "[", "'result_info'", "]", "[", "'total_pages'", "]", ";", "i", "++", ")", "{", "promises", ".", "push", "(", "self", ".", "cloudflareClient", ".", "findZones", "(", "{", "page", ":", "i", ",", "per_page", ":", "self", ".", "perPage", "}", ")", ")", ";", "}", "return", "Promise", ".", "all", "(", "promises", ")", ";", "}", ")", ".", "then", "(", "function", "(", "responses", ")", "{", "let", "rows", "=", "[", "]", ";", "_", ".", "each", "(", "responses", ",", "function", "(", "response", ")", "{", "_", ".", "each", "(", "response", ".", "data", ".", "result", ",", "function", "(", "item", ")", "{", "rows", ".", "push", "(", "_", ".", "extend", "(", "item", ",", "{", "planName", ":", "item", ".", "plan", ".", "name", ",", "accountName", ":", "item", ".", "account", ".", "name", "}", ")", ")", ";", "}", ")", "}", ")", ";", "return", "new", "Result", "(", "rows", ")", ";", "}", ")", ";", "}" ]
List zones in the current account @return {Promise}
[ "List", "zones", "in", "the", "current", "account" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/index.js#L397-L421
18,961
danielpigott/cloudflare-cli
index.js
purgeCache
function purgeCache(options) { return getZone(options.domain).then(function (zone) { let query = (options._[1]) ? {files: options._.slice(1)} : {purge_everything: true}; return self.cloudflareClient.purgeCache(zone.id, query); }).then(function () { return new Result('Purged cache successfully'); }); }
javascript
function purgeCache(options) { return getZone(options.domain).then(function (zone) { let query = (options._[1]) ? {files: options._.slice(1)} : {purge_everything: true}; return self.cloudflareClient.purgeCache(zone.id, query); }).then(function () { return new Result('Purged cache successfully'); }); }
[ "function", "purgeCache", "(", "options", ")", "{", "return", "getZone", "(", "options", ".", "domain", ")", ".", "then", "(", "function", "(", "zone", ")", "{", "let", "query", "=", "(", "options", ".", "_", "[", "1", "]", ")", "?", "{", "files", ":", "options", ".", "_", ".", "slice", "(", "1", ")", "}", ":", "{", "purge_everything", ":", "true", "}", ";", "return", "self", ".", "cloudflareClient", ".", "purgeCache", "(", "zone", ".", "id", ",", "query", ")", ";", "}", ")", ".", "then", "(", "function", "(", ")", "{", "return", "new", "Result", "(", "'Purged cache successfully'", ")", ";", "}", ")", ";", "}" ]
Purge files from cache @param options @returns {Promise}
[ "Purge", "files", "from", "cache" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/index.js#L441-L448
18,962
danielpigott/cloudflare-cli
index.js
getCommand
function getCommand(commandName) { return _.find(commands, function (command) { return _.includes(command.aliases, commandName); }); }
javascript
function getCommand(commandName) { return _.find(commands, function (command) { return _.includes(command.aliases, commandName); }); }
[ "function", "getCommand", "(", "commandName", ")", "{", "return", "_", ".", "find", "(", "commands", ",", "function", "(", "command", ")", "{", "return", "_", ".", "includes", "(", "command", ".", "aliases", ",", "commandName", ")", ";", "}", ")", ";", "}" ]
Get command from available commands by name @param commandName @return {Object}
[ "Get", "command", "from", "available", "commands", "by", "name" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/index.js#L474-L478
18,963
danielpigott/cloudflare-cli
index.js
mapRecordOptions
function mapRecordOptions(options) { if (options.type === 'SRV') { let contentParts = options.content.split(' '); let serverParts = options.name.split('.'); options.data = { service: serverParts[0], proto: serverParts[1], name: _.slice(serverParts, 2).join('.'), priority: parseInt(contentParts[0]), weight: parseInt(contentParts[1]), port: parseInt(contentParts[2]), target: contentParts[3] } } if (options.activate !== undefined) { options.proxied = options.activate; } options = _.omit(options, ['domain', 'email', 'token', '_', 'activate', 'a']); return options; }
javascript
function mapRecordOptions(options) { if (options.type === 'SRV') { let contentParts = options.content.split(' '); let serverParts = options.name.split('.'); options.data = { service: serverParts[0], proto: serverParts[1], name: _.slice(serverParts, 2).join('.'), priority: parseInt(contentParts[0]), weight: parseInt(contentParts[1]), port: parseInt(contentParts[2]), target: contentParts[3] } } if (options.activate !== undefined) { options.proxied = options.activate; } options = _.omit(options, ['domain', 'email', 'token', '_', 'activate', 'a']); return options; }
[ "function", "mapRecordOptions", "(", "options", ")", "{", "if", "(", "options", ".", "type", "===", "'SRV'", ")", "{", "let", "contentParts", "=", "options", ".", "content", ".", "split", "(", "' '", ")", ";", "let", "serverParts", "=", "options", ".", "name", ".", "split", "(", "'.'", ")", ";", "options", ".", "data", "=", "{", "service", ":", "serverParts", "[", "0", "]", ",", "proto", ":", "serverParts", "[", "1", "]", ",", "name", ":", "_", ".", "slice", "(", "serverParts", ",", "2", ")", ".", "join", "(", "'.'", ")", ",", "priority", ":", "parseInt", "(", "contentParts", "[", "0", "]", ")", ",", "weight", ":", "parseInt", "(", "contentParts", "[", "1", "]", ")", ",", "port", ":", "parseInt", "(", "contentParts", "[", "2", "]", ")", ",", "target", ":", "contentParts", "[", "3", "]", "}", "}", "if", "(", "options", ".", "activate", "!==", "undefined", ")", "{", "options", ".", "proxied", "=", "options", ".", "activate", ";", "}", "options", "=", "_", ".", "omit", "(", "options", ",", "[", "'domain'", ",", "'email'", ",", "'token'", ",", "'_'", ",", "'activate'", ",", "'a'", "]", ")", ";", "return", "options", ";", "}" ]
Map options to parameters when adding or editing records @param options @return {*}
[ "Map", "options", "to", "parameters", "when", "adding", "or", "editing", "records" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/index.js#L512-L532
18,964
danielpigott/cloudflare-cli
index.js
validateConfig
function validateConfig(config) { let missing = []; _.each(requiredOptions, function (option) { if (config[option] === undefined) { missing.push(option); } }); if (missing.length > 0) { throw new Error('The following required parameters were not provided: ' + missing.join(',')); } }
javascript
function validateConfig(config) { let missing = []; _.each(requiredOptions, function (option) { if (config[option] === undefined) { missing.push(option); } }); if (missing.length > 0) { throw new Error('The following required parameters were not provided: ' + missing.join(',')); } }
[ "function", "validateConfig", "(", "config", ")", "{", "let", "missing", "=", "[", "]", ";", "_", ".", "each", "(", "requiredOptions", ",", "function", "(", "option", ")", "{", "if", "(", "config", "[", "option", "]", "===", "undefined", ")", "{", "missing", ".", "push", "(", "option", ")", ";", "}", "}", ")", ";", "if", "(", "missing", ".", "length", ">", "0", ")", "{", "throw", "new", "Error", "(", "'The following required parameters were not provided: '", "+", "missing", ".", "join", "(", "','", ")", ")", ";", "}", "}" ]
Check that required config is set @param config
[ "Check", "that", "required", "config", "is", "set" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/index.js#L547-L557
18,965
danielpigott/cloudflare-cli
lib/configReader.js
ConfigReader
function ConfigReader(path) { const self = this; const fs = require('fs'); const util = require('util'); const yaml = require('js-yaml'); const _ = require('lodash'); const allowedEnvironmentVars = { token: 'CF_API_KEY', email: 'CF_API_EMAIL', domain: 'CF_API_DOMAIN' }; const homePath = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME']; path = path ? path.replace('~', homePath) : false; self.readConfig = readConfig; function readConfig(account) { let config = {}; //Load allowed environment variables const envConfig = _.fromPairs( _.filter(_.map(allowedEnvironmentVars, function (envVar, key) { if (process.env[envVar]) { return [key, process.env[envVar]]; } else { return false; } } ), function (value) { return value !== false; }) ); if (path && fs.existsSync(path)) { try { const ymlConfig = yaml.safeLoad(fs.readFileSync(path, 'utf8')); if (ymlConfig !== undefined) { if (ymlConfig.defaults.account || account) { account = (account) ? account : ymlConfig.defaults.account; if (ymlConfig.accounts[account] !== undefined) { config = ymlConfig.accounts[account]; } else { console.log(util.format('Unable to find account %s', account)); console.log('Available accounts: '); _.each(ymlConfig.accounts, function (acc, name) { console.log(util.format(' - %s', name)); }); return false; } } else { config = ymlConfig.defaults; } } else { throw new Error(util.format('Unable to parse file: %s', path)); } } catch (error) { throw new Error(util.format('Invalid config file: %s message: ', path, error.message)); } } return _.extend(config, envConfig); } }
javascript
function ConfigReader(path) { const self = this; const fs = require('fs'); const util = require('util'); const yaml = require('js-yaml'); const _ = require('lodash'); const allowedEnvironmentVars = { token: 'CF_API_KEY', email: 'CF_API_EMAIL', domain: 'CF_API_DOMAIN' }; const homePath = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME']; path = path ? path.replace('~', homePath) : false; self.readConfig = readConfig; function readConfig(account) { let config = {}; //Load allowed environment variables const envConfig = _.fromPairs( _.filter(_.map(allowedEnvironmentVars, function (envVar, key) { if (process.env[envVar]) { return [key, process.env[envVar]]; } else { return false; } } ), function (value) { return value !== false; }) ); if (path && fs.existsSync(path)) { try { const ymlConfig = yaml.safeLoad(fs.readFileSync(path, 'utf8')); if (ymlConfig !== undefined) { if (ymlConfig.defaults.account || account) { account = (account) ? account : ymlConfig.defaults.account; if (ymlConfig.accounts[account] !== undefined) { config = ymlConfig.accounts[account]; } else { console.log(util.format('Unable to find account %s', account)); console.log('Available accounts: '); _.each(ymlConfig.accounts, function (acc, name) { console.log(util.format(' - %s', name)); }); return false; } } else { config = ymlConfig.defaults; } } else { throw new Error(util.format('Unable to parse file: %s', path)); } } catch (error) { throw new Error(util.format('Invalid config file: %s message: ', path, error.message)); } } return _.extend(config, envConfig); } }
[ "function", "ConfigReader", "(", "path", ")", "{", "const", "self", "=", "this", ";", "const", "fs", "=", "require", "(", "'fs'", ")", ";", "const", "util", "=", "require", "(", "'util'", ")", ";", "const", "yaml", "=", "require", "(", "'js-yaml'", ")", ";", "const", "_", "=", "require", "(", "'lodash'", ")", ";", "const", "allowedEnvironmentVars", "=", "{", "token", ":", "'CF_API_KEY'", ",", "email", ":", "'CF_API_EMAIL'", ",", "domain", ":", "'CF_API_DOMAIN'", "}", ";", "const", "homePath", "=", "process", ".", "env", "[", "(", "process", ".", "platform", "===", "'win32'", ")", "?", "'USERPROFILE'", ":", "'HOME'", "]", ";", "path", "=", "path", "?", "path", ".", "replace", "(", "'~'", ",", "homePath", ")", ":", "false", ";", "self", ".", "readConfig", "=", "readConfig", ";", "function", "readConfig", "(", "account", ")", "{", "let", "config", "=", "{", "}", ";", "//Load allowed environment variables", "const", "envConfig", "=", "_", ".", "fromPairs", "(", "_", ".", "filter", "(", "_", ".", "map", "(", "allowedEnvironmentVars", ",", "function", "(", "envVar", ",", "key", ")", "{", "if", "(", "process", ".", "env", "[", "envVar", "]", ")", "{", "return", "[", "key", ",", "process", ".", "env", "[", "envVar", "]", "]", ";", "}", "else", "{", "return", "false", ";", "}", "}", ")", ",", "function", "(", "value", ")", "{", "return", "value", "!==", "false", ";", "}", ")", ")", ";", "if", "(", "path", "&&", "fs", ".", "existsSync", "(", "path", ")", ")", "{", "try", "{", "const", "ymlConfig", "=", "yaml", ".", "safeLoad", "(", "fs", ".", "readFileSync", "(", "path", ",", "'utf8'", ")", ")", ";", "if", "(", "ymlConfig", "!==", "undefined", ")", "{", "if", "(", "ymlConfig", ".", "defaults", ".", "account", "||", "account", ")", "{", "account", "=", "(", "account", ")", "?", "account", ":", "ymlConfig", ".", "defaults", ".", "account", ";", "if", "(", "ymlConfig", ".", "accounts", "[", "account", "]", "!==", "undefined", ")", "{", "config", "=", "ymlConfig", ".", "accounts", "[", "account", "]", ";", "}", "else", "{", "console", ".", "log", "(", "util", ".", "format", "(", "'Unable to find account %s'", ",", "account", ")", ")", ";", "console", ".", "log", "(", "'Available accounts: '", ")", ";", "_", ".", "each", "(", "ymlConfig", ".", "accounts", ",", "function", "(", "acc", ",", "name", ")", "{", "console", ".", "log", "(", "util", ".", "format", "(", "' - %s'", ",", "name", ")", ")", ";", "}", ")", ";", "return", "false", ";", "}", "}", "else", "{", "config", "=", "ymlConfig", ".", "defaults", ";", "}", "}", "else", "{", "throw", "new", "Error", "(", "util", ".", "format", "(", "'Unable to parse file: %s'", ",", "path", ")", ")", ";", "}", "}", "catch", "(", "error", ")", "{", "throw", "new", "Error", "(", "util", ".", "format", "(", "'Invalid config file: %s message: '", ",", "path", ",", "error", ".", "message", ")", ")", ";", "}", "}", "return", "_", ".", "extend", "(", "config", ",", "envConfig", ")", ";", "}", "}" ]
Read config at given path @param path @constructor
[ "Read", "config", "at", "given", "path" ]
1cfbb99041f123aae278550bdcc6b44642103c0d
https://github.com/danielpigott/cloudflare-cli/blob/1cfbb99041f123aae278550bdcc6b44642103c0d/lib/configReader.js#L6-L67
18,966
koopjs/winnow
src/options/normalizeOptions.js
normalizeLimit
function normalizeLimit (options) { const limit = options.limit || options.resultRecordCount || options.count || options.maxFeatures // If there is a limit, add 1 to it so we can later calculate a limitExceeded. The result set will be resized accordingly, post SQL if (limit) return limit + 1 }
javascript
function normalizeLimit (options) { const limit = options.limit || options.resultRecordCount || options.count || options.maxFeatures // If there is a limit, add 1 to it so we can later calculate a limitExceeded. The result set will be resized accordingly, post SQL if (limit) return limit + 1 }
[ "function", "normalizeLimit", "(", "options", ")", "{", "const", "limit", "=", "options", ".", "limit", "||", "options", ".", "resultRecordCount", "||", "options", ".", "count", "||", "options", ".", "maxFeatures", "// If there is a limit, add 1 to it so we can later calculate a limitExceeded. The result set will be resized accordingly, post SQL", "if", "(", "limit", ")", "return", "limit", "+", "1", "}" ]
Normalize the limit option; defaults to undefined @param {object} options @returns {integer} or undefined
[ "Normalize", "the", "limit", "option", ";", "defaults", "to", "undefined" ]
90293fe930ad34ef4eeb6df73a8426d887b4ec69
https://github.com/koopjs/winnow/blob/90293fe930ad34ef4eeb6df73a8426d887b4ec69/src/options/normalizeOptions.js#L171-L175
18,967
koopjs/winnow
src/options/normalizeOptions.js
normalizeIdField
function normalizeIdField (options, features = []) { const collection = options.collection || {} const metadata = collection.metadata || {} const feature = features[0] || {} const featureProperties = feature.properties || feature.attributes || {} let idField = null // First, check metadata for idField if (metadata.idField) idField = metadata.idField // Check metadata.fields for and OBJECTID property else if (_.find(metadata.fields, { name: 'OBJECTID' })) idField = 'OBJECTID' // Check features for an OBJECTID property that is not null else if (features.length > 0 && !_.isUndefined(featureProperties.OBJECTID) && !_.isNull(featureProperties.OBJECTID)) idField = 'OBJECTID' // If there are features, check that the idField is one of the properties if (process.env.NODE_ENV !== 'production' && process.env.KOOP_WARNINGS !== 'suppress' && idField && features.length > 0 && !featureProperties[idField]) { console.warn(`WARNING: requested provider has "idField" assignment, but this property is not found in properties of all features.`) } return idField }
javascript
function normalizeIdField (options, features = []) { const collection = options.collection || {} const metadata = collection.metadata || {} const feature = features[0] || {} const featureProperties = feature.properties || feature.attributes || {} let idField = null // First, check metadata for idField if (metadata.idField) idField = metadata.idField // Check metadata.fields for and OBJECTID property else if (_.find(metadata.fields, { name: 'OBJECTID' })) idField = 'OBJECTID' // Check features for an OBJECTID property that is not null else if (features.length > 0 && !_.isUndefined(featureProperties.OBJECTID) && !_.isNull(featureProperties.OBJECTID)) idField = 'OBJECTID' // If there are features, check that the idField is one of the properties if (process.env.NODE_ENV !== 'production' && process.env.KOOP_WARNINGS !== 'suppress' && idField && features.length > 0 && !featureProperties[idField]) { console.warn(`WARNING: requested provider has "idField" assignment, but this property is not found in properties of all features.`) } return idField }
[ "function", "normalizeIdField", "(", "options", ",", "features", "=", "[", "]", ")", "{", "const", "collection", "=", "options", ".", "collection", "||", "{", "}", "const", "metadata", "=", "collection", ".", "metadata", "||", "{", "}", "const", "feature", "=", "features", "[", "0", "]", "||", "{", "}", "const", "featureProperties", "=", "feature", ".", "properties", "||", "feature", ".", "attributes", "||", "{", "}", "let", "idField", "=", "null", "// First, check metadata for idField", "if", "(", "metadata", ".", "idField", ")", "idField", "=", "metadata", ".", "idField", "// Check metadata.fields for and OBJECTID property", "else", "if", "(", "_", ".", "find", "(", "metadata", ".", "fields", ",", "{", "name", ":", "'OBJECTID'", "}", ")", ")", "idField", "=", "'OBJECTID'", "// Check features for an OBJECTID property that is not null", "else", "if", "(", "features", ".", "length", ">", "0", "&&", "!", "_", ".", "isUndefined", "(", "featureProperties", ".", "OBJECTID", ")", "&&", "!", "_", ".", "isNull", "(", "featureProperties", ".", "OBJECTID", ")", ")", "idField", "=", "'OBJECTID'", "// If there are features, check that the idField is one of the properties", "if", "(", "process", ".", "env", ".", "NODE_ENV", "!==", "'production'", "&&", "process", ".", "env", ".", "KOOP_WARNINGS", "!==", "'suppress'", "&&", "idField", "&&", "features", ".", "length", ">", "0", "&&", "!", "featureProperties", "[", "idField", "]", ")", "{", "console", ".", "warn", "(", "`", "`", ")", "}", "return", "idField", "}" ]
Ensure idField is set if metadata doesn't have a value but a field named OBJECTID is present @param {object} metadata
[ "Ensure", "idField", "is", "set", "if", "metadata", "doesn", "t", "have", "a", "value", "but", "a", "field", "named", "OBJECTID", "is", "present" ]
90293fe930ad34ef4eeb6df73a8426d887b4ec69
https://github.com/koopjs/winnow/blob/90293fe930ad34ef4eeb6df73a8426d887b4ec69/src/options/normalizeOptions.js#L208-L229
18,968
koopjs/winnow
src/select/fields.js
createClause
function createClause (options = {}, idField = null) { // Default clause let clause = `type, properties as properties` // Comma-delimited list of date-fields is needed for formatting ESRI specific output let dateFields = options.dateFields.join(',') let requiresObjectId = !!options.returnIdsOnly || !(options.fields instanceof Array && !options.fields.includes('OBJECTID')) // If options.fields defined, selected only a subset of teh GeoJSON properties if (options.fields) { // if option.fields is an Array, join with comma; if already a comma delimited list, remove any spaces let fields = (options.fields instanceof Array) ? options.fields.join(',') : options.fields.replace(/,\s+/g, ',') // For ESRI specific output, process w/ "pickAndEsriFy"; for simple GeoJSON output, process with "pick" clause = (options.toEsri) ? `pickAndEsriFy(properties, geometry, "${fields}", "${dateFields}", "${requiresObjectId}", "${options.idField}") as attributes` : `pick(properties, "${fields}") as properties` } else if (options.toEsri) { // For ESRI specific output, process w/ "esriFy" clause = `esriFy(properties, geometry, "${dateFields}", "${requiresObjectId}", "${options.idField}") as attributes` } return clause }
javascript
function createClause (options = {}, idField = null) { // Default clause let clause = `type, properties as properties` // Comma-delimited list of date-fields is needed for formatting ESRI specific output let dateFields = options.dateFields.join(',') let requiresObjectId = !!options.returnIdsOnly || !(options.fields instanceof Array && !options.fields.includes('OBJECTID')) // If options.fields defined, selected only a subset of teh GeoJSON properties if (options.fields) { // if option.fields is an Array, join with comma; if already a comma delimited list, remove any spaces let fields = (options.fields instanceof Array) ? options.fields.join(',') : options.fields.replace(/,\s+/g, ',') // For ESRI specific output, process w/ "pickAndEsriFy"; for simple GeoJSON output, process with "pick" clause = (options.toEsri) ? `pickAndEsriFy(properties, geometry, "${fields}", "${dateFields}", "${requiresObjectId}", "${options.idField}") as attributes` : `pick(properties, "${fields}") as properties` } else if (options.toEsri) { // For ESRI specific output, process w/ "esriFy" clause = `esriFy(properties, geometry, "${dateFields}", "${requiresObjectId}", "${options.idField}") as attributes` } return clause }
[ "function", "createClause", "(", "options", "=", "{", "}", ",", "idField", "=", "null", ")", "{", "// Default clause", "let", "clause", "=", "`", "`", "// Comma-delimited list of date-fields is needed for formatting ESRI specific output", "let", "dateFields", "=", "options", ".", "dateFields", ".", "join", "(", "','", ")", "let", "requiresObjectId", "=", "!", "!", "options", ".", "returnIdsOnly", "||", "!", "(", "options", ".", "fields", "instanceof", "Array", "&&", "!", "options", ".", "fields", ".", "includes", "(", "'OBJECTID'", ")", ")", "// If options.fields defined, selected only a subset of teh GeoJSON properties", "if", "(", "options", ".", "fields", ")", "{", "// if option.fields is an Array, join with comma; if already a comma delimited list, remove any spaces", "let", "fields", "=", "(", "options", ".", "fields", "instanceof", "Array", ")", "?", "options", ".", "fields", ".", "join", "(", "','", ")", ":", "options", ".", "fields", ".", "replace", "(", "/", ",\\s+", "/", "g", ",", "','", ")", "// For ESRI specific output, process w/ \"pickAndEsriFy\"; for simple GeoJSON output, process with \"pick\"", "clause", "=", "(", "options", ".", "toEsri", ")", "?", "`", "${", "fields", "}", "${", "dateFields", "}", "${", "requiresObjectId", "}", "${", "options", ".", "idField", "}", "`", ":", "`", "${", "fields", "}", "`", "}", "else", "if", "(", "options", ".", "toEsri", ")", "{", "// For ESRI specific output, process w/ \"esriFy\"", "clause", "=", "`", "${", "dateFields", "}", "${", "requiresObjectId", "}", "${", "options", ".", "idField", "}", "`", "}", "return", "clause", "}" ]
Create the SQL fragment used to SELECT GeoJSON attributes @param {object} options @param {string} idField a string that identifies which property can be used as the OBJECTID
[ "Create", "the", "SQL", "fragment", "used", "to", "SELECT", "GeoJSON", "attributes" ]
90293fe930ad34ef4eeb6df73a8426d887b4ec69
https://github.com/koopjs/winnow/blob/90293fe930ad34ef4eeb6df73a8426d887b4ec69/src/select/fields.js#L6-L26
18,969
koopjs/winnow
src/options/normalizeSQL.js
normalizeFields
function normalizeFields (options) { const fields = options.fields || options.outFields const idField = _.get(options, 'collection.metadata.idField') if (options.returnIdsOnly === true && idField) return [idField] else if (options.returnIdsOnly === true) return ['OBJECTID'] if (fields === '*') return undefined if (typeof fields === 'string' || fields instanceof String) return fields.split(',') if (fields instanceof Array) return fields return undefined }
javascript
function normalizeFields (options) { const fields = options.fields || options.outFields const idField = _.get(options, 'collection.metadata.idField') if (options.returnIdsOnly === true && idField) return [idField] else if (options.returnIdsOnly === true) return ['OBJECTID'] if (fields === '*') return undefined if (typeof fields === 'string' || fields instanceof String) return fields.split(',') if (fields instanceof Array) return fields return undefined }
[ "function", "normalizeFields", "(", "options", ")", "{", "const", "fields", "=", "options", ".", "fields", "||", "options", ".", "outFields", "const", "idField", "=", "_", ".", "get", "(", "options", ",", "'collection.metadata.idField'", ")", "if", "(", "options", ".", "returnIdsOnly", "===", "true", "&&", "idField", ")", "return", "[", "idField", "]", "else", "if", "(", "options", ".", "returnIdsOnly", "===", "true", ")", "return", "[", "'OBJECTID'", "]", "if", "(", "fields", "===", "'*'", ")", "return", "undefined", "if", "(", "typeof", "fields", "===", "'string'", "||", "fields", "instanceof", "String", ")", "return", "fields", ".", "split", "(", "','", ")", "if", "(", "fields", "instanceof", "Array", ")", "return", "fields", "return", "undefined", "}" ]
Transform the input of requested response fields @param {Object} options - object that may contain 'fields' or 'outFields' property
[ "Transform", "the", "input", "of", "requested", "response", "fields" ]
90293fe930ad34ef4eeb6df73a8426d887b4ec69
https://github.com/koopjs/winnow/blob/90293fe930ad34ef4eeb6df73a8426d887b4ec69/src/options/normalizeSQL.js#L21-L30
18,970
koopjs/winnow
src/where.js
handleExpr
function handleExpr (node, options) { let expr if (node.type === 'unary_expr') { expr = `${node.operator} ${traverse(node.expr, options)}` } else if (node.operator === '=' && node.left.value === 1 && node.right.value === 1) { // a special case related to arcgis server return '1=1' } else if (node.operator === 'BETWEEN') { expr = traverse(node.left, options) + ' ' + (node.operator) + ' ' + (traverse(node.right.value[0], options)) + 'AND' + (traverse(node.right.value[1], options)) } else { // store the column node for value decoding if (node.left.type === 'column_ref') { node.right.columnNode = node.left } if (node.right.type === 'column_ref') { node.left.columnNode = node.right } expr = `${traverse(node.left, options)} ${node.operator} ${traverse(node.right, options)}` } if (node.parentheses) { expr = `(${expr})` } return expr }
javascript
function handleExpr (node, options) { let expr if (node.type === 'unary_expr') { expr = `${node.operator} ${traverse(node.expr, options)}` } else if (node.operator === '=' && node.left.value === 1 && node.right.value === 1) { // a special case related to arcgis server return '1=1' } else if (node.operator === 'BETWEEN') { expr = traverse(node.left, options) + ' ' + (node.operator) + ' ' + (traverse(node.right.value[0], options)) + 'AND' + (traverse(node.right.value[1], options)) } else { // store the column node for value decoding if (node.left.type === 'column_ref') { node.right.columnNode = node.left } if (node.right.type === 'column_ref') { node.left.columnNode = node.right } expr = `${traverse(node.left, options)} ${node.operator} ${traverse(node.right, options)}` } if (node.parentheses) { expr = `(${expr})` } return expr }
[ "function", "handleExpr", "(", "node", ",", "options", ")", "{", "let", "expr", "if", "(", "node", ".", "type", "===", "'unary_expr'", ")", "{", "expr", "=", "`", "${", "node", ".", "operator", "}", "${", "traverse", "(", "node", ".", "expr", ",", "options", ")", "}", "`", "}", "else", "if", "(", "node", ".", "operator", "===", "'='", "&&", "node", ".", "left", ".", "value", "===", "1", "&&", "node", ".", "right", ".", "value", "===", "1", ")", "{", "// a special case related to arcgis server", "return", "'1=1'", "}", "else", "if", "(", "node", ".", "operator", "===", "'BETWEEN'", ")", "{", "expr", "=", "traverse", "(", "node", ".", "left", ",", "options", ")", "+", "' '", "+", "(", "node", ".", "operator", ")", "+", "' '", "+", "(", "traverse", "(", "node", ".", "right", ".", "value", "[", "0", "]", ",", "options", ")", ")", "+", "'AND'", "+", "(", "traverse", "(", "node", ".", "right", ".", "value", "[", "1", "]", ",", "options", ")", ")", "}", "else", "{", "// store the column node for value decoding", "if", "(", "node", ".", "left", ".", "type", "===", "'column_ref'", ")", "{", "node", ".", "right", ".", "columnNode", "=", "node", ".", "left", "}", "if", "(", "node", ".", "right", ".", "type", "===", "'column_ref'", ")", "{", "node", ".", "left", ".", "columnNode", "=", "node", ".", "right", "}", "expr", "=", "`", "${", "traverse", "(", "node", ".", "left", ",", "options", ")", "}", "${", "node", ".", "operator", "}", "${", "traverse", "(", "node", ".", "right", ",", "options", ")", "}", "`", "}", "if", "(", "node", ".", "parentheses", ")", "{", "expr", "=", "`", "${", "expr", "}", "`", "}", "return", "expr", "}" ]
Convert an expression node to its string representation. @param {object} node AST expression node @param {object} options winnow options @return {string} expression string
[ "Convert", "an", "expression", "node", "to", "its", "string", "representation", "." ]
90293fe930ad34ef4eeb6df73a8426d887b4ec69
https://github.com/koopjs/winnow/blob/90293fe930ad34ef4eeb6df73a8426d887b4ec69/src/where.js#L11-L40
18,971
koopjs/winnow
src/where.js
handleExprList
function handleExprList (node, options) { const values = node.value.map((valueNode) => traverse(valueNode, options)).join(',') return `(${values})` }
javascript
function handleExprList (node, options) { const values = node.value.map((valueNode) => traverse(valueNode, options)).join(',') return `(${values})` }
[ "function", "handleExprList", "(", "node", ",", "options", ")", "{", "const", "values", "=", "node", ".", "value", ".", "map", "(", "(", "valueNode", ")", "=>", "traverse", "(", "valueNode", ",", "options", ")", ")", ".", "join", "(", "','", ")", "return", "`", "${", "values", "}", "`", "}" ]
Convert an expression list node to its string representation. @param {object} node AST expression list node @param {object} options winnow options @return {string} expression list string
[ "Convert", "an", "expression", "list", "node", "to", "its", "string", "representation", "." ]
90293fe930ad34ef4eeb6df73a8426d887b4ec69
https://github.com/koopjs/winnow/blob/90293fe930ad34ef4eeb6df73a8426d887b4ec69/src/where.js#L48-L51
18,972
koopjs/winnow
src/where.js
handleFunction
function handleFunction (node, options) { const args = handleExprList(node.args, options) return `${node.name}${args}` }
javascript
function handleFunction (node, options) { const args = handleExprList(node.args, options) return `${node.name}${args}` }
[ "function", "handleFunction", "(", "node", ",", "options", ")", "{", "const", "args", "=", "handleExprList", "(", "node", ".", "args", ",", "options", ")", "return", "`", "${", "node", ".", "name", "}", "${", "args", "}", "`", "}" ]
Convert a function node to its string representation. @param {object} node AST function node @param {object} options winnow options @return {string} function string
[ "Convert", "a", "function", "node", "to", "its", "string", "representation", "." ]
90293fe930ad34ef4eeb6df73a8426d887b4ec69
https://github.com/koopjs/winnow/blob/90293fe930ad34ef4eeb6df73a8426d887b4ec69/src/where.js#L59-L62
18,973
koopjs/winnow
src/where.js
handleValue
function handleValue (node, options) { let value = node.value if (node.columnNode) { const field = _.find(options.esriFields, { name: node.columnNode.column }) if (_.has(field, 'domain.codedValues')) { const actual = _.find(field.domain.codedValues, { code: value }) if (actual) { value = actual.name } } } if (typeof value === 'string') { value = `'${value}'` } return value }
javascript
function handleValue (node, options) { let value = node.value if (node.columnNode) { const field = _.find(options.esriFields, { name: node.columnNode.column }) if (_.has(field, 'domain.codedValues')) { const actual = _.find(field.domain.codedValues, { code: value }) if (actual) { value = actual.name } } } if (typeof value === 'string') { value = `'${value}'` } return value }
[ "function", "handleValue", "(", "node", ",", "options", ")", "{", "let", "value", "=", "node", ".", "value", "if", "(", "node", ".", "columnNode", ")", "{", "const", "field", "=", "_", ".", "find", "(", "options", ".", "esriFields", ",", "{", "name", ":", "node", ".", "columnNode", ".", "column", "}", ")", "if", "(", "_", ".", "has", "(", "field", ",", "'domain.codedValues'", ")", ")", "{", "const", "actual", "=", "_", ".", "find", "(", "field", ".", "domain", ".", "codedValues", ",", "{", "code", ":", "value", "}", ")", "if", "(", "actual", ")", "{", "value", "=", "actual", ".", "name", "}", "}", "}", "if", "(", "typeof", "value", "===", "'string'", ")", "{", "value", "=", "`", "${", "value", "}", "`", "}", "return", "value", "}" ]
Convert a value node to its string representation. If the value node has a reference to its column and this column is an encoded field, this function will try to decode the value. @param {object} node AST value node @param {object} options winnow options @return {string} value string
[ "Convert", "a", "value", "node", "to", "its", "string", "representation", "." ]
90293fe930ad34ef4eeb6df73a8426d887b4ec69
https://github.com/koopjs/winnow/blob/90293fe930ad34ef4eeb6df73a8426d887b4ec69/src/where.js#L84-L104
18,974
koopjs/winnow
src/where.js
traverse
function traverse (node, options) { if (!node) { return '' } switch (node.type) { case 'unary_expr': case 'binary_expr': return handleExpr(node, options) case 'function': return handleFunction(node, options) case 'expr_list': return handleExprList(node, options) case 'column_ref': return handleColumn(node, options) case 'string': case 'number': case 'null': case 'bool': return handleValue(node, options) case 'timestamp': return handleTimestampValue(node, options) default: throw new Error('Unrecognized AST node: \n' + JSON.stringify(node, null, 2)) } }
javascript
function traverse (node, options) { if (!node) { return '' } switch (node.type) { case 'unary_expr': case 'binary_expr': return handleExpr(node, options) case 'function': return handleFunction(node, options) case 'expr_list': return handleExprList(node, options) case 'column_ref': return handleColumn(node, options) case 'string': case 'number': case 'null': case 'bool': return handleValue(node, options) case 'timestamp': return handleTimestampValue(node, options) default: throw new Error('Unrecognized AST node: \n' + JSON.stringify(node, null, 2)) } }
[ "function", "traverse", "(", "node", ",", "options", ")", "{", "if", "(", "!", "node", ")", "{", "return", "''", "}", "switch", "(", "node", ".", "type", ")", "{", "case", "'unary_expr'", ":", "case", "'binary_expr'", ":", "return", "handleExpr", "(", "node", ",", "options", ")", "case", "'function'", ":", "return", "handleFunction", "(", "node", ",", "options", ")", "case", "'expr_list'", ":", "return", "handleExprList", "(", "node", ",", "options", ")", "case", "'column_ref'", ":", "return", "handleColumn", "(", "node", ",", "options", ")", "case", "'string'", ":", "case", "'number'", ":", "case", "'null'", ":", "case", "'bool'", ":", "return", "handleValue", "(", "node", ",", "options", ")", "case", "'timestamp'", ":", "return", "handleTimestampValue", "(", "node", ",", "options", ")", "default", ":", "throw", "new", "Error", "(", "'Unrecognized AST node: \\n'", "+", "JSON", ".", "stringify", "(", "node", ",", "null", ",", "2", ")", ")", "}", "}" ]
Traverse a SQL AST and return its string representation @param {object} node AST node @param {object} options winnow options @return {string} AST string
[ "Traverse", "a", "SQL", "AST", "and", "return", "its", "string", "representation" ]
90293fe930ad34ef4eeb6df73a8426d887b4ec69
https://github.com/koopjs/winnow/blob/90293fe930ad34ef4eeb6df73a8426d887b4ec69/src/where.js#L123-L148
18,975
koopjs/winnow
src/sql.js
esriFy
function esriFy (properties, geometry, dateFields, requiresObjectId, idField) { const parsedDateFields = (dateFields.length === 0) ? [] : dateFields.split(',') if (parsedDateFields.length) { parsedDateFields.forEach(field => { properties[field] = new Date(properties[field]).getTime() }) } // If the object ID is not needed, return here if (requiresObjectId === 'false') return properties // Coerce idField idField = (idField === 'null') ? null : idField // If the idField for the model set use its value as OBJECTID if (idField) { if (process.env.NODE_ENV !== 'production' && process.env.KOOP_WARNINGS !== 'suppress' && (!Number.isInteger(properties[idField]) || properties[idField] > 2147483647)) { console.warn(`WARNING: OBJECTIDs created from provider's "idField" are not integers from 0 to 2147483647`) } } else { // Create an OBJECTID by creating a numeric hash from the stringified feature // Note possibility of OBJECTID collisions with this method still exists, but should be small properties.OBJECTID = createIntHash(JSON.stringify({ properties, geometry })) } return properties }
javascript
function esriFy (properties, geometry, dateFields, requiresObjectId, idField) { const parsedDateFields = (dateFields.length === 0) ? [] : dateFields.split(',') if (parsedDateFields.length) { parsedDateFields.forEach(field => { properties[field] = new Date(properties[field]).getTime() }) } // If the object ID is not needed, return here if (requiresObjectId === 'false') return properties // Coerce idField idField = (idField === 'null') ? null : idField // If the idField for the model set use its value as OBJECTID if (idField) { if (process.env.NODE_ENV !== 'production' && process.env.KOOP_WARNINGS !== 'suppress' && (!Number.isInteger(properties[idField]) || properties[idField] > 2147483647)) { console.warn(`WARNING: OBJECTIDs created from provider's "idField" are not integers from 0 to 2147483647`) } } else { // Create an OBJECTID by creating a numeric hash from the stringified feature // Note possibility of OBJECTID collisions with this method still exists, but should be small properties.OBJECTID = createIntHash(JSON.stringify({ properties, geometry })) } return properties }
[ "function", "esriFy", "(", "properties", ",", "geometry", ",", "dateFields", ",", "requiresObjectId", ",", "idField", ")", "{", "const", "parsedDateFields", "=", "(", "dateFields", ".", "length", "===", "0", ")", "?", "[", "]", ":", "dateFields", ".", "split", "(", "','", ")", "if", "(", "parsedDateFields", ".", "length", ")", "{", "parsedDateFields", ".", "forEach", "(", "field", "=>", "{", "properties", "[", "field", "]", "=", "new", "Date", "(", "properties", "[", "field", "]", ")", ".", "getTime", "(", ")", "}", ")", "}", "// If the object ID is not needed, return here", "if", "(", "requiresObjectId", "===", "'false'", ")", "return", "properties", "// Coerce idField", "idField", "=", "(", "idField", "===", "'null'", ")", "?", "null", ":", "idField", "// If the idField for the model set use its value as OBJECTID", "if", "(", "idField", ")", "{", "if", "(", "process", ".", "env", ".", "NODE_ENV", "!==", "'production'", "&&", "process", ".", "env", ".", "KOOP_WARNINGS", "!==", "'suppress'", "&&", "(", "!", "Number", ".", "isInteger", "(", "properties", "[", "idField", "]", ")", "||", "properties", "[", "idField", "]", ">", "2147483647", ")", ")", "{", "console", ".", "warn", "(", "`", "`", ")", "}", "}", "else", "{", "// Create an OBJECTID by creating a numeric hash from the stringified feature", "// Note possibility of OBJECTID collisions with this method still exists, but should be small", "properties", ".", "OBJECTID", "=", "createIntHash", "(", "JSON", ".", "stringify", "(", "{", "properties", ",", "geometry", "}", ")", ")", "}", "return", "properties", "}" ]
Modify propterties to fit ESRI specs @param {object} properties GeoJSON properties @param {object} geometry GeoJSON geometry @param {string} dateFields comma-delimited list of date fields @param {string} requiresObjectId boolean-string flagging requirement of OBJECTID as part of properties @param {string} idField name of attribute to be used as OBJECTID
[ "Modify", "propterties", "to", "fit", "ESRI", "specs" ]
90293fe930ad34ef4eeb6df73a8426d887b4ec69
https://github.com/koopjs/winnow/blob/90293fe930ad34ef4eeb6df73a8426d887b4ec69/src/sql.js#L127-L152
18,976
mckamey/countdownjs
lib/qunit/qunit.js
function(a, msg) { a = !!a; var details = { result: a, message: msg }; msg = escapeInnerText(msg); runLoggingCallbacks( 'log', QUnit, details ); config.current.assertions.push({ result: a, message: msg }); }
javascript
function(a, msg) { a = !!a; var details = { result: a, message: msg }; msg = escapeInnerText(msg); runLoggingCallbacks( 'log', QUnit, details ); config.current.assertions.push({ result: a, message: msg }); }
[ "function", "(", "a", ",", "msg", ")", "{", "a", "=", "!", "!", "a", ";", "var", "details", "=", "{", "result", ":", "a", ",", "message", ":", "msg", "}", ";", "msg", "=", "escapeInnerText", "(", "msg", ")", ";", "runLoggingCallbacks", "(", "'log'", ",", "QUnit", ",", "details", ")", ";", "config", ".", "current", ".", "assertions", ".", "push", "(", "{", "result", ":", "a", ",", "message", ":", "msg", "}", ")", ";", "}" ]
Asserts true. @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
[ "Asserts", "true", "." ]
cb5b1877ca474d3c86e0407c090a7af90fbded41
https://github.com/mckamey/countdownjs/blob/cb5b1877ca474d3c86e0407c090a7af90fbded41/lib/qunit/qunit.js#L309-L321
18,977
mckamey/countdownjs
lib/qunit/qunit.js
function(actual, expected, message) { QUnit.push(expected == actual, actual, expected, message); }
javascript
function(actual, expected, message) { QUnit.push(expected == actual, actual, expected, message); }
[ "function", "(", "actual", ",", "expected", ",", "message", ")", "{", "QUnit", ".", "push", "(", "expected", "==", "actual", ",", "actual", ",", "expected", ",", "message", ")", ";", "}" ]
Checks that the first two arguments are equal, with an optional message. Prints out both actual and expected values. Prefered to ok( actual == expected, message ) @example equal( format("Received {0} bytes.", 2), "Received 2 bytes." ); @param Object actual @param Object expected @param String message (optional)
[ "Checks", "that", "the", "first", "two", "arguments", "are", "equal", "with", "an", "optional", "message", ".", "Prints", "out", "both", "actual", "and", "expected", "values", "." ]
cb5b1877ca474d3c86e0407c090a7af90fbded41
https://github.com/mckamey/countdownjs/blob/cb5b1877ca474d3c86e0407c090a7af90fbded41/lib/qunit/qunit.js#L335-L337
18,978
mckamey/countdownjs
lib/qunit/qunit.js
function() { extend(config, { stats: { all: 0, bad: 0 }, moduleStats: { all: 0, bad: 0 }, started: +new Date, updateRate: 1000, blocking: false, autostart: true, autorun: false, filter: "", queue: [], semaphore: 0 }); var tests = id( "qunit-tests" ), banner = id( "qunit-banner" ), result = id( "qunit-testresult" ); if ( tests ) { tests.innerHTML = ""; } if ( banner ) { banner.className = ""; } if ( result ) { result.parentNode.removeChild( result ); } if ( tests ) { result = document.createElement( "p" ); result.id = "qunit-testresult"; result.className = "result"; tests.parentNode.insertBefore( result, tests ); result.innerHTML = 'Running...<br/>&nbsp;'; } }
javascript
function() { extend(config, { stats: { all: 0, bad: 0 }, moduleStats: { all: 0, bad: 0 }, started: +new Date, updateRate: 1000, blocking: false, autostart: true, autorun: false, filter: "", queue: [], semaphore: 0 }); var tests = id( "qunit-tests" ), banner = id( "qunit-banner" ), result = id( "qunit-testresult" ); if ( tests ) { tests.innerHTML = ""; } if ( banner ) { banner.className = ""; } if ( result ) { result.parentNode.removeChild( result ); } if ( tests ) { result = document.createElement( "p" ); result.id = "qunit-testresult"; result.className = "result"; tests.parentNode.insertBefore( result, tests ); result.innerHTML = 'Running...<br/>&nbsp;'; } }
[ "function", "(", ")", "{", "extend", "(", "config", ",", "{", "stats", ":", "{", "all", ":", "0", ",", "bad", ":", "0", "}", ",", "moduleStats", ":", "{", "all", ":", "0", ",", "bad", ":", "0", "}", ",", "started", ":", "+", "new", "Date", ",", "updateRate", ":", "1000", ",", "blocking", ":", "false", ",", "autostart", ":", "true", ",", "autorun", ":", "false", ",", "filter", ":", "\"\"", ",", "queue", ":", "[", "]", ",", "semaphore", ":", "0", "}", ")", ";", "var", "tests", "=", "id", "(", "\"qunit-tests\"", ")", ",", "banner", "=", "id", "(", "\"qunit-banner\"", ")", ",", "result", "=", "id", "(", "\"qunit-testresult\"", ")", ";", "if", "(", "tests", ")", "{", "tests", ".", "innerHTML", "=", "\"\"", ";", "}", "if", "(", "banner", ")", "{", "banner", ".", "className", "=", "\"\"", ";", "}", "if", "(", "result", ")", "{", "result", ".", "parentNode", ".", "removeChild", "(", "result", ")", ";", "}", "if", "(", "tests", ")", "{", "result", "=", "document", ".", "createElement", "(", "\"p\"", ")", ";", "result", ".", "id", "=", "\"qunit-testresult\"", ";", "result", ".", "className", "=", "\"result\"", ";", "tests", ".", "parentNode", ".", "insertBefore", "(", "result", ",", "tests", ")", ";", "result", ".", "innerHTML", "=", "'Running...<br/>&nbsp;'", ";", "}", "}" ]
Initialize the configuration options
[ "Initialize", "the", "configuration", "options" ]
cb5b1877ca474d3c86e0407c090a7af90fbded41
https://github.com/mckamey/countdownjs/blob/cb5b1877ca474d3c86e0407c090a7af90fbded41/lib/qunit/qunit.js#L519-L556
18,979
mckamey/countdownjs
lib/qunit/qunit.js
function() { if ( window.jQuery ) { jQuery( "#qunit-fixture" ).html( config.fixture ); } else { var main = id( 'qunit-fixture' ); if ( main ) { main.innerHTML = config.fixture; } } }
javascript
function() { if ( window.jQuery ) { jQuery( "#qunit-fixture" ).html( config.fixture ); } else { var main = id( 'qunit-fixture' ); if ( main ) { main.innerHTML = config.fixture; } } }
[ "function", "(", ")", "{", "if", "(", "window", ".", "jQuery", ")", "{", "jQuery", "(", "\"#qunit-fixture\"", ")", ".", "html", "(", "config", ".", "fixture", ")", ";", "}", "else", "{", "var", "main", "=", "id", "(", "'qunit-fixture'", ")", ";", "if", "(", "main", ")", "{", "main", ".", "innerHTML", "=", "config", ".", "fixture", ";", "}", "}", "}" ]
Resets the test setup. Useful for tests that modify the DOM. If jQuery is available, uses jQuery's html(), otherwise just innerHTML.
[ "Resets", "the", "test", "setup", ".", "Useful", "for", "tests", "that", "modify", "the", "DOM", "." ]
cb5b1877ca474d3c86e0407c090a7af90fbded41
https://github.com/mckamey/countdownjs/blob/cb5b1877ca474d3c86e0407c090a7af90fbded41/lib/qunit/qunit.js#L563-L572
18,980
mckamey/countdownjs
lib/qunit/qunit.js
function( elem, type, event ) { if ( document.createEvent ) { event = document.createEvent("MouseEvents"); event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null); elem.dispatchEvent( event ); } else if ( elem.fireEvent ) { elem.fireEvent("on"+type); } }
javascript
function( elem, type, event ) { if ( document.createEvent ) { event = document.createEvent("MouseEvents"); event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null); elem.dispatchEvent( event ); } else if ( elem.fireEvent ) { elem.fireEvent("on"+type); } }
[ "function", "(", "elem", ",", "type", ",", "event", ")", "{", "if", "(", "document", ".", "createEvent", ")", "{", "event", "=", "document", ".", "createEvent", "(", "\"MouseEvents\"", ")", ";", "event", ".", "initMouseEvent", "(", "type", ",", "true", ",", "true", ",", "elem", ".", "ownerDocument", ".", "defaultView", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "false", ",", "false", ",", "false", ",", "false", ",", "0", ",", "null", ")", ";", "elem", ".", "dispatchEvent", "(", "event", ")", ";", "}", "else", "if", "(", "elem", ".", "fireEvent", ")", "{", "elem", ".", "fireEvent", "(", "\"on\"", "+", "type", ")", ";", "}", "}" ]
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
[ "Trigger", "an", "event", "on", "an", "element", "." ]
cb5b1877ca474d3c86e0407c090a7af90fbded41
https://github.com/mckamey/countdownjs/blob/cb5b1877ca474d3c86e0407c090a7af90fbded41/lib/qunit/qunit.js#L582-L592
18,981
mckamey/countdownjs
lib/qunit/qunit.js
diff
function diff( a, b ) { var result = a.slice(); for ( var i = 0; i < result.length; i++ ) { for ( var j = 0; j < b.length; j++ ) { if ( result[i] === b[j] ) { result.splice(i, 1); i--; break; } } } return result; }
javascript
function diff( a, b ) { var result = a.slice(); for ( var i = 0; i < result.length; i++ ) { for ( var j = 0; j < b.length; j++ ) { if ( result[i] === b[j] ) { result.splice(i, 1); i--; break; } } } return result; }
[ "function", "diff", "(", "a", ",", "b", ")", "{", "var", "result", "=", "a", ".", "slice", "(", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "result", ".", "length", ";", "i", "++", ")", "{", "for", "(", "var", "j", "=", "0", ";", "j", "<", "b", ".", "length", ";", "j", "++", ")", "{", "if", "(", "result", "[", "i", "]", "===", "b", "[", "j", "]", ")", "{", "result", ".", "splice", "(", "i", ",", "1", ")", ";", "i", "--", ";", "break", ";", "}", "}", "}", "return", "result", ";", "}" ]
returns a new Array with the elements that are in a but not in b
[ "returns", "a", "new", "Array", "with", "the", "elements", "that", "are", "in", "a", "but", "not", "in", "b" ]
cb5b1877ca474d3c86e0407c090a7af90fbded41
https://github.com/mckamey/countdownjs/blob/cb5b1877ca474d3c86e0407c090a7af90fbded41/lib/qunit/qunit.js#L948-L960
18,982
mckamey/countdownjs
lib/qunit/qunit.js
runLoggingCallbacks
function runLoggingCallbacks(key, scope, args) { //debugger; var callbacks; if ( QUnit.hasOwnProperty(key) ) { QUnit[key].call(scope, args); } else { callbacks = config[key]; for( var i = 0; i < callbacks.length; i++ ) { callbacks[i].call( scope, args ); } } }
javascript
function runLoggingCallbacks(key, scope, args) { //debugger; var callbacks; if ( QUnit.hasOwnProperty(key) ) { QUnit[key].call(scope, args); } else { callbacks = config[key]; for( var i = 0; i < callbacks.length; i++ ) { callbacks[i].call( scope, args ); } } }
[ "function", "runLoggingCallbacks", "(", "key", ",", "scope", ",", "args", ")", "{", "//debugger;", "var", "callbacks", ";", "if", "(", "QUnit", ".", "hasOwnProperty", "(", "key", ")", ")", "{", "QUnit", "[", "key", "]", ".", "call", "(", "scope", ",", "args", ")", ";", "}", "else", "{", "callbacks", "=", "config", "[", "key", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "callbacks", ".", "length", ";", "i", "++", ")", "{", "callbacks", "[", "i", "]", ".", "call", "(", "scope", ",", "args", ")", ";", "}", "}", "}" ]
Supports deprecated method of completely overwriting logging callbacks
[ "Supports", "deprecated", "method", "of", "completely", "overwriting", "logging", "callbacks" ]
cb5b1877ca474d3c86e0407c090a7af90fbded41
https://github.com/mckamey/countdownjs/blob/cb5b1877ca474d3c86e0407c090a7af90fbded41/lib/qunit/qunit.js#L1007-L1018
18,983
mckamey/countdownjs
lib/qunit/qunit.js
useStrictEquality
function useStrictEquality(b, a) { if (b instanceof a.constructor || a instanceof b.constructor) { // to catch short annotaion VS 'new' annotation of a // declaration // e.g. var i = 1; // var j = new Number(1); return a == b; } else { return a === b; } }
javascript
function useStrictEquality(b, a) { if (b instanceof a.constructor || a instanceof b.constructor) { // to catch short annotaion VS 'new' annotation of a // declaration // e.g. var i = 1; // var j = new Number(1); return a == b; } else { return a === b; } }
[ "function", "useStrictEquality", "(", "b", ",", "a", ")", "{", "if", "(", "b", "instanceof", "a", ".", "constructor", "||", "a", "instanceof", "b", ".", "constructor", ")", "{", "// to catch short annotaion VS 'new' annotation of a", "// declaration", "// e.g. var i = 1;", "// var j = new Number(1);", "return", "a", "==", "b", ";", "}", "else", "{", "return", "a", "===", "b", ";", "}", "}" ]
for string, boolean, number and null
[ "for", "string", "boolean", "number", "and", "null" ]
cb5b1877ca474d3c86e0407c090a7af90fbded41
https://github.com/mckamey/countdownjs/blob/cb5b1877ca474d3c86e0407c090a7af90fbded41/lib/qunit/qunit.js#L1043-L1053
18,984
jackbearheart/email-addresses
lib/email-addresses.js
o
function o(name, value) { return { name: name, tokens: value || "", semantic: value || "", children: [] }; }
javascript
function o(name, value) { return { name: name, tokens: value || "", semantic: value || "", children: [] }; }
[ "function", "o", "(", "name", ",", "value", ")", "{", "return", "{", "name", ":", "name", ",", "tokens", ":", "value", "||", "\"\"", ",", "semantic", ":", "value", "||", "\"\"", ",", "children", ":", "[", "]", "}", ";", "}" ]
parser helper functions
[ "parser", "helper", "functions" ]
30a1e654f8d2227322d54683dbf418c4b956fec9
https://github.com/jackbearheart/email-addresses/blob/30a1e654f8d2227322d54683dbf418c4b956fec9/lib/email-addresses.js#L47-L54
18,985
jackbearheart/email-addresses
lib/email-addresses.js
displayName
function displayName() { return wrap('display-name', function phraseFixedSemantic() { var result = phrase(); if (result !== null) { result.semantic = collapseWhitespace(result.semantic); } return result; }()); }
javascript
function displayName() { return wrap('display-name', function phraseFixedSemantic() { var result = phrase(); if (result !== null) { result.semantic = collapseWhitespace(result.semantic); } return result; }()); }
[ "function", "displayName", "(", ")", "{", "return", "wrap", "(", "'display-name'", ",", "function", "phraseFixedSemantic", "(", ")", "{", "var", "result", "=", "phrase", "(", ")", ";", "if", "(", "result", "!==", "null", ")", "{", "result", ".", "semantic", "=", "collapseWhitespace", "(", "result", ".", "semantic", ")", ";", "}", "return", "result", ";", "}", "(", ")", ")", ";", "}" ]
display-name = phrase
[ "display", "-", "name", "=", "phrase" ]
30a1e654f8d2227322d54683dbf418c4b956fec9
https://github.com/jackbearheart/email-addresses/blob/30a1e654f8d2227322d54683dbf418c4b956fec9/lib/email-addresses.js#L491-L499
18,986
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
searchNodeInTree
function searchNodeInTree(treeRoot, nodeId){ if (treeRoot.childNodes){ for (var i = 0; i < treeRoot.childNodes.length; ++i){ var currentNode = treeRoot.childNodes[i]; if (currentNode._id == nodeId){ return currentNode; } else { var found = searchNodeInTree(currentNode, nodeId); if (found) { return found; } } } } return false; }
javascript
function searchNodeInTree(treeRoot, nodeId){ if (treeRoot.childNodes){ for (var i = 0; i < treeRoot.childNodes.length; ++i){ var currentNode = treeRoot.childNodes[i]; if (currentNode._id == nodeId){ return currentNode; } else { var found = searchNodeInTree(currentNode, nodeId); if (found) { return found; } } } } return false; }
[ "function", "searchNodeInTree", "(", "treeRoot", ",", "nodeId", ")", "{", "if", "(", "treeRoot", ".", "childNodes", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "treeRoot", ".", "childNodes", ".", "length", ";", "++", "i", ")", "{", "var", "currentNode", "=", "treeRoot", ".", "childNodes", "[", "i", "]", ";", "if", "(", "currentNode", ".", "_id", "==", "nodeId", ")", "{", "return", "currentNode", ";", "}", "else", "{", "var", "found", "=", "searchNodeInTree", "(", "currentNode", ",", "nodeId", ")", ";", "if", "(", "found", ")", "{", "return", "found", ";", "}", "}", "}", "}", "return", "false", ";", "}" ]
Depth First Search algorithm that returns the node and its children with the id "nodeId" @param treeRoot @param nodeId @returns {*}
[ "Depth", "First", "Search", "algorithm", "that", "returns", "the", "node", "and", "its", "children", "with", "the", "id", "nodeId" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L209-L224
18,987
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
createTree
function createTree(){ for (var i = 0; i < gRootNodes.length; ++i){ var node = { _id : gRootNodes[i]._id, //todo : id instead of name? node : gRootNodes[i], parent : "root", childNodes : loadChildNodes(gRootNodes[i]) }; gTree.childNodes.push(node); } }
javascript
function createTree(){ for (var i = 0; i < gRootNodes.length; ++i){ var node = { _id : gRootNodes[i]._id, //todo : id instead of name? node : gRootNodes[i], parent : "root", childNodes : loadChildNodes(gRootNodes[i]) }; gTree.childNodes.push(node); } }
[ "function", "createTree", "(", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "gRootNodes", ".", "length", ";", "++", "i", ")", "{", "var", "node", "=", "{", "_id", ":", "gRootNodes", "[", "i", "]", ".", "_id", ",", "//todo : id instead of name?", "node", ":", "gRootNodes", "[", "i", "]", ",", "parent", ":", "\"root\"", ",", "childNodes", ":", "loadChildNodes", "(", "gRootNodes", "[", "i", "]", ")", "}", ";", "gTree", ".", "childNodes", ".", "push", "(", "node", ")", ";", "}", "}" ]
Creates an object containing the nodes of the graph in the form of a tree
[ "Creates", "an", "object", "containing", "the", "nodes", "of", "the", "graph", "in", "the", "form", "of", "a", "tree" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L273-L283
18,988
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
loadChildNodes
function loadChildNodes(parentNode){ if (gNodesWithChildren[parentNode._id]){ var children = []; for (var i = 0; i < gNodesWithChildren[parentNode._id].length; ++i){ var currentNode = gNodesWithChildren[parentNode._id][i]; children.push({ _id : currentNode._id, //todo : id instead of name? node : currentNode, parent : parentNode._id, //todo id instead of name? childNodes : loadChildNodes(currentNode) }); } return children; } }
javascript
function loadChildNodes(parentNode){ if (gNodesWithChildren[parentNode._id]){ var children = []; for (var i = 0; i < gNodesWithChildren[parentNode._id].length; ++i){ var currentNode = gNodesWithChildren[parentNode._id][i]; children.push({ _id : currentNode._id, //todo : id instead of name? node : currentNode, parent : parentNode._id, //todo id instead of name? childNodes : loadChildNodes(currentNode) }); } return children; } }
[ "function", "loadChildNodes", "(", "parentNode", ")", "{", "if", "(", "gNodesWithChildren", "[", "parentNode", ".", "_id", "]", ")", "{", "var", "children", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "gNodesWithChildren", "[", "parentNode", ".", "_id", "]", ".", "length", ";", "++", "i", ")", "{", "var", "currentNode", "=", "gNodesWithChildren", "[", "parentNode", ".", "_id", "]", "[", "i", "]", ";", "children", ".", "push", "(", "{", "_id", ":", "currentNode", ".", "_id", ",", "//todo : id instead of name?", "node", ":", "currentNode", ",", "parent", ":", "parentNode", ".", "_id", ",", "//todo id instead of name?", "childNodes", ":", "loadChildNodes", "(", "currentNode", ")", "}", ")", ";", "}", "return", "children", ";", "}", "}" ]
Returns the nodes children of the node in parameter @param parentNode @returns {Array}
[ "Returns", "the", "nodes", "children", "of", "the", "node", "in", "parameter" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L290-L304
18,989
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
displayNameDOM
function displayNameDOM(node){ $('.nodeLabel').remove(); var nodePos = layout.getNodePosition(node._id); var domPos = { x: nodePos.x, y: nodePos.y }; graphics.transformGraphToClientCoordinates(domPos); var labelStyle = generateDOMLabel(node).style; labelStyle.left = domPos.x; labelStyle.top = domPos.y; }
javascript
function displayNameDOM(node){ $('.nodeLabel').remove(); var nodePos = layout.getNodePosition(node._id); var domPos = { x: nodePos.x, y: nodePos.y }; graphics.transformGraphToClientCoordinates(domPos); var labelStyle = generateDOMLabel(node).style; labelStyle.left = domPos.x; labelStyle.top = domPos.y; }
[ "function", "displayNameDOM", "(", "node", ")", "{", "$", "(", "'.nodeLabel'", ")", ".", "remove", "(", ")", ";", "var", "nodePos", "=", "layout", ".", "getNodePosition", "(", "node", ".", "_id", ")", ";", "var", "domPos", "=", "{", "x", ":", "nodePos", ".", "x", ",", "y", ":", "nodePos", ".", "y", "}", ";", "graphics", ".", "transformGraphToClientCoordinates", "(", "domPos", ")", ";", "var", "labelStyle", "=", "generateDOMLabel", "(", "node", ")", ".", "style", ";", "labelStyle", ".", "left", "=", "domPos", ".", "x", ";", "labelStyle", ".", "top", "=", "domPos", ".", "y", ";", "}" ]
Removes the previous label and add a new one for the current node @param node
[ "Removes", "the", "previous", "label", "and", "add", "a", "new", "one", "for", "the", "current", "node" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L323-L336
18,990
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
generateDOMLabel
function generateDOMLabel(node) { var label = document.createElement('span'); label.className = 'nodeLabel'; label.id = node._id; if (node.name){ label.innerText = node.name; } else { label.innerText = node._id; } divGraph.appendChild(label); return label; }
javascript
function generateDOMLabel(node) { var label = document.createElement('span'); label.className = 'nodeLabel'; label.id = node._id; if (node.name){ label.innerText = node.name; } else { label.innerText = node._id; } divGraph.appendChild(label); return label; }
[ "function", "generateDOMLabel", "(", "node", ")", "{", "var", "label", "=", "document", ".", "createElement", "(", "'span'", ")", ";", "label", ".", "className", "=", "'nodeLabel'", ";", "label", ".", "id", "=", "node", ".", "_id", ";", "if", "(", "node", ".", "name", ")", "{", "label", ".", "innerText", "=", "node", ".", "name", ";", "}", "else", "{", "label", ".", "innerText", "=", "node", ".", "_id", ";", "}", "divGraph", ".", "appendChild", "(", "label", ")", ";", "return", "label", ";", "}" ]
Create a span element containing the name of the parameter node @param node @returns {Element}
[ "Create", "a", "span", "element", "containing", "the", "name", "of", "the", "parameter", "node" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L343-L355
18,991
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
createTableLayout
function createTableLayout(){ var tableItem = { type: 'component', componentName: 'Table' }; var stackItem = myLayout.root.getItemsById('stack-topleft')[0]; stackItem.addChild(tableItem); // get focus on the search tab stackItem.setActiveContentItem(myLayout.root.getItemsById('node-list')[0]); globalFunc.initTable(); }
javascript
function createTableLayout(){ var tableItem = { type: 'component', componentName: 'Table' }; var stackItem = myLayout.root.getItemsById('stack-topleft')[0]; stackItem.addChild(tableItem); // get focus on the search tab stackItem.setActiveContentItem(myLayout.root.getItemsById('node-list')[0]); globalFunc.initTable(); }
[ "function", "createTableLayout", "(", ")", "{", "var", "tableItem", "=", "{", "type", ":", "'component'", ",", "componentName", ":", "'Table'", "}", ";", "var", "stackItem", "=", "myLayout", ".", "root", ".", "getItemsById", "(", "'stack-topleft'", ")", "[", "0", "]", ";", "stackItem", ".", "addChild", "(", "tableItem", ")", ";", "// get focus on the search tab", "stackItem", ".", "setActiveContentItem", "(", "myLayout", ".", "root", ".", "getItemsById", "(", "'node-list'", ")", "[", "0", "]", ")", ";", "globalFunc", ".", "initTable", "(", ")", ";", "}" ]
Creates a golden-layout component for SlickGrid and initializes it
[ "Creates", "a", "golden", "-", "layout", "component", "for", "SlickGrid", "and", "initializes", "it" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L360-L371
18,992
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
initJQueryEvents
function initJQueryEvents(){ $('#searchDiv').parent().scroll(function() { if($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight - 100) { globalFunc.addNodesInList(); } }); $('#toggleLayout').click(function() { toggleLayout(); }); $("#sliderText").html("Context with <strong>2</strong> hops"); $("#slider").slider({ range: "max", min: 0, max: 10, value: 2, slide: function (event, ui){ var strHops = " hop"; if (ui.value > 1){ strHops = " hops"; } $("#sliderText").html("Context with <strong>" + ui.value + "</strong>" + strHops); NB_HOPS = ui.value; } }); }
javascript
function initJQueryEvents(){ $('#searchDiv').parent().scroll(function() { if($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight - 100) { globalFunc.addNodesInList(); } }); $('#toggleLayout').click(function() { toggleLayout(); }); $("#sliderText").html("Context with <strong>2</strong> hops"); $("#slider").slider({ range: "max", min: 0, max: 10, value: 2, slide: function (event, ui){ var strHops = " hop"; if (ui.value > 1){ strHops = " hops"; } $("#sliderText").html("Context with <strong>" + ui.value + "</strong>" + strHops); NB_HOPS = ui.value; } }); }
[ "function", "initJQueryEvents", "(", ")", "{", "$", "(", "'#searchDiv'", ")", ".", "parent", "(", ")", ".", "scroll", "(", "function", "(", ")", "{", "if", "(", "$", "(", "this", ")", ".", "scrollTop", "(", ")", "+", "$", "(", "this", ")", ".", "innerHeight", "(", ")", ">=", "$", "(", "this", ")", "[", "0", "]", ".", "scrollHeight", "-", "100", ")", "{", "globalFunc", ".", "addNodesInList", "(", ")", ";", "}", "}", ")", ";", "$", "(", "'#toggleLayout'", ")", ".", "click", "(", "function", "(", ")", "{", "toggleLayout", "(", ")", ";", "}", ")", ";", "$", "(", "\"#sliderText\"", ")", ".", "html", "(", "\"Context with <strong>2</strong> hops\"", ")", ";", "$", "(", "\"#slider\"", ")", ".", "slider", "(", "{", "range", ":", "\"max\"", ",", "min", ":", "0", ",", "max", ":", "10", ",", "value", ":", "2", ",", "slide", ":", "function", "(", "event", ",", "ui", ")", "{", "var", "strHops", "=", "\" hop\"", ";", "if", "(", "ui", ".", "value", ">", "1", ")", "{", "strHops", "=", "\" hops\"", ";", "}", "$", "(", "\"#sliderText\"", ")", ".", "html", "(", "\"Context with <strong>\"", "+", "ui", ".", "value", "+", "\"</strong>\"", "+", "strHops", ")", ";", "NB_HOPS", "=", "ui", ".", "value", ";", "}", "}", ")", ";", "}" ]
Initializes the necessary events
[ "Initializes", "the", "necessary", "events" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L376-L403
18,993
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
panToNode
function panToNode(node) { var pos = layout.getNodePosition(node._id); renderer.moveTo(pos.x, pos.y); highlightNodeWebGL(node); }
javascript
function panToNode(node) { var pos = layout.getNodePosition(node._id); renderer.moveTo(pos.x, pos.y); highlightNodeWebGL(node); }
[ "function", "panToNode", "(", "node", ")", "{", "var", "pos", "=", "layout", ".", "getNodePosition", "(", "node", ".", "_id", ")", ";", "renderer", ".", "moveTo", "(", "pos", ".", "x", ",", "pos", ".", "y", ")", ";", "highlightNodeWebGL", "(", "node", ")", ";", "}" ]
Center the focus on the node with nodeId, then highlight it @param node
[ "Center", "the", "focus", "on", "the", "node", "with", "nodeId", "then", "highlight", "it" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L409-L414
18,994
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
highlightNodeWebGL
function highlightNodeWebGL(node) { var ui = graphics.getNodeUI(node._id); if (prevNodeUI){ prevNodeUI.size = NODE_SIZE; //prevNodeUI.color = hexColorToWebGLColor(colorsByNodeType[node._type]); } prevNodeUI = ui; ui.size = NODE_SIZE * 4; //ui.color = 0xFFA500FF; //orange if (isPaused){ renderer.rerender(); } }
javascript
function highlightNodeWebGL(node) { var ui = graphics.getNodeUI(node._id); if (prevNodeUI){ prevNodeUI.size = NODE_SIZE; //prevNodeUI.color = hexColorToWebGLColor(colorsByNodeType[node._type]); } prevNodeUI = ui; ui.size = NODE_SIZE * 4; //ui.color = 0xFFA500FF; //orange if (isPaused){ renderer.rerender(); } }
[ "function", "highlightNodeWebGL", "(", "node", ")", "{", "var", "ui", "=", "graphics", ".", "getNodeUI", "(", "node", ".", "_id", ")", ";", "if", "(", "prevNodeUI", ")", "{", "prevNodeUI", ".", "size", "=", "NODE_SIZE", ";", "//prevNodeUI.color = hexColorToWebGLColor(colorsByNodeType[node._type]);", "}", "prevNodeUI", "=", "ui", ";", "ui", ".", "size", "=", "NODE_SIZE", "*", "4", ";", "//ui.color = 0xFFA500FF; //orange", "if", "(", "isPaused", ")", "{", "renderer", ".", "rerender", "(", ")", ";", "}", "}" ]
Highlight function especially for WebGL @param node
[ "Highlight", "function", "especially", "for", "WebGL" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L420-L433
18,995
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
addToGlobalNodes
function addToGlobalNodes(node){ var nodeToAdd = { "_id": node.id(), "_world": node.world(), "_time": node.time(), "_type": (node.nodeTypeName() ? node.nodeTypeName() : "default") }; var containsRel = false; // add all the attributes of the node to the JSON graph.resolver().resolveState(node, false).each(function (attributeKey, elemType, elem) { var key = graph.resolver().hashToString(attributeKey); if(elemType == org.mwg.Type.BOOL || elemType == org.mwg.Type.STRING || elemType == org.mwg.Type.INT || elemType == org.mwg.Type.LONG || elemType == org.mwg.Type.DOUBLE) { //primitive types nodeToAdd[key] = elem; } else if(elemType == org.mwg.Type.RELATION) { //classic relation nodeToAdd[key] = []; for (var i = 0; i < elem.size(); ++i){ nodeToAdd[key].push(elem.get(i)); } containsRel = true; } else if(elemType == org.mwg.Type.LONG_TO_LONG_ARRAY_MAP) { //indexed relation nodeToAdd[key] = []; elem.each(function(relKey,relIdNode) { nodeToAdd[key].push(relIdNode); }); containsRel = true; } else { throw "Type(" + elemType + ") is not yet managed. Please update the debugger." } }); // if the node contains a relationship, we add them into a global variable to deal with the relationships later if (containsRel){ gNodesWithRel.push(nodeToAdd); } // we sort the nodes per type if (gNodesPerType[nodeToAdd._type] == null){ gNodesPerType[nodeToAdd._type] = []; colorsByNodeType[nodeToAdd._type] = getRandomColor(); // add the type of the node to the type list and assign a color to the type } gNodesPerType[nodeToAdd._type].push(nodeToAdd); // finally we add them to the global array containing all the nodes gAllNodes.push(nodeToAdd); }
javascript
function addToGlobalNodes(node){ var nodeToAdd = { "_id": node.id(), "_world": node.world(), "_time": node.time(), "_type": (node.nodeTypeName() ? node.nodeTypeName() : "default") }; var containsRel = false; // add all the attributes of the node to the JSON graph.resolver().resolveState(node, false).each(function (attributeKey, elemType, elem) { var key = graph.resolver().hashToString(attributeKey); if(elemType == org.mwg.Type.BOOL || elemType == org.mwg.Type.STRING || elemType == org.mwg.Type.INT || elemType == org.mwg.Type.LONG || elemType == org.mwg.Type.DOUBLE) { //primitive types nodeToAdd[key] = elem; } else if(elemType == org.mwg.Type.RELATION) { //classic relation nodeToAdd[key] = []; for (var i = 0; i < elem.size(); ++i){ nodeToAdd[key].push(elem.get(i)); } containsRel = true; } else if(elemType == org.mwg.Type.LONG_TO_LONG_ARRAY_MAP) { //indexed relation nodeToAdd[key] = []; elem.each(function(relKey,relIdNode) { nodeToAdd[key].push(relIdNode); }); containsRel = true; } else { throw "Type(" + elemType + ") is not yet managed. Please update the debugger." } }); // if the node contains a relationship, we add them into a global variable to deal with the relationships later if (containsRel){ gNodesWithRel.push(nodeToAdd); } // we sort the nodes per type if (gNodesPerType[nodeToAdd._type] == null){ gNodesPerType[nodeToAdd._type] = []; colorsByNodeType[nodeToAdd._type] = getRandomColor(); // add the type of the node to the type list and assign a color to the type } gNodesPerType[nodeToAdd._type].push(nodeToAdd); // finally we add them to the global array containing all the nodes gAllNodes.push(nodeToAdd); }
[ "function", "addToGlobalNodes", "(", "node", ")", "{", "var", "nodeToAdd", "=", "{", "\"_id\"", ":", "node", ".", "id", "(", ")", ",", "\"_world\"", ":", "node", ".", "world", "(", ")", ",", "\"_time\"", ":", "node", ".", "time", "(", ")", ",", "\"_type\"", ":", "(", "node", ".", "nodeTypeName", "(", ")", "?", "node", ".", "nodeTypeName", "(", ")", ":", "\"default\"", ")", "}", ";", "var", "containsRel", "=", "false", ";", "// add all the attributes of the node to the JSON", "graph", ".", "resolver", "(", ")", ".", "resolveState", "(", "node", ",", "false", ")", ".", "each", "(", "function", "(", "attributeKey", ",", "elemType", ",", "elem", ")", "{", "var", "key", "=", "graph", ".", "resolver", "(", ")", ".", "hashToString", "(", "attributeKey", ")", ";", "if", "(", "elemType", "==", "org", ".", "mwg", ".", "Type", ".", "BOOL", "||", "elemType", "==", "org", ".", "mwg", ".", "Type", ".", "STRING", "||", "elemType", "==", "org", ".", "mwg", ".", "Type", ".", "INT", "||", "elemType", "==", "org", ".", "mwg", ".", "Type", ".", "LONG", "||", "elemType", "==", "org", ".", "mwg", ".", "Type", ".", "DOUBLE", ")", "{", "//primitive types", "nodeToAdd", "[", "key", "]", "=", "elem", ";", "}", "else", "if", "(", "elemType", "==", "org", ".", "mwg", ".", "Type", ".", "RELATION", ")", "{", "//classic relation", "nodeToAdd", "[", "key", "]", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "elem", ".", "size", "(", ")", ";", "++", "i", ")", "{", "nodeToAdd", "[", "key", "]", ".", "push", "(", "elem", ".", "get", "(", "i", ")", ")", ";", "}", "containsRel", "=", "true", ";", "}", "else", "if", "(", "elemType", "==", "org", ".", "mwg", ".", "Type", ".", "LONG_TO_LONG_ARRAY_MAP", ")", "{", "//indexed relation", "nodeToAdd", "[", "key", "]", "=", "[", "]", ";", "elem", ".", "each", "(", "function", "(", "relKey", ",", "relIdNode", ")", "{", "nodeToAdd", "[", "key", "]", ".", "push", "(", "relIdNode", ")", ";", "}", ")", ";", "containsRel", "=", "true", ";", "}", "else", "{", "throw", "\"Type(\"", "+", "elemType", "+", "\") is not yet managed. Please update the debugger.\"", "}", "}", ")", ";", "// if the node contains a relationship, we add them into a global variable to deal with the relationships later", "if", "(", "containsRel", ")", "{", "gNodesWithRel", ".", "push", "(", "nodeToAdd", ")", ";", "}", "// we sort the nodes per type", "if", "(", "gNodesPerType", "[", "nodeToAdd", ".", "_type", "]", "==", "null", ")", "{", "gNodesPerType", "[", "nodeToAdd", ".", "_type", "]", "=", "[", "]", ";", "colorsByNodeType", "[", "nodeToAdd", ".", "_type", "]", "=", "getRandomColor", "(", ")", ";", "// add the type of the node to the type list and assign a color to the type", "}", "gNodesPerType", "[", "nodeToAdd", ".", "_type", "]", ".", "push", "(", "nodeToAdd", ")", ";", "// finally we add them to the global array containing all the nodes", "gAllNodes", ".", "push", "(", "nodeToAdd", ")", ";", "}" ]
Transform every node from mwg and add them to a global var @param node
[ "Transform", "every", "node", "from", "mwg", "and", "add", "them", "to", "a", "global", "var" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L439-L486
18,996
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
addNodeToGraph
function addNodeToGraph(node){ gNodesDisplayed.push(node); g.addNode(node._id, node); if (contains(childrenNodes, node._id)){ var parentNode = getNodeFromId(nodesToBeLinked[node._id].from); if (contains(gNodesDisplayed, parentNode)){ addLinkToParent(node._id, parentNode._id); } } }
javascript
function addNodeToGraph(node){ gNodesDisplayed.push(node); g.addNode(node._id, node); if (contains(childrenNodes, node._id)){ var parentNode = getNodeFromId(nodesToBeLinked[node._id].from); if (contains(gNodesDisplayed, parentNode)){ addLinkToParent(node._id, parentNode._id); } } }
[ "function", "addNodeToGraph", "(", "node", ")", "{", "gNodesDisplayed", ".", "push", "(", "node", ")", ";", "g", ".", "addNode", "(", "node", ".", "_id", ",", "node", ")", ";", "if", "(", "contains", "(", "childrenNodes", ",", "node", ".", "_id", ")", ")", "{", "var", "parentNode", "=", "getNodeFromId", "(", "nodesToBeLinked", "[", "node", ".", "_id", "]", ".", "from", ")", ";", "if", "(", "contains", "(", "gNodesDisplayed", ",", "parentNode", ")", ")", "{", "addLinkToParent", "(", "node", ".", "_id", ",", "parentNode", ".", "_id", ")", ";", "}", "}", "}" ]
Add the node in param to the graph @param node
[ "Add", "the", "node", "in", "param", "to", "the", "graph" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L492-L504
18,997
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
addRelToGraph
function addRelToGraph(node){ var children = []; for (var prop in node){ if(node.hasOwnProperty(prop)){ if (typeof node[prop] === 'object') { var linkedNodes = node[prop]; // same for links if (colorsByLinkType[prop] == null) { colorsByLinkType[prop] = getRandomColor(); } for (var i = 0; i < linkedNodes.length; i++) { //find node by id in the array (using jQuery) const linkedNode = linkedNodes[i]; var nodeResult = getNodeFromId(linkedNode); gChildrenNodes.push(nodeResult); children.push(nodeResult); //if the node is displayed, we add a link otherwise we will need to add it later if (contains(gNodesDisplayed, nodeResult)){ g.addLink(node._id, nodeResult._id, prop); } else { nodesToBeLinked[nodeResult._id] = delayLinkCreation(node._id, nodeResult._id, prop); } } } } } gNodesWithChildren[node._id] = children; }
javascript
function addRelToGraph(node){ var children = []; for (var prop in node){ if(node.hasOwnProperty(prop)){ if (typeof node[prop] === 'object') { var linkedNodes = node[prop]; // same for links if (colorsByLinkType[prop] == null) { colorsByLinkType[prop] = getRandomColor(); } for (var i = 0; i < linkedNodes.length; i++) { //find node by id in the array (using jQuery) const linkedNode = linkedNodes[i]; var nodeResult = getNodeFromId(linkedNode); gChildrenNodes.push(nodeResult); children.push(nodeResult); //if the node is displayed, we add a link otherwise we will need to add it later if (contains(gNodesDisplayed, nodeResult)){ g.addLink(node._id, nodeResult._id, prop); } else { nodesToBeLinked[nodeResult._id] = delayLinkCreation(node._id, nodeResult._id, prop); } } } } } gNodesWithChildren[node._id] = children; }
[ "function", "addRelToGraph", "(", "node", ")", "{", "var", "children", "=", "[", "]", ";", "for", "(", "var", "prop", "in", "node", ")", "{", "if", "(", "node", ".", "hasOwnProperty", "(", "prop", ")", ")", "{", "if", "(", "typeof", "node", "[", "prop", "]", "===", "'object'", ")", "{", "var", "linkedNodes", "=", "node", "[", "prop", "]", ";", "// same for links", "if", "(", "colorsByLinkType", "[", "prop", "]", "==", "null", ")", "{", "colorsByLinkType", "[", "prop", "]", "=", "getRandomColor", "(", ")", ";", "}", "for", "(", "var", "i", "=", "0", ";", "i", "<", "linkedNodes", ".", "length", ";", "i", "++", ")", "{", "//find node by id in the array (using jQuery)", "const", "linkedNode", "=", "linkedNodes", "[", "i", "]", ";", "var", "nodeResult", "=", "getNodeFromId", "(", "linkedNode", ")", ";", "gChildrenNodes", ".", "push", "(", "nodeResult", ")", ";", "children", ".", "push", "(", "nodeResult", ")", ";", "//if the node is displayed, we add a link otherwise we will need to add it later", "if", "(", "contains", "(", "gNodesDisplayed", ",", "nodeResult", ")", ")", "{", "g", ".", "addLink", "(", "node", ".", "_id", ",", "nodeResult", ".", "_id", ",", "prop", ")", ";", "}", "else", "{", "nodesToBeLinked", "[", "nodeResult", ".", "_id", "]", "=", "delayLinkCreation", "(", "node", ".", "_id", ",", "nodeResult", ".", "_id", ",", "prop", ")", ";", "}", "}", "}", "}", "}", "gNodesWithChildren", "[", "node", ".", "_id", "]", "=", "children", ";", "}" ]
Add the necessary nodes and the relationships to the graph @param node
[ "Add", "the", "necessary", "nodes", "and", "the", "relationships", "to", "the", "graph" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L510-L541
18,998
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
getNodeFromId
function getNodeFromId(nodeId){ var res = $.grep(gAllNodes, function(e) { return e._id === nodeId; }); return res[0]; }
javascript
function getNodeFromId(nodeId){ var res = $.grep(gAllNodes, function(e) { return e._id === nodeId; }); return res[0]; }
[ "function", "getNodeFromId", "(", "nodeId", ")", "{", "var", "res", "=", "$", ".", "grep", "(", "gAllNodes", ",", "function", "(", "e", ")", "{", "return", "e", ".", "_id", "===", "nodeId", ";", "}", ")", ";", "return", "res", "[", "0", "]", ";", "}" ]
Function that will return the node from the id in parameter @param nodeId @returns {*}
[ "Function", "that", "will", "return", "the", "node", "from", "the", "id", "in", "parameter" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L548-L553
18,999
datathings/greycat
plugins/incub/visualizer/old/src/js/demo_vivagraph.js
delayLinkCreation
function delayLinkCreation(idParent, idChild, relationName){ childrenNodes.push(idChild); return { from: idParent, name: relationName }; }
javascript
function delayLinkCreation(idParent, idChild, relationName){ childrenNodes.push(idChild); return { from: idParent, name: relationName }; }
[ "function", "delayLinkCreation", "(", "idParent", ",", "idChild", ",", "relationName", ")", "{", "childrenNodes", ".", "push", "(", "idChild", ")", ";", "return", "{", "from", ":", "idParent", ",", "name", ":", "relationName", "}", ";", "}" ]
Handle the links that need to be created by keeping the nodes id and the relationship name @param idParent @param idChild @param relationName @returns {{from: *, to: *, name: *}}
[ "Handle", "the", "links", "that", "need", "to", "be", "created", "by", "keeping", "the", "nodes", "id", "and", "the", "relationship", "name" ]
602243bdd50e1f869bb19e3ac2991c540ea7af79
https://github.com/datathings/greycat/blob/602243bdd50e1f869bb19e3ac2991c540ea7af79/plugins/incub/visualizer/old/src/js/demo_vivagraph.js#L561-L567