From fef2a63770a2aaf8b176a7815937cc6652859c40 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 1 Jul 2016 15:51:59 -0700 Subject: [PATCH 1/3] Create variables from the flyout --- core/field_variable.js | 36 ++++---------------- core/flyout.js | 3 +- core/flyout_button.js | 12 +++++-- core/toolbox.js | 12 +++++++ core/variables.js | 77 ++++++++++++++++++++++++++++++++---------- core/workspace.js | 15 +++++++- core/workspace_svg.js | 13 +++++++ 7 files changed, 117 insertions(+), 51 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index 2f48e627d..0221f2937 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -110,7 +110,6 @@ Blockly.FieldVariable.dropdownCreate = function() { } variableList.sort(goog.string.caseInsensitiveCompare); variableList.push(Blockly.Msg.RENAME_VARIABLE); - variableList.push(Blockly.Msg.NEW_VARIABLE); variableList.push(Blockly.Msg.DELETE_VARIABLE.replace('%1', name)); // Variables are not language-specific, use the name as both the user-facing // text and the internal representation. @@ -123,8 +122,8 @@ Blockly.FieldVariable.dropdownCreate = function() { /** * Event handler for a change in variable name. - * Special case the 'New variable...' and 'Rename variable...' options. - * In both of these special cases, prompt the user for a new name. + * Special case the 'Rename variable...' and 'Delete variable...' options. + * In the rename case, prompt the user for a new name. * @param {string} text The selected dropdown menu option. * @return {null|undefined|string} An acceptable new variable name, or null if * change is to be either aborted (cancel button) or has been already @@ -132,40 +131,17 @@ Blockly.FieldVariable.dropdownCreate = function() { * @this {!Blockly.FieldVariable} */ Blockly.FieldVariable.classValidator = function(text) { - function promptName(promptText, defaultText) { - Blockly.hideChaff(); - var newVar = window.prompt(promptText, defaultText); - // Merge runs of whitespace. Strip leading and trailing whitespace. - // Beyond this, all names are legal. - if (newVar) { - newVar = newVar.replace(/[\s\xa0]+/g, ' ').replace(/^ | $/g, ''); - if (newVar == Blockly.Msg.RENAME_VARIABLE || - newVar == Blockly.Msg.NEW_VARIABLE) { - // Ok, not ALL names are legal... - newVar = null; - } - } - return newVar; - } var workspace = this.sourceBlock_.workspace; if (text == Blockly.Msg.RENAME_VARIABLE) { var oldVar = this.getText(); - text = promptName(Blockly.Msg.RENAME_VARIABLE_TITLE.replace('%1', oldVar), - oldVar); + Blockly.hideChaff(); + text = Blockly.Variables.promptName( + Blockly.Msg.RENAME_VARIABLE_TITLE.replace('%1', oldVar), oldVar); if (text) { Blockly.Variables.renameVariable(oldVar, text, workspace); } return null; - } else if (text == Blockly.Msg.NEW_VARIABLE) { - text = promptName(Blockly.Msg.NEW_VARIABLE_TITLE, ''); - // Since variables are case-insensitive, ensure that if the new variable - // matches with an existing variable, the new case prevails throughout. - if (text) { - Blockly.Variables.renameVariable(text, text, workspace); - return text; - } - return null; - } else if (text == Blockly.Msg.DELETE_VARIABLE.replace('%1', this.getText())) { + }else if (text == Blockly.Msg.DELETE_VARIABLE.replace('%1', this.getText())) { Blockly.Variables.delete(this.getText(), this.sourceBlock_.workspace); return null; } diff --git a/core/flyout.js b/core/flyout.js index b8c2367f2..8fa8b5d5c 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -574,7 +574,8 @@ Blockly.Flyout.prototype.show = function(xmlList) { } else if (tagName == 'BUTTON') { var label = xml.getAttribute('text'); - var curButton = new Blockly.FlyoutButton(this.workspace_, label); + var curButton = new Blockly.FlyoutButton(this.workspace_, + this.targetWorkspace_, label); contents.push({type: 'button', button: curButton}); gaps.push(this.MARGIN); } diff --git a/core/flyout_button.js b/core/flyout_button.js index 77d18f426..cd251897e 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -34,16 +34,23 @@ goog.require('goog.math.Coordinate'); * Class for a button in the flyout. * @param {!Blockly.Workspace} workspace The workspace in which to place this * button. + * @param {!Blockly.Workspace} targetWorkspace The flyout's target workspace. * @param {string} text The text to display on the button. * @constructor */ -Blockly.FlyoutButton = function(workspace, text) { +Blockly.FlyoutButton = function(workspace, targetWorkspace, text) { /** * @type {!Blockly.Workspace} * @private */ this.workspace_ = workspace; + /** + * @type {!Blockly.Workspace} + * @private + */ + this.targetWorkspace_ = targetWorkspace; + /** * @type {string} * @private @@ -150,9 +157,10 @@ Blockly.FlyoutButton.prototype.dispose = function() { * @param {!Event} e Mouse up event. */ Blockly.FlyoutButton.prototype.onMouseUp = function(e) { - console.log("Button was clicked"); // Don't scroll the page. e.preventDefault(); // Don't propagate mousewheel event (zooming). e.stopPropagation(); + + Blockly.Variables.createVariable(this.targetWorkspace_); }; diff --git a/core/toolbox.js b/core/toolbox.js index b5b27f869..3f715ed3a 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -420,6 +420,18 @@ Blockly.Toolbox.prototype.getClientRect = function() { } }; +/** + * Update the flyout's contents without closing it. Should be used in response + * to a change in one of the dynamic categories, such as variables or + * procedures. + */ +Blockly.Toolbox.prototype.refreshSelection = function() { + var selectedItem = this.tree_.getSelectedItem(); + if (selectedItem && selectedItem.blocks) { + this.flyout_.show(selectedItem.blocks); + } +}; + // Extending Closure's Tree UI. /** diff --git a/core/variables.js b/core/variables.js index 37a881791..3bc77f0e3 100644 --- a/core/variables.js +++ b/core/variables.js @@ -110,29 +110,31 @@ Blockly.Variables.flyoutCategory = function(workspace) { var button = goog.dom.createDom('button'); button.setAttribute('text', 'Create variable'); xmlList.push(button); - for (var i = 0; i < variableList.length; i++) { - if (Blockly.Blocks['variables_set']) { - // - // item - // - var block = goog.dom.createDom('block'); - block.setAttribute('type', 'variables_set'); - if (Blockly.Blocks['variables_get']) { - block.setAttribute('gap', 8); - } - var field = goog.dom.createDom('field', null, variableList[i]); - field.setAttribute('name', 'VAR'); - block.appendChild(field); - xmlList.push(block); - } + + if (Blockly.Blocks['variables_set']) { + // + // item + // + var block = goog.dom.createDom('block'); + block.setAttribute('type', 'variables_set'); if (Blockly.Blocks['variables_get']) { - // + block.setAttribute('gap', 20); + } + var field = goog.dom.createDom('field', null, variableList[0]); + field.setAttribute('name', 'VAR'); + block.appendChild(field); + xmlList.push(block); + } + + for (var i = 0; i < variableList.length; i++) { + if (Blockly.Blocks['variables_get']) { + // // item // var block = goog.dom.createDom('block'); block.setAttribute('type', 'variables_get'); if (Blockly.Blocks['variables_set']) { - block.setAttribute('gap', 24); + block.setAttribute('gap', 8); } var field = goog.dom.createDom('field', null, variableList[i]); field.setAttribute('name', 'VAR'); @@ -244,3 +246,44 @@ Blockly.Variables.delete = function(name, workspace) { Blockly.Variables.disposeUses(name, workspace); }; + +/** + * Create a new variable on the given workspace. + * @param {!Blockly.Workspace} workspace The workspace on which to create the + * variable. + * @return {null|undefined|string} An acceptable new variable name, or null if + * change is to be aborted (cancel button), or undefined if an existing + * variable was chosen. + */ +Blockly.Variables.createVariable = function(workspace) { + var text = Blockly.Variables.promptName(Blockly.Msg.NEW_VARIABLE_TITLE, ''); + // Since variables are case-insensitive, ensure that if the new variable + // matches with an existing variable, the new case prevails throughout. + if (text) { + workspace.createVariable(text); + return text; + } + return null; +}; + +/** + * Prompt the user for a new variable name. + * @param {string} promptText The string of the prompt. + * @param {string} defaultText The default value to show in the prompt's field. + * @return {string|null} The new variable name, or null if the user picked + * something illegal. + */ +Blockly.Variables.promptName = function(promptText, defaultText) { + var newVar = window.prompt(promptText, defaultText); + // Merge runs of whitespace. Strip leading and trailing whitespace. + // Beyond this, all names are legal. + if (newVar) { + newVar = newVar.replace(/[\s\xa0]+/g, ' ').replace(/^ | $/g, ''); + if (newVar == Blockly.Msg.RENAME_VARIABLE || + newVar == Blockly.Msg.NEW_VARIABLE) { + // Ok, not ALL names are legal... + newVar = null; + } + } + return newVar; +}; diff --git a/core/workspace.js b/core/workspace.js index 4d4d635d2..6e044fcb4 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -217,20 +217,33 @@ Blockly.Workspace.prototype.updateVariableList = function() { /** * Rename a variable by updating its name in the variable list. + * TODO: #468 * @param {string} oldName Variable to rename. * @param {string} newName New variable name. */ Blockly.Workspace.prototype.renameVariable = function(oldName, newName) { // Find the old name in the list and replace it. var variableIndex = this.variableList.indexOf(oldName); - if (variableIndex != -1) { + var newVariableIndex = this.variableList.indexOf(newName); + if (variableIndex != -1 && newVariableIndex == -1) { this.variableList[variableIndex] = newName; + } else if (variableIndex != -1 && newVariableIndex != -1) { + this.variableList.splice(variableIndex, 1); } else { this.variableList.push(newName); console.log('Tried to rename an non-existent variable.'); } }; +/** + * Create a variables with the given name. + * TODO: #468 + * @param {string} name The new variable's name. + */ +Blockly.Workspace.prototype.createVariable = function(name) { + this.variableList.push(name); +}; + /** * Returns the horizontal offset of the workspace. * Intended for LTR/RTL compatibility in XML. diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 6f9be212d..d02243551 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -589,6 +589,19 @@ Blockly.WorkspaceSvg.prototype.paste = function(xmlBlock) { block.select(); }; +/** + * Create a new variable with the given name. Update the flyout to show the new + * variable immediately. + * TODO: #468 + * @param {string} name The new variable's name. + */ +Blockly.WorkspaceSvg.prototype.createVariable = function(name) { + Blockly.WorkspaceSvg.superClass_.createVariable.call(this, name); + if (this.toolbox_ && this.toolbox_.flyout_) { + this.toolbox_.refreshSelection(); + } +}; + /** * Make a list of all the delete areas for this workspace. */ From 87de25ec9b23211138ef5e51aa02a85dd7c13c57 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 1 Jul 2016 16:17:30 -0700 Subject: [PATCH 2/3] Move the change block to the variables category --- blocks/math.js | 2 +- core/variables.js | 33 +++++++++++++++++++++++++++++++-- tests/playground.html | 7 ------- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/blocks/math.js b/blocks/math.js index 475fd6ce2..053b5458f 100644 --- a/blocks/math.js +++ b/blocks/math.js @@ -325,7 +325,7 @@ Blockly.Blocks['math_change'] = { ], "previousStatement": null, "nextStatement": null, - "colour": Blockly.Blocks.math.HUE, + "colour": Blockly.Blocks.variables.HUE, "helpUrl": Blockly.Msg.MATH_CHANGE_HELPURL }); // Assign 'this' to a variable for use in the tooltip closure below. diff --git a/core/variables.js b/core/variables.js index 3bc77f0e3..c5c5e22fb 100644 --- a/core/variables.js +++ b/core/variables.js @@ -117,14 +117,43 @@ Blockly.Variables.flyoutCategory = function(workspace) { // var block = goog.dom.createDom('block'); block.setAttribute('type', 'variables_set'); - if (Blockly.Blocks['variables_get']) { - block.setAttribute('gap', 20); + if (Blockly.Blocks['math_change']) { + block.setAttribute('gap', 8); + } else { + block.setAttribute('gap', 24); } var field = goog.dom.createDom('field', null, variableList[0]); field.setAttribute('name', 'VAR'); block.appendChild(field); xmlList.push(block); } + if (Blockly.Blocks['math_change']) { + // + // + // + // 1 + // + // + // + var block = goog.dom.createDom('block'); + block.setAttribute('type', 'math_change'); + if (Blockly.Blocks['variables_get']) { + block.setAttribute('gap', 20); + } + var value = goog.dom.createDom('value'); + value.setAttribute('name', 'DELTA'); + block.appendChild(value); + + var shadowBlock = goog.dom.createDom('shadow'); + shadowBlock.setAttribute('type', 'math_number'); + value.appendChild(shadowBlock); + + var field = goog.dom.createDom('field', null, '1'); + field.setAttribute('name', 'NUM'); + shadowBlock.appendChild(field); + + xmlList.push(block); + } for (var i = 0; i < variableList.length; i++) { if (Blockly.Blocks['variables_get']) { diff --git a/tests/playground.html b/tests/playground.html index e7e6e1166..144b4f4e7 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -472,13 +472,6 @@ h1 { - - - - 1 - - - From fc9e56de58349b2b158705e92ed4b4b3afa24622 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 7 Jul 2016 13:59:27 -0700 Subject: [PATCH 3/3] Lint and remove math_change wherever necessary --- blockly_compressed.js | 30 ++++++++++++++++-------------- blocks_compressed.js | 2 +- core/field_variable.js | 3 ++- core/flyout_button.js | 2 +- core/variables.js | 2 +- dart_compressed.js | 2 +- demos/code/index.html | 7 ------- demos/rtl/index.html | 7 ------- demos/toolbox/index.html | 7 ------- javascript_compressed.js | 4 ++-- msg/json/en.json | 2 +- php_compressed.js | 2 +- python_compressed.js | 6 +++--- tests/generators/index.html | 1 - tests/multi_playground.html | 7 ------- 15 files changed, 29 insertions(+), 55 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 77c193449..924a6f7f9 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -866,7 +866,8 @@ Blockly.Workspace.prototype.dispose=function(){this.listeners_.length=0;this.cle Blockly.Workspace.prototype.removeTopBlock=function(a){for(var b=!1,c,d=0;c=this.topBlocks_[d];d++)if(c==a){this.topBlocks_.splice(d,1);b=!0;break}if(!b)throw"Block not present in workspace's list of top-most blocks.";}; Blockly.Workspace.prototype.getTopBlocks=function(a){var b=[].concat(this.topBlocks_);if(a&&1this.MAX_UNDO&&this.undoStack_.unshift());for(var b=0,c;c=this.listeners_[b];b++)c(a)}; Blockly.Workspace.prototype.getBlockById=function(a){return this.blockDB_[a]||null};Blockly.Workspace.WorkspaceDB_=Object.create(null);Blockly.Workspace.getById=function(a){return Blockly.Workspace.WorkspaceDB_[a]||null};Blockly.Workspace.prototype.clear=Blockly.Workspace.prototype.clear;Blockly.Workspace.prototype.clearUndo=Blockly.Workspace.prototype.clearUndo;Blockly.Workspace.prototype.addChangeListener=Blockly.Workspace.prototype.addChangeListener; @@ -1034,7 +1035,7 @@ Blockly.WorkspaceSvg.prototype.getWidth=function(){var a=this.getMetrics();retur Blockly.WorkspaceSvg.prototype.traceOn=function(a){this.traceOn_=a;this.traceWrapper_&&(Blockly.unbindEvent_(this.traceWrapper_),this.traceWrapper_=null);a&&(this.traceWrapper_=Blockly.bindEvent_(this.svgBlockCanvas_,"blocklySelectChange",this,function(){this.traceOn_=!1}))}; Blockly.WorkspaceSvg.prototype.highlightBlock=function(a){this.traceOn_&&Blockly.dragMode_!=Blockly.DRAG_NONE&&this.traceOn(!1);if(this.traceOn_){var b=null;if(a&&(b=this.getBlockById(a),!b))return;this.traceOn(!1);b?b.select():Blockly.selected&&Blockly.selected.unselect();var c=this;setTimeout(function(){c.traceOn(!0)},1)}}; Blockly.WorkspaceSvg.prototype.paste=function(a){if(this.rendered&&!(a.getElementsByTagName("block").length>=this.remainingCapacity())){Blockly.terminateDrag_();Blockly.Events.disable();var b=Blockly.Xml.domToBlock(a,this),c=parseInt(a.getAttribute("x"),10);a=parseInt(a.getAttribute("y"),10);if(!isNaN(c)&&!isNaN(a)){this.RTL&&(c=-c);do{for(var d=!1,e=this.getAllBlocks(),f=0,g;g=e[f];f++)if(g=g.getRelativeToSurfaceXY(),1>=Math.abs(c-g.x)&&1>=Math.abs(a-g.y)){d=!0;break}if(!d)for(e=b.getConnections_(!1), -f=0;g=e[f];f++)if(g.closest(Blockly.SNAP_RADIUS,new goog.math.Coordinate(c,a)).connection){d=!0;break}d&&(c=this.RTL?c-Blockly.SNAP_RADIUS:c+Blockly.SNAP_RADIUS,a+=2*Blockly.SNAP_RADIUS)}while(d);b.moveBy(c,a)}Blockly.Events.enable();Blockly.Events.isEnabled()&&!b.isShadow()&&Blockly.Events.fire(new Blockly.Events.Create(b));b.select()}}; +f=0;g=e[f];f++)if(g.closest(Blockly.SNAP_RADIUS,new goog.math.Coordinate(c,a)).connection){d=!0;break}d&&(c=this.RTL?c-Blockly.SNAP_RADIUS:c+Blockly.SNAP_RADIUS,a+=2*Blockly.SNAP_RADIUS)}while(d);b.moveBy(c,a)}Blockly.Events.enable();Blockly.Events.isEnabled()&&!b.isShadow()&&Blockly.Events.fire(new Blockly.Events.Create(b));b.select()}};Blockly.WorkspaceSvg.prototype.createVariable=function(a){Blockly.WorkspaceSvg.superClass_.createVariable.call(this,a);this.toolbox_&&this.toolbox_.flyout_&&this.toolbox_.refreshSelection()}; Blockly.WorkspaceSvg.prototype.recordDeleteAreas=function(){this.deleteAreaTrash_=this.trashcan?this.trashcan.getClientRect():null;this.deleteAreaToolbox_=this.flyout_?this.flyout_.getClientRect():this.toolbox_?this.toolbox_.getClientRect():null}; Blockly.WorkspaceSvg.prototype.isDeleteArea=function(a){a=new goog.math.Coordinate(a.clientX,a.clientY);if(this.deleteAreaTrash_){if(this.deleteAreaTrash_.contains(a))return this.trashcan.setOpen_(!0),Blockly.Css.setCursor(Blockly.Css.Cursor.DELETE),!0;this.trashcan.setOpen_(!1)}if(this.deleteAreaToolbox_&&this.deleteAreaToolbox_.contains(a))return Blockly.Css.setCursor(Blockly.Css.Cursor.DELETE),!0;Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);return!1}; Blockly.WorkspaceSvg.prototype.onMouseDown_=function(a){this.markFocused();Blockly.isTargetInput_(a)||(Blockly.terminateDrag_(),Blockly.hideChaff(),a.target&&a.target.nodeName&&("svg"==a.target.nodeName.toLowerCase()||a.target==this.svgBackground_)&&Blockly.selected&&!this.options.readOnly&&Blockly.selected.unselect(),Blockly.isRightButton(a)?this.showContextMenu_(a):this.scrollbar&&(this.isScrolling=!0,this.startDragMouseX=a.clientX,this.startDragMouseY=a.clientY,this.startDragMetrics=this.getMetrics(), @@ -1276,15 +1277,15 @@ var a=this.rectElement_||this.imageElement_;a.tooltip=this.sourceBlock_;Blockly. Blockly.FieldImage.prototype.setValue=function(a){null!==a&&(this.src_=a,this.imageElement_&&this.imageElement_.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",goog.isString(a)?a:""))};Blockly.FieldImage.prototype.setText=function(a){null!==a&&(this.text_=a)};Blockly.FieldImage.prototype.render_=function(){};Blockly.FieldNumber=function(a,b,c,d,e){Blockly.FieldNumber.superClass_.constructor.call(this,a,e);this.setConstraints(b,c,d)};goog.inherits(Blockly.FieldNumber,Blockly.FieldTextInput);Blockly.FieldNumber.prototype.setConstraints=function(a,b,c){c=parseFloat(c);this.precision_=isNaN(c)?0:c;a=parseFloat(a);this.min_=isNaN(a)?-Infinity:a;b=parseFloat(b);this.max_=isNaN(b)?Infinity:b;this.setValue(this.callValidator(this.getValue))}; Blockly.FieldNumber.classValidator=function(a){if(null===a)return null;a=String(a);a=a.replace(/O/ig,"0");a=a.replace(/,/g,"");a=parseFloat(a||0);if(isNaN(a))return null;this.precision_&&Number.isFinite(a)&&(a=Math.round(a/this.precision_)*this.precision_);a=goog.math.clamp(a,this.min_,this.max_);return String(a)};Blockly.Variables={};Blockly.Variables.NAME_TYPE="VARIABLE";Blockly.Variables.allVariables=function(a){var b;if(a.getDescendants)b=a.getDescendants();else if(a.getAllBlocks)b=a.getAllBlocks();else throw"Not Block or Workspace: "+a;a=Object.create(null);for(var c=0;c - - - - 1 - - - diff --git a/demos/rtl/index.html b/demos/rtl/index.html index f2ae162f4..fd84febd2 100644 --- a/demos/rtl/index.html +++ b/demos/rtl/index.html @@ -87,13 +87,6 @@ - - - - 1 - - - diff --git a/demos/toolbox/index.html b/demos/toolbox/index.html index a4e70b878..4e81c02eb 100644 --- a/demos/toolbox/index.html +++ b/demos/toolbox/index.html @@ -84,13 +84,6 @@ - - - - 1 - - - diff --git a/javascript_compressed.js b/javascript_compressed.js index 46b1b89ae..5bee7a0cc 100644 --- a/javascript_compressed.js +++ b/javascript_compressed.js @@ -9,8 +9,8 @@ Blockly.JavaScript.ORDER_DIVISION=5.1;Blockly.JavaScript.ORDER_MULTIPLICATION=5. Blockly.JavaScript.ORDER_LOGICAL_AND=13;Blockly.JavaScript.ORDER_LOGICAL_OR=14;Blockly.JavaScript.ORDER_CONDITIONAL=15;Blockly.JavaScript.ORDER_ASSIGNMENT=16;Blockly.JavaScript.ORDER_COMMA=17;Blockly.JavaScript.ORDER_NONE=99; Blockly.JavaScript.ORDER_OVERRIDES=[[Blockly.JavaScript.ORDER_FUNCTION_CALL,Blockly.JavaScript.ORDER_MEMBER],[Blockly.JavaScript.ORDER_FUNCTION_CALL,Blockly.JavaScript.ORDER_FUNCTION_CALL],[Blockly.JavaScript.ORDER_MEMBER,Blockly.JavaScript.ORDER_MEMBER],[Blockly.JavaScript.ORDER_MEMBER,Blockly.JavaScript.ORDER_FUNCTION_CALL],[Blockly.JavaScript.ORDER_LOGICAL_NOT,Blockly.JavaScript.ORDER_LOGICAL_NOT],[Blockly.JavaScript.ORDER_MULTIPLICATION,Blockly.JavaScript.ORDER_MULTIPLICATION],[Blockly.JavaScript.ORDER_ADDITION, Blockly.JavaScript.ORDER_ADDITION],[Blockly.JavaScript.ORDER_LOGICAL_AND,Blockly.JavaScript.ORDER_LOGICAL_AND],[Blockly.JavaScript.ORDER_LOGICAL_OR,Blockly.JavaScript.ORDER_LOGICAL_OR]];Blockly.JavaScript.ONE_BASED_INDEXING=!0; -Blockly.JavaScript.init=function(a){Blockly.JavaScript.definitions_=Object.create(null);Blockly.JavaScript.functionNames_=Object.create(null);Blockly.JavaScript.variableDB_?Blockly.JavaScript.variableDB_.reset():Blockly.JavaScript.variableDB_=new Blockly.Names(Blockly.JavaScript.RESERVED_WORDS_);var b=[];a=Blockly.Variables.allVariables(a);if(a.length){for(var c=0;c", - "lastupdated": "2016-07-01 13:53:37.491022", + "lastupdated": "2016-07-07 13:57:36.962843", "locale": "en", "messagedocumentation" : "qqq" }, diff --git a/php_compressed.js b/php_compressed.js index da9ebbc90..1a4a5147b 100644 --- a/php_compressed.js +++ b/php_compressed.js @@ -49,7 +49,7 @@ Blockly.PHP.colour_rgb=function(a){var b=Blockly.PHP.valueToCode(a,"RED",Blockly ' $hex .= str_pad(dechex($g), 2, "0", STR_PAD_LEFT);',' $hex .= str_pad(dechex($b), 2, "0", STR_PAD_LEFT);'," return $hex;","}"])+"("+b+", "+c+", "+a+")",Blockly.PHP.ORDER_FUNCTION_CALL]}; Blockly.PHP.colour_blend=function(a){var b=Blockly.PHP.valueToCode(a,"COLOUR1",Blockly.PHP.ORDER_COMMA)||"'#000000'",c=Blockly.PHP.valueToCode(a,"COLOUR2",Blockly.PHP.ORDER_COMMA)||"'#000000'";a=Blockly.PHP.valueToCode(a,"RATIO",Blockly.PHP.ORDER_COMMA)||.5;return[Blockly.PHP.provideFunction_("colour_blend",["function "+Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_+"($c1, $c2, $ratio) {"," $ratio = max(min($ratio, 1), 0);"," $r1 = hexdec(substr($c1, 1, 2));"," $g1 = hexdec(substr($c1, 3, 2));"," $b1 = hexdec(substr($c1, 5, 2));", " $r2 = hexdec(substr($c2, 1, 2));"," $g2 = hexdec(substr($c2, 3, 2));"," $b2 = hexdec(substr($c2, 5, 2));"," $r = round($r1 * (1 - $ratio) + $r2 * $ratio);"," $g = round($g1 * (1 - $ratio) + $g2 * $ratio);"," $b = round($b1 * (1 - $ratio) + $b2 * $ratio);",' $hex = "#";',' $hex .= str_pad(dechex($r), 2, "0", STR_PAD_LEFT);',' $hex .= str_pad(dechex($g), 2, "0", STR_PAD_LEFT);',' $hex .= str_pad(dechex($b), 2, "0", STR_PAD_LEFT);'," return $hex;","}"])+"("+b+", "+c+", "+a+")",Blockly.PHP.ORDER_FUNCTION_CALL]};Blockly.PHP.procedures={}; -Blockly.PHP.procedures_defreturn=function(a){for(var b=Blockly.Variables.allVariables(a),c=b.length-1;0<=c;c--){var d=b[c];-1==a.arguments_.indexOf(d)?b[c]=Blockly.PHP.variableDB_.getName(d,Blockly.Variables.NAME_TYPE):b.splice(c,1)}b=b.length?" global "+b.join(", ")+";\n":"";c=Blockly.PHP.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE);d=Blockly.PHP.statementToCode(a,"STACK");Blockly.PHP.STATEMENT_PREFIX&&(d=Blockly.PHP.prefixLines(Blockly.PHP.STATEMENT_PREFIX.replace(/%1/g,"'"+ +Blockly.PHP.procedures_defreturn=function(a){for(var b=a.workspace.variableList,c=b.length-1;0<=c;c--){var d=b[c];-1==a.arguments_.indexOf(d)?b[c]=Blockly.PHP.variableDB_.getName(d,Blockly.Variables.NAME_TYPE):b.splice(c,1)}b=b.length?" global "+b.join(", ")+";\n":"";c=Blockly.PHP.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE);d=Blockly.PHP.statementToCode(a,"STACK");Blockly.PHP.STATEMENT_PREFIX&&(d=Blockly.PHP.prefixLines(Blockly.PHP.STATEMENT_PREFIX.replace(/%1/g,"'"+ a.id+"'"),Blockly.PHP.INDENT)+d);Blockly.PHP.INFINITE_LOOP_TRAP&&(d=Blockly.PHP.INFINITE_LOOP_TRAP.replace(/%1/g,"'"+a.id+"'")+d);var e=Blockly.PHP.valueToCode(a,"RETURN",Blockly.PHP.ORDER_NONE)||"";e&&(e=" return "+e+";\n");for(var g=[],f=0;f - diff --git a/tests/multi_playground.html b/tests/multi_playground.html index f541d6f6b..cdba845e9 100644 --- a/tests/multi_playground.html +++ b/tests/multi_playground.html @@ -236,13 +236,6 @@ h1 { - - - - 1 - - -