From 84838a67f35798676624a6de2b7238632b09766c Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 20 Aug 2015 12:07:48 -0700 Subject: [PATCH 01/98] Don't delete connected child blocks. --- core/block_svg.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/block_svg.js b/core/block_svg.js index e7f5176b7..a2268ccf6 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -456,7 +456,7 @@ Blockly.BlockSvg.prototype.onMouseUp_ = function(e) { // Don't throw an object in the trash can if it just got connected. this_.workspace.trashcan.close(); } - } else if (Blockly.selected.isDeletable() && + } else if (!this_.getParent() && Blockly.selected.isDeletable() && this_.workspace.isDeleteArea(e)) { var trashcan = this_.workspace.trashcan; if (trashcan) { From e8f1de3bdf07b6538a2d73369228c42515e95dbe Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 20 Aug 2015 14:09:14 -0700 Subject: [PATCH 02/98] Fix bottom-right workspace metrics when not at 100% zoom. --- core/blockly.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index 883bba13f..820978583 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -490,8 +490,8 @@ Blockly.getMainWorkspaceMetrics_ = function() { return null; } // Fix scale. - var contentWidth = blockBox.width; - var contentHeight = blockBox.height; + var contentWidth = blockBox.width * this.scale; + var contentHeight = blockBox.height * this.scale; var contentX = blockBox.x * this.scale; var contentY = blockBox.y * this.scale; if (this.scrollbar) { From 575b71246250d49c467ced08f4888fd72eae3ab2 Mon Sep 17 00:00:00 2001 From: Winston Date: Thu, 20 Aug 2015 15:18:58 -0700 Subject: [PATCH 03/98] fix: https://github.com/google/blockly/issues/161 On iOS, if I use a pinch gesture in the workspace, these errors appear in the console: Error: Invalid value for attribute x="NaN" --- core/blockly.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/blockly.js b/core/blockly.js index 883bba13f..ab56ed941 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -294,6 +294,9 @@ Blockly.onMouseUp_ = function(e) { * @private */ Blockly.onMouseMove_ = function(e) { + if (event.touches && event.touches.length >= 2) { + return // multi-touch gestures won't have e.clientX + } var workspace = Blockly.getMainWorkspace(); if (workspace.isScrolling) { Blockly.removeAllRanges(); From 53f54248018db2a5bb6f5133ee08ad20f78dbbc6 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 20 Aug 2015 15:46:44 -0700 Subject: [PATCH 04/98] Skc memory leaks (PR #159) --- blockly_compressed.js | 35 ++++++++++++++++++----------------- core/flyout.js | 19 +++++++++++-------- core/scrollbar.js | 6 ------ core/toolbox.js | 1 + core/workspace_svg.js | 40 +++++++++++++++++++++++++++++++--------- 5 files changed, 61 insertions(+), 40 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 1fd656d47..ffb647805 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -933,13 +933,13 @@ Blockly.Input.prototype.appendField=function(a,b){if(!a&&!b)return this;goog.isS Blockly.Input.prototype.appendTitle=function(a,b){console.warn("Deprecated call to appendTitle, use appendField instead.");return this.appendField(a,b)};Blockly.Input.prototype.removeField=function(a){for(var b=0,c;c=this.fieldRow[b];b++)if(c.name===a){c.dispose();this.fieldRow.splice(b,1);this.sourceBlock_.rendered&&(this.sourceBlock_.render(),this.sourceBlock_.bumpNeighbours_());return}goog.asserts.fail('Field "%s" not found.',a)};Blockly.Input.prototype.isVisible=function(){return this.visible_}; Blockly.Input.prototype.setVisible=function(a){var b=[];if(this.visible_==a)return b;for(var c=(this.visible_=a)?"block":"none",d=0,e;e=this.fieldRow[d];d++)e.setVisible(a);this.connection&&(a?b=this.connection.unhideAll():this.connection.hideAll(),d=this.connection.targetBlock())&&(d.getSvgRoot().style.display=c,a||(d.rendered=!1));return b};Blockly.Input.prototype.setCheck=function(a){if(!this.connection)throw"This input does not have a connection.";this.connection.setCheck(a);return this}; Blockly.Input.prototype.setAlign=function(a){this.align=a;this.sourceBlock_.rendered&&this.sourceBlock_.render();return this};Blockly.Input.prototype.init=function(){if(this.sourceBlock_.workspace.rendered)for(var a=0;athis.options.zoomOptions.maxScale?c=this.options.zoomOptions.maxScale/this.scale:dthis.workspace.remainingCapacity()&&(d.enabled=!1);c.push(d);this.isEditable()&&!this.collapsed_&&this.workspace.options.comments&&(d={enabled:!0},this.comment?(d.text=Blockly.Msg.REMOVE_COMMENT,d.callback= function(){b.setCommentText(null)}):(d.text=Blockly.Msg.ADD_COMMENT,d.callback=function(){b.setCommentText("")}),c.push(d));if(!this.collapsed_)for(d=1;d} * @private */ @@ -145,14 +145,14 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) { this.hide(); - this.eventWrappers_.concat(Blockly.bindEvent_(this.svgGroup_, - 'wheel', this, this.wheel_)); - this.eventWrappers_.concat( + Array.prototype.push.apply(this.eventWrappers_, + Blockly.bindEvent_(this.svgGroup_, 'wheel', this, this.wheel_)); + Array.prototype.push.apply(this.eventWrappers_, Blockly.bindEvent_(this.targetWorkspace_.getCanvas(), 'blocklyWorkspaceChange', this, this.filterForCapacity_)); // Dragging the flyout up and down. - this.eventWrappers_.concat(Blockly.bindEvent_(this.svgGroup_, - 'mousedown', this, this.onMouseDown_)); + Array.prototype.push.apply(this.eventWrappers_, + Blockly.bindEvent_(this.svgGroup_, 'mousedown', this, this.onMouseDown_)); }; /** @@ -162,12 +162,15 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) { Blockly.Flyout.prototype.dispose = function() { this.hide(); Blockly.unbindEvent_(this.eventWrappers_); - this.eventWrappers_.length = 0; if (this.scrollbar_) { this.scrollbar_.dispose(); this.scrollbar_ = null; } - this.workspace_ = null; + if (this.workspace_) { + this.workspace_.targetWorkspace = null; + this.workspace_.dispose(); + this.workspace_ = null; + } if (this.svgGroup_) { goog.dom.removeNode(this.svgGroup_); this.svgGroup_ = null; diff --git a/core/scrollbar.js b/core/scrollbar.js index 80adc623e..0712df792 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -53,8 +53,6 @@ Blockly.ScrollbarPair = function(workspace) { * Unlink from all DOM elements to prevent memory leaks. */ Blockly.ScrollbarPair.prototype.dispose = function() { - Blockly.unbindEvent_(this.onResizeWrapper_); - this.onResizeWrapper_ = null; goog.dom.removeNode(this.corner_); this.corner_ = null; this.workspace_ = null; @@ -190,10 +188,6 @@ if (goog.events.BrowserFeature.TOUCH_ENABLED) { */ Blockly.Scrollbar.prototype.dispose = function() { this.onMouseUpKnob_(); - if (this.onResizeWrapper_) { - Blockly.unbindEvent_(this.onResizeWrapper_); - this.onResizeWrapper_ = null; - } Blockly.unbindEvent_(this.onMouseDownBarWrapper_); this.onMouseDownBarWrapper_ = null; Blockly.unbindEvent_(this.onMouseDownKnobWrapper_); diff --git a/core/toolbox.js b/core/toolbox.js index cdc8f0a82..e975ba2ac 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -147,6 +147,7 @@ Blockly.Toolbox.prototype.dispose = function() { this.flyout_.dispose(); this.tree_.dispose(); goog.dom.removeNode(this.HtmlDiv); + this.workspace_ = null; }; /** diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 2030eec2d..9bea8211e 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -52,12 +52,20 @@ Blockly.WorkspaceSvg = function(options) { this.setMetrics = options.setMetrics; Blockly.ConnectionDB.init(this); + /** * Database of pre-loaded sounds. * @private * @const */ this.SOUNDS_ = Object.create(null); + + /** + * Opaque data that can be passed to Blockly.unbindEvent_. + * @type {Array.} + * @private + */ + this.eventWrappers_ = []; }; goog.inherits(Blockly.WorkspaceSvg, Blockly.Workspace); @@ -187,6 +195,7 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) { Blockly.WorkspaceSvg.prototype.dispose = function() { // Stop rerendering. this.rendered = false; + Blockly.unbindEvent_(this.eventWrappers_); Blockly.WorkspaceSvg.superClass_.dispose.call(this); if (this.svgGroup_) { goog.dom.removeNode(this.svgGroup_); @@ -206,9 +215,13 @@ Blockly.WorkspaceSvg.prototype.dispose = function() { this.trashcan.dispose(); this.trashcan = null; } - if (this.zoomControls) { - this.zoomControls.dispose(); - this.zoomControls = null; + if (this.scrollbar) { + this.scrollbar.dispose(); + this.scrollbar = null; + } + if (this.zoomControls_) { + this.zoomControls_.dispose(); + this.zoomControls_ = null; } if (!this.options.parentWorkspace) { // Top-most workspace. Dispose of the SVG too. @@ -221,6 +234,7 @@ Blockly.WorkspaceSvg.prototype.dispose = function() { * @private */ Blockly.WorkspaceSvg.prototype.addTrashcan_ = function() { + /** @type {Blockly.Trashcan} */ this.trashcan = new Blockly.Trashcan(this); var svgTrashcan = this.trashcan.createDom(); this.svgGroup_.insertBefore(svgTrashcan, this.svgBlockCanvas_); @@ -232,10 +246,11 @@ Blockly.WorkspaceSvg.prototype.addTrashcan_ = function() { * @private */ Blockly.WorkspaceSvg.prototype.addZoomControls_ = function() { - this.zoomControls = new Blockly.ZoomControls(this); - var svgZoomControls = this.zoomControls.createDom(); + /** @type {Blockly.ZoomControls} */ + this.zoomControls_ = new Blockly.ZoomControls(this); + var svgZoomControls = this.zoomControls_.createDom(); this.svgGroup_.appendChild(svgZoomControls); - this.zoomControls.init(); + this.zoomControls_.init(); }; /** @@ -247,6 +262,7 @@ Blockly.WorkspaceSvg.prototype.addFlyout_ = function() { parentWorkspace: this, RTL: this.RTL }; + /** @type {Blockly.Flyout} */ this.flyout_ = new Blockly.Flyout(workspaceOptions); this.flyout_.autoClose = false; var svgFlyout = this.flyout_.createDom(); @@ -266,8 +282,8 @@ Blockly.WorkspaceSvg.prototype.resize = function() { if (this.trashcan) { this.trashcan.position(); } - if (this.zoomControls) { - this.zoomControls.position(); + if (this.zoomControls_) { + this.zoomControls_.position(); } if (this.scrollbar) { this.scrollbar.resize(); @@ -811,8 +827,10 @@ Blockly.WorkspaceSvg.prototype.updateToolbox = function(tree) { * removeChangeListener. */ Blockly.WorkspaceSvg.prototype.addChangeListener = function(func) { - return Blockly.bindEvent_(this.getCanvas(), + var wrapper = Blockly.bindEvent_(this.getCanvas(), 'blocklyWorkspaceChange', null, func); + Array.prototype.push.apply(this.eventWrappers_, wrapper); + return wrapper; }; /** @@ -821,6 +839,10 @@ Blockly.WorkspaceSvg.prototype.addChangeListener = function(func) { */ Blockly.WorkspaceSvg.prototype.removeChangeListener = function(bindData) { Blockly.unbindEvent_(bindData); + var i = this.eventWrappers_.indexOf(bindData); + if (i != -1) { + this.eventWrappers_.splice(i, 1); + } }; /** From a43c426986073a937909da837b397c6cc5adb48d Mon Sep 17 00:00:00 2001 From: carlosperate Date: Fri, 21 Aug 2015 17:25:05 +0100 Subject: [PATCH 05/98] Remove additional height to the FieldImage size. --- core/field_image.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_image.js b/core/field_image.js index 26fab813b..5d132f6a1 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -46,7 +46,7 @@ Blockly.FieldImage = function(src, width, height, opt_alt) { // Ensure height and width are numbers. Strings are bad at math. this.height_ = Number(height); this.width_ = Number(width); - this.size_ = new goog.math.Size(this.height_ + 10, this.width_); + this.size_ = new goog.math.Size(this.height_, this.width_); this.text_ = opt_alt || ''; this.setValue(src); }; From 055c11155d3c7341ed3a941a311edf1997a5a6d8 Mon Sep 17 00:00:00 2001 From: carlosperate Date: Fri, 21 Aug 2015 18:51:25 +0100 Subject: [PATCH 06/98] Update getScaledBBox_ to return new object to fix issue in IE. --- core/field.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/field.js b/core/field.js index 279d19539..67a5c64ba 100644 --- a/core/field.js +++ b/core/field.js @@ -231,9 +231,9 @@ Blockly.Field.prototype.getSize = function() { */ Blockly.Field.prototype.getScaledBBox_ = function() { var bBox = this.borderRect_.getBBox(); - bBox.width *= this.sourceBlock_.workspace.scale; - bBox.height *= this.sourceBlock_.workspace.scale; - return bBox; + // Create new object, as getBBox can return an uneditable SVGRect. + return {width: bBox.width * this.sourceBlock_.workspace.scale, + height: bBox.height * this.sourceBlock_.workspace.scale}; }; /** From 17be3219ee37867267fd6eec797e5aeb577a8c90 Mon Sep 17 00:00:00 2001 From: carlosperate Date: Fri, 21 Aug 2015 19:20:00 +0100 Subject: [PATCH 07/98] Update FieldTextInput to not edit possible read-only attributes. The SVGRect returned from getBBox can be have its attributes as read-only. --- core/field_textinput.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index 3fdbacd0f..58db44915 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -228,10 +228,8 @@ Blockly.FieldTextInput.prototype.validate_ = function() { Blockly.FieldTextInput.prototype.resizeEditor_ = function() { var div = Blockly.WidgetDiv.DIV; var bBox = this.fieldGroup_.getBBox(); - bBox.width *= this.sourceBlock_.workspace.scale; - bBox.height *= this.sourceBlock_.workspace.scale; - div.style.width = bBox.width + 'px'; - div.style.height = bBox.height + 'px'; + div.style.width = bBox.width * this.sourceBlock_.workspace.scale + 'px'; + div.style.height = bBox.height * this.sourceBlock_.workspace.scale + 'px'; var xy = this.getAbsoluteXY_(); // In RTL mode block fields and LTR input fields the left edge moves, // whereas the right edge is fixed. Reposition the editor. From 466115d52bcf46c49f2839c34fb78103e9855af5 Mon Sep 17 00:00:00 2001 From: carlosperate Date: Fri, 21 Aug 2015 20:51:35 +0100 Subject: [PATCH 08/98] Revert DOM injection order of the zoom control images. --- core/zoom_controls.js | 47 ++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index a788d55bb..5e5077379 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -95,38 +95,40 @@ Blockly.ZoomControls.prototype.createDom = function() { var workspace = this.workspace_; /* Here's the markup that will be generated: - - - - - clip-path="url(#blocklyZoomresetClipPath837493)"> - - - - - clip-path="url(#blocklyZoominClipPath837493)"> clip-path="url(#blocklyZoomoutClipPath837493)"> + + + + + clip-path="url(#blocklyZoominClipPath837493)"> + + + + + clip-path="url(#blocklyZoomresetClipPath837493)"> */ this.svgGroup_ = Blockly.createSvgElement('g', {'class': 'blocklyZoom'}, null); var rnd = String(Math.random()).substring(2); + var clip = Blockly.createSvgElement('clipPath', - {'id': 'blocklyZoomresetClipPath' + rnd}, + {'id': 'blocklyZoomoutClipPath' + rnd}, this.svgGroup_); Blockly.createSvgElement('rect', - {'width': 32, 'height': 32}, + {'width': 32, 'height': 32, 'y': 77}, clip); - var zoomresetSvg = Blockly.createSvgElement('image', + var zoomoutSvg = Blockly.createSvgElement('image', {'width': Blockly.SPRITE.width, - 'height': Blockly.SPRITE.height, 'y': -92, - 'clip-path': 'url(#blocklyZoomresetClipPath' + rnd + ')'}, + 'height': Blockly.SPRITE.height, 'x': -64, + 'y': -15, + 'clip-path': 'url(#blocklyZoomoutClipPath' + rnd + ')'}, this.svgGroup_); - zoomresetSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', + zoomoutSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', workspace.options.pathToMedia + Blockly.SPRITE.url); var clip = Blockly.createSvgElement('clipPath', @@ -146,18 +148,17 @@ Blockly.ZoomControls.prototype.createDom = function() { workspace.options.pathToMedia + Blockly.SPRITE.url); var clip = Blockly.createSvgElement('clipPath', - {'id': 'blocklyZoomoutClipPath' + rnd}, + {'id': 'blocklyZoomresetClipPath' + rnd}, this.svgGroup_); Blockly.createSvgElement('rect', - {'width': 32, 'height': 32, 'y': 77}, + {'width': 32, 'height': 32}, clip); - var zoomoutSvg = Blockly.createSvgElement('image', + var zoomresetSvg = Blockly.createSvgElement('image', {'width': Blockly.SPRITE.width, - 'height': Blockly.SPRITE.height, 'x': -64, - 'y': -15, - 'clip-path': 'url(#blocklyZoomoutClipPath' + rnd + ')'}, + 'height': Blockly.SPRITE.height, 'y': -92, + 'clip-path': 'url(#blocklyZoomresetClipPath' + rnd + ')'}, this.svgGroup_); - zoomoutSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', + zoomresetSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', workspace.options.pathToMedia + Blockly.SPRITE.url); // Attach event listeners. From f601bdc3c73f8fe424bb7cd002eb46e2f61c8e27 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 21 Aug 2015 14:13:07 -0700 Subject: [PATCH 09/98] Fix FF editor location by a pixel. --- blockly_compressed.js | 8 ++++---- core/field.js | 8 ++++---- core/field_textinput.js | 6 ++++++ core/widgetdiv.js | 2 ++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index ffb647805..88b8ba0b1 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -914,7 +914,7 @@ this.mouseUpWrapper_=Blockly.bindEvent_(this.fieldGroup_,"mouseup",this,this.onM Blockly.Field.prototype.updateEditable=function(){this.EDITABLE&&this.sourceBlock_&&(this.sourceBlock_.isEditable()?(Blockly.addClass_(this.fieldGroup_,"blocklyEditableText"),Blockly.removeClass_(this.fieldGroup_,"blocklyNoNEditableText"),this.fieldGroup_.style.cursor=this.CURSOR):(Blockly.addClass_(this.fieldGroup_,"blocklyNonEditableText"),Blockly.removeClass_(this.fieldGroup_,"blocklyEditableText"),this.fieldGroup_.style.cursor=""))};Blockly.Field.prototype.isVisible=function(){return this.visible_}; Blockly.Field.prototype.setVisible=function(a){if(this.visible_!=a){this.visible_=a;var b=this.getSvgRoot();b&&(b.style.display=a?"block":"none",this.render_())}};Blockly.Field.prototype.setChangeHandler=function(a){this.changeHandler_=a};Blockly.Field.prototype.getSvgRoot=function(){return this.fieldGroup_}; Blockly.Field.prototype.render_=function(){if(this.visible_&&this.textElement_){try{var a=this.textElement_.getComputedTextLength()}catch(b){a=8*this.textElement_.textContent.length}this.borderRect_&&this.borderRect_.setAttribute("width",a+Blockly.BlockSvg.SEP_SPACE_X)}else a=0;this.size_.width=a};Blockly.Field.prototype.getSize=function(){this.size_.width||this.render_();return this.size_}; -Blockly.Field.prototype.getScaledBBox_=function(){var a=this.borderRect_.getBBox();a.width*=this.sourceBlock_.workspace.scale;a.height*=this.sourceBlock_.workspace.scale;return a};Blockly.Field.prototype.getText=function(){return this.text_};Blockly.Field.prototype.setText=function(a){null!==a&&(a=String(a),a!==this.text_&&(this.text_=a,this.updateTextNode_(),this.sourceBlock_&&this.sourceBlock_.rendered&&(this.sourceBlock_.render(),this.sourceBlock_.bumpNeighbours_(),this.sourceBlock_.workspace.fireChangeEvent())))}; +Blockly.Field.prototype.getScaledBBox_=function(){var a=this.borderRect_.getBBox();return new goog.math.Size(a.width*this.sourceBlock_.workspace.scale,a.height*this.sourceBlock_.workspace.scale)};Blockly.Field.prototype.getText=function(){return this.text_};Blockly.Field.prototype.setText=function(a){null!==a&&(a=String(a),a!==this.text_&&(this.text_=a,this.updateTextNode_(),this.sourceBlock_&&this.sourceBlock_.rendered&&(this.sourceBlock_.render(),this.sourceBlock_.bumpNeighbours_(),this.sourceBlock_.workspace.fireChangeEvent())))}; Blockly.Field.prototype.updateTextNode_=function(){if(this.textElement_){var a=this.text_;a.length>this.maxDisplayLength&&(a=a.substring(0,this.maxDisplayLength-2)+"\u2026");goog.dom.removeChildren(this.textElement_);a=a.replace(/\s/g,Blockly.Field.NBSP);this.sourceBlock_.RTL&&a&&(a+="\u200f");a||(a=Blockly.Field.NBSP);a=document.createTextNode(a);this.textElement_.appendChild(a);this.size_.width=0}};Blockly.Field.prototype.getValue=function(){return this.getText()}; Blockly.Field.prototype.setValue=function(a){this.setText(a)};Blockly.Field.prototype.onMouseUp_=function(a){if(!goog.userAgent.IPHONE&&!goog.userAgent.IPAD||goog.userAgent.isVersionOrHigher("537.51.2")||0===a.layerX||0===a.layerY)Blockly.isRightButton(a)||2!=Blockly.dragMode_&&this.sourceBlock_.isEditable()&&this.showEditor_()};Blockly.Field.prototype.setTooltip=function(a){};Blockly.Field.prototype.getAbsoluteXY_=function(){return goog.style.getPageOffset(this.borderRect_)};Blockly.Tooltip={};Blockly.Tooltip.visible=!1;Blockly.Tooltip.LIMIT=50;Blockly.Tooltip.mouseOutPid_=0;Blockly.Tooltip.showPid_=0;Blockly.Tooltip.lastX_=0;Blockly.Tooltip.lastY_=0;Blockly.Tooltip.element_=null;Blockly.Tooltip.poisonedElement_=null;Blockly.Tooltip.OFFSET_X=0;Blockly.Tooltip.OFFSET_Y=10;Blockly.Tooltip.RADIUS_OK=10;Blockly.Tooltip.HOVER_MS=1E3;Blockly.Tooltip.MARGINS=5;Blockly.Tooltip.DIV=null; Blockly.Tooltip.createDom=function(){Blockly.Tooltip.DIV||(Blockly.Tooltip.DIV=goog.dom.createDom("div","blocklyTooltipDiv"),document.body.appendChild(Blockly.Tooltip.DIV))};Blockly.Tooltip.bindMouseEvents=function(a){Blockly.bindEvent_(a,"mouseover",null,Blockly.Tooltip.onMouseOver_);Blockly.bindEvent_(a,"mouseout",null,Blockly.Tooltip.onMouseOut_);Blockly.bindEvent_(a,"mousemove",null,Blockly.Tooltip.onMouseMove_)}; @@ -1141,7 +1141,7 @@ var d=Blockly.FieldTextInput.FONTSIZE*this.sourceBlock_.workspace.scale+"pt";c.s b=this.sourceBlock_.workspace.getCanvas();a.onWorkspaceChangeWrapper_=Blockly.bindEvent_(b,"blocklyWorkspaceChange",this,this.resizeEditor_)}};Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_=function(a){var b=Blockly.FieldTextInput.htmlInput_;13==a.keyCode?Blockly.WidgetDiv.hide():27==a.keyCode&&(this.setText(b.defaultValue),Blockly.WidgetDiv.hide())}; Blockly.FieldTextInput.prototype.onHtmlInputChange_=function(a){var b=Blockly.FieldTextInput.htmlInput_;27!=a.keyCode&&(a=b.value,a!==b.oldValue_?(b.oldValue_=a,this.setText(a),this.validate_()):goog.userAgent.WEBKIT&&this.sourceBlock_.render())}; Blockly.FieldTextInput.prototype.validate_=function(){var a=!0;goog.asserts.assertObject(Blockly.FieldTextInput.htmlInput_);var b=Blockly.FieldTextInput.htmlInput_;this.sourceBlock_&&this.changeHandler_&&(a=this.changeHandler_(b.value));null===a?Blockly.addClass_(b,"blocklyInvalidInput"):Blockly.removeClass_(b,"blocklyInvalidInput")}; -Blockly.FieldTextInput.prototype.resizeEditor_=function(){var a=Blockly.WidgetDiv.DIV,b=this.fieldGroup_.getBBox();b.width*=this.sourceBlock_.workspace.scale;b.height*=this.sourceBlock_.workspace.scale;a.style.width=b.width+"px";a.style.height=b.height+"px";b=this.getAbsoluteXY_();if(this.sourceBlock_.RTL){var c=this.getScaledBBox_();b.x+=c.width;b.x-=a.offsetWidth}b.y+=1;goog.userAgent.WEBKIT&&(b.y-=3);a.style.left=b.x+"px";a.style.top=b.y+"px"}; +Blockly.FieldTextInput.prototype.resizeEditor_=function(){var a=Blockly.WidgetDiv.DIV,b=this.fieldGroup_.getBBox();a.style.width=b.width*this.sourceBlock_.workspace.scale+"px";a.style.height=b.height*this.sourceBlock_.workspace.scale+"px";b=this.getAbsoluteXY_();if(this.sourceBlock_.RTL){var c=this.getScaledBBox_();b.x+=c.width;b.x-=a.offsetWidth}b.y+=1;goog.userAgent.GECKO&&Blockly.WidgetDiv.DIV.style.top&&(--b.x,--b.y);goog.userAgent.WEBKIT&&(b.y-=3);a.style.left=b.x+"px";a.style.top=b.y+"px"}; Blockly.FieldTextInput.prototype.widgetDispose_=function(){var a=this;return function(){var b=Blockly.FieldTextInput.htmlInput_,c=b.value;if(a.sourceBlock_&&a.changeHandler_){var d=a.changeHandler_(c);null===d?c=b.defaultValue:void 0!==d&&(c=d)}a.setText(c);a.sourceBlock_.rendered&&a.sourceBlock_.render();Blockly.unbindEvent_(b.onKeyDownWrapper_);Blockly.unbindEvent_(b.onKeyUpWrapper_);Blockly.unbindEvent_(b.onKeyPressWrapper_);Blockly.unbindEvent_(b.onWorkspaceChangeWrapper_);Blockly.FieldTextInput.htmlInput_= null;b=Blockly.WidgetDiv.DIV.style;b.width="auto";b.height="auto";b.fontSize=""}};Blockly.FieldTextInput.numberValidator=function(a){if(null===a)return null;a=String(a);a=a.replace(/O/ig,"0");a=a.replace(/,/g,"");a=parseFloat(a||0);return isNaN(a)?null:String(a)};Blockly.FieldTextInput.nonnegativeIntegerValidator=function(a){(a=Blockly.FieldTextInput.numberValidator(a))&&(a=String(Math.max(0,Math.floor(a))));return a};Blockly.FieldAngle=function(a,b){this.symbol_=Blockly.createSvgElement("tspan",{},null);this.symbol_.appendChild(document.createTextNode("\u00b0"));Blockly.FieldAngle.superClass_.constructor.call(this,a,null);this.setChangeHandler(b)};goog.inherits(Blockly.FieldAngle,Blockly.FieldTextInput); Blockly.FieldAngle.prototype.setChangeHandler=function(a){Blockly.FieldAngle.superClass_.setChangeHandler.call(this,a?function(b){var c=a.call(this,b);if(null===c)var d=c;else void 0===c&&(c=b),d=Blockly.FieldAngle.angleValidator.call(this,c),void 0!==d&&(d=c);return d===b?void 0:d}:Blockly.FieldAngle.angleValidator)};Blockly.FieldAngle.ROUND=15;Blockly.FieldAngle.HALF=50;Blockly.FieldAngle.RADIUS=Blockly.FieldAngle.HALF-1; @@ -1168,7 +1168,7 @@ g.focus()}; Blockly.FieldDropdown.prototype.trimOptions_=function(){this.suffixField=this.prefixField=null;var a=this.menuGenerator_;if(goog.isArray(a)&&!(2>a.length)){var b=a.map(function(a){return a[0]}),c=Blockly.shortestStringLength(b),d=Blockly.commonWordPrefix(b,c),e=Blockly.commonWordSuffix(b,c);if((d||e)&&!(c<=d+e)){d&&(this.prefixField=b[0].substring(0,d-1));e&&(this.suffixField=b[0].substr(1-e));b=[];for(c=0;cc.width+d.x&&(a=c.width+d.x):a Date: Fri, 21 Aug 2015 14:54:11 -0700 Subject: [PATCH 10/98] Routine recompile. --- blockly_compressed.js | 14 +++++++------- core/blockly.js | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 88b8ba0b1..e22bb2e68 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -963,10 +963,10 @@ Blockly.Trashcan.prototype.animateLid_=function(){this.lidOpen_+=this.isOpen?.2: Blockly.Trashcan.prototype.close=function(){this.setOpen_(!1)}; // Copyright 2015 Google Inc. Apache License 2.0 Blockly.ZoomControls=function(a){this.workspace_=a};Blockly.ZoomControls.prototype.WIDTH_=32;Blockly.ZoomControls.prototype.HEIGHT_=110;Blockly.ZoomControls.prototype.MARGIN_BOTTOM_=100;Blockly.ZoomControls.prototype.MARGIN_SIDE_=35;Blockly.ZoomControls.prototype.svgGroup_=null;Blockly.ZoomControls.prototype.left_=0;Blockly.ZoomControls.prototype.top_=0; -Blockly.ZoomControls.prototype.createDom=function(){var a=this.workspace_;this.svgGroup_=Blockly.createSvgElement("g",{"class":"blocklyZoom"},null);var b=String(Math.random()).substring(2),c=Blockly.createSvgElement("clipPath",{id:"blocklyZoomresetClipPath"+b},this.svgGroup_);Blockly.createSvgElement("rect",{width:32,height:32},c);var d=Blockly.createSvgElement("image",{width:Blockly.SPRITE.width,height:Blockly.SPRITE.height,y:-92,"clip-path":"url(#blocklyZoomresetClipPath"+b+")"},this.svgGroup_); +Blockly.ZoomControls.prototype.createDom=function(){var a=this.workspace_;this.svgGroup_=Blockly.createSvgElement("g",{"class":"blocklyZoom"},null);var b=String(Math.random()).substring(2),c=Blockly.createSvgElement("clipPath",{id:"blocklyZoomoutClipPath"+b},this.svgGroup_);Blockly.createSvgElement("rect",{width:32,height:32,y:77},c);var d=Blockly.createSvgElement("image",{width:Blockly.SPRITE.width,height:Blockly.SPRITE.height,x:-64,y:-15,"clip-path":"url(#blocklyZoomoutClipPath"+b+")"},this.svgGroup_); d.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",a.options.pathToMedia+Blockly.SPRITE.url);c=Blockly.createSvgElement("clipPath",{id:"blocklyZoominClipPath"+b},this.svgGroup_);Blockly.createSvgElement("rect",{width:32,height:32,y:43},c);var e=Blockly.createSvgElement("image",{width:Blockly.SPRITE.width,height:Blockly.SPRITE.height,x:-32,y:-49,"clip-path":"url(#blocklyZoominClipPath"+b+")"},this.svgGroup_);e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",a.options.pathToMedia+ -Blockly.SPRITE.url);c=Blockly.createSvgElement("clipPath",{id:"blocklyZoomoutClipPath"+b},this.svgGroup_);Blockly.createSvgElement("rect",{width:32,height:32,y:77},c);b=Blockly.createSvgElement("image",{width:Blockly.SPRITE.width,height:Blockly.SPRITE.height,x:-64,y:-15,"clip-path":"url(#blocklyZoomoutClipPath"+b+")"},this.svgGroup_);b.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",a.options.pathToMedia+Blockly.SPRITE.url);Blockly.bindEvent_(d,"mousedown",a,a.zoomReset);Blockly.bindEvent_(e, -"mousedown",null,function(){a.zoomCenter(1)});Blockly.bindEvent_(b,"mousedown",null,function(){a.zoomCenter(-1)});return this.svgGroup_};Blockly.ZoomControls.prototype.init=function(){};Blockly.ZoomControls.prototype.dispose=function(){this.svgGroup_&&(goog.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.workspace_=null}; +Blockly.SPRITE.url);c=Blockly.createSvgElement("clipPath",{id:"blocklyZoomresetClipPath"+b},this.svgGroup_);Blockly.createSvgElement("rect",{width:32,height:32},c);b=Blockly.createSvgElement("image",{width:Blockly.SPRITE.width,height:Blockly.SPRITE.height,y:-92,"clip-path":"url(#blocklyZoomresetClipPath"+b+")"},this.svgGroup_);b.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",a.options.pathToMedia+Blockly.SPRITE.url);Blockly.bindEvent_(b,"mousedown",a,a.zoomReset);Blockly.bindEvent_(e, +"mousedown",null,function(){a.zoomCenter(1)});Blockly.bindEvent_(d,"mousedown",null,function(){a.zoomCenter(-1)});return this.svgGroup_};Blockly.ZoomControls.prototype.init=function(){};Blockly.ZoomControls.prototype.dispose=function(){this.svgGroup_&&(goog.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.workspace_=null}; Blockly.ZoomControls.prototype.position=function(){var a=this.workspace_.getMetrics();a&&(this.left_=this.workspace_.RTL?this.MARGIN_SIDE_:a.viewWidth+a.absoluteLeft-this.WIDTH_-this.MARGIN_SIDE_,this.top_=a.viewHeight+a.absoluteTop-this.HEIGHT_-this.MARGIN_BOTTOM_,this.svgGroup_.setAttribute("transform","translate("+this.left_+","+this.top_+")"))};Blockly.Xml={};Blockly.Xml.workspaceToDom=function(a){var b;a.RTL&&(b=a.getWidth());for(var c=goog.dom.createDom("xml"),d=a.getTopBlocks(!0),e=0,f;f=d[e];e++){var g=Blockly.Xml.blockToDom_(f);f=f.getRelativeToSurfaceXY();g.setAttribute("x",Math.round(a.RTL?b-f.x:f.x));g.setAttribute("y",Math.round(f.y));c.appendChild(g)}return c}; Blockly.Xml.blockToDom_=function(a){var b=goog.dom.createDom("block");b.setAttribute("type",a.type);b.setAttribute("id",a.id);if(a.mutationToDom){var c=a.mutationToDom();c&&(c.hasChildNodes()||c.hasAttributes())&&b.appendChild(c)}for(var c=0,d;d=a.inputList[c];c++)for(var e=0,f;f=d.fieldRow[e];e++)if(f.name&&f.EDITABLE){var g=goog.dom.createDom("field",null,f.getValue());g.setAttribute("name",f.name);b.appendChild(g)}if(c=a.getCommentText())c=goog.dom.createDom("comment",null,c),"object"==typeof a.comment&& (c.setAttribute("pinned",a.comment.isVisible()),d=a.comment.getBubbleSize(),c.setAttribute("h",d.height),c.setAttribute("w",d.width)),b.appendChild(c);a.data&&(c=goog.dom.createDom("data",null,a.data),b.appendChild(c));for(c=0;d=a.inputList[c];c++){var h,e=!0;d.type!=Blockly.DUMMY_INPUT&&(f=d.connection.targetBlock(),d.type==Blockly.INPUT_VALUE?h=goog.dom.createDom("value"):d.type==Blockly.NEXT_STATEMENT&&(h=goog.dom.createDom("statement")),f&&(h.appendChild(Blockly.Xml.blockToDom_(f)),e=!1),h.setAttribute("name", @@ -1316,10 +1316,10 @@ Blockly.OPPOSITE_TYPE=[];Blockly.OPPOSITE_TYPE[Blockly.INPUT_VALUE]=Blockly.OUTP Blockly.mainWorkspace=null;Blockly.clipboardXml_=null;Blockly.clipboardSource_=null;Blockly.dragMode_=0;Blockly.onTouchUpWrapper_=null;Blockly.svgSize=function(a){return{width:a.cachedWidth_,height:a.cachedHeight_}}; Blockly.svgResize=function(a){for(;a.options.parentWorkspace;)a=a.options.parentWorkspace;var b=a.options.svg,c=b.parentNode;if(c){var d=c.offsetWidth,c=c.offsetHeight;b.cachedWidth_!=d&&(b.setAttribute("width",d+"px"),b.cachedWidth_=d);b.cachedHeight_!=c&&(b.setAttribute("height",c+"px"),b.cachedHeight_=c);a.resize()}}; Blockly.onMouseUp_=function(a){a=Blockly.getMainWorkspace();Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN);a.isScrolling=!1;Blockly.onTouchUpWrapper_&&(Blockly.unbindEvent_(Blockly.onTouchUpWrapper_),Blockly.onTouchUpWrapper_=null);Blockly.onMouseMoveWrapper_&&(Blockly.unbindEvent_(Blockly.onMouseMoveWrapper_),Blockly.onMouseMoveWrapper_=null)}; -Blockly.onMouseMove_=function(a){var b=Blockly.getMainWorkspace();if(b.isScrolling){Blockly.removeAllRanges();var c=a.clientX-b.startDragMouseX,d=a.clientY-b.startDragMouseY,e=b.startDragMetrics,f=b.startScrollX+c,g=b.startScrollY+d,f=Math.min(f,-e.contentLeft),g=Math.min(g,-e.contentTop),f=Math.max(f,e.viewWidth-e.contentLeft-e.contentWidth),g=Math.max(g,e.viewHeight-e.contentTop-e.contentHeight);b.scrollbar.set(-f-e.contentLeft,-g-e.contentTop);Math.sqrt(c*c+d*d)>Blockly.DRAG_RADIUS&&Blockly.longStop_(); -a.stopPropagation()}}; -Blockly.onKeyDown_=function(a){if(!Blockly.isTargetInput_(a))if(27==a.keyCode)Blockly.hideChaff();else if(8==a.keyCode||46==a.keyCode)try{Blockly.selected&&Blockly.selected.isDeletable()&&(Blockly.hideChaff(),Blockly.selected.dispose(!0,!0))}finally{a.preventDefault()}else if(a.altKey||a.ctrlKey||a.metaKey)Blockly.selected&&Blockly.selected.isDeletable()&&Blockly.selected.isMovable()&&(Blockly.hideChaff(),67==a.keyCode?Blockly.copy_(Blockly.selected):88==a.keyCode&&(Blockly.copy_(Blockly.selected),Blockly.selected.dispose(!0, -!0))),86==a.keyCode&&Blockly.clipboardXml_&&Blockly.clipboardSource_.paste(Blockly.clipboardXml_)};Blockly.terminateDrag_=function(){Blockly.BlockSvg.terminateDrag_();Blockly.Flyout.terminateDrag_()};Blockly.longPid_=0;Blockly.longStart_=function(a,b){Blockly.longStop_();Blockly.longPid_=setTimeout(function(){a.button=2;b.onMouseDown_(a)},Blockly.LONGPRESS)};Blockly.longStop_=function(){Blockly.longPid_&&(clearTimeout(Blockly.longPid_),Blockly.longPid_=0)}; +Blockly.onMouseMove_=function(a){if(!(event.touches&&2<=event.touches.length)){var b=Blockly.getMainWorkspace();if(b.isScrolling){Blockly.removeAllRanges();var c=a.clientX-b.startDragMouseX,d=a.clientY-b.startDragMouseY,e=b.startDragMetrics,f=b.startScrollX+c,g=b.startScrollY+d,f=Math.min(f,-e.contentLeft),g=Math.min(g,-e.contentTop),f=Math.max(f,e.viewWidth-e.contentLeft-e.contentWidth),g=Math.max(g,e.viewHeight-e.contentTop-e.contentHeight);b.scrollbar.set(-f-e.contentLeft,-g-e.contentTop);Math.sqrt(c* +c+d*d)>Blockly.DRAG_RADIUS&&Blockly.longStop_();a.stopPropagation()}}}; +Blockly.onKeyDown_=function(a){if(!Blockly.isTargetInput_(a))if(27==a.keyCode)Blockly.hideChaff();else if(8==a.keyCode||46==a.keyCode)try{Blockly.selected&&Blockly.selected.isDeletable()&&(Blockly.hideChaff(),Blockly.selected.dispose(!0,!0))}finally{a.preventDefault()}else if(a.altKey||a.ctrlKey||a.metaKey)Blockly.selected&&Blockly.selected.isDeletable()&&Blockly.selected.isMovable()&&(Blockly.hideChaff(),67==a.keyCode?Blockly.copy_(Blockly.selected):88==a.keyCode&&(Blockly.copy_(Blockly.selected), +Blockly.selected.dispose(!0,!0))),86==a.keyCode&&Blockly.clipboardXml_&&Blockly.clipboardSource_.paste(Blockly.clipboardXml_)};Blockly.terminateDrag_=function(){Blockly.BlockSvg.terminateDrag_();Blockly.Flyout.terminateDrag_()};Blockly.longPid_=0;Blockly.longStart_=function(a,b){Blockly.longStop_();Blockly.longPid_=setTimeout(function(){a.button=2;b.onMouseDown_(a)},Blockly.LONGPRESS)};Blockly.longStop_=function(){Blockly.longPid_&&(clearTimeout(Blockly.longPid_),Blockly.longPid_=0)}; Blockly.copy_=function(a){var b=Blockly.Xml.blockToDom_(a);Blockly.Xml.deleteNext(b);var c=a.getRelativeToSurfaceXY();b.setAttribute("x",a.RTL?-c.x:c.x);b.setAttribute("y",c.y);Blockly.clipboardXml_=b;Blockly.clipboardSource_=a.workspace};Blockly.onContextMenu_=function(a){Blockly.isTargetInput_(a)||a.preventDefault()};Blockly.hideChaff=function(a){Blockly.Tooltip.hide();Blockly.WidgetDiv.hide();a||(a=Blockly.getMainWorkspace(),a.toolbox_&&a.toolbox_.flyout_&&a.toolbox_.flyout_.autoClose&&a.toolbox_.clearSelection())}; Blockly.getMainWorkspaceMetrics_=function(){var a=Blockly.svgSize(this.options.svg);this.toolbox_&&(a.width-=this.toolbox_.width);var b=a.width-Blockly.Scrollbar.scrollbarThickness,c=a.height-Blockly.Scrollbar.scrollbarThickness;try{var d=this.getCanvas().getBBox()}catch(e){return null}var f=d.width*this.scale,g=d.height*this.scale,h=d.x*this.scale,k=d.y*this.scale;if(this.scrollbar)var l=Math.min(h-b/2,h+f-b),b=Math.max(h+f+b/2,h+b),f=Math.min(k-c/2,k+g-c),c=Math.max(k+g+c/2,k+c);else l=d.x,b=l+ d.width,f=d.y,c=f+d.height;d=0;!this.RTL&&this.toolbox_&&(d=this.toolbox_.width);return{viewHeight:a.height,viewWidth:a.width,contentHeight:c-f,contentWidth:b-l,viewTop:-this.scrollY,viewLeft:-this.scrollX,contentTop:f,contentLeft:l,absoluteTop:0,absoluteLeft:d}}; diff --git a/core/blockly.js b/core/blockly.js index fea702823..a751160ad 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -295,7 +295,7 @@ Blockly.onMouseUp_ = function(e) { */ Blockly.onMouseMove_ = function(e) { if (event.touches && event.touches.length >= 2) { - return // multi-touch gestures won't have e.clientX + return; // Multi-touch gestures won't have e.clientX. } var workspace = Blockly.getMainWorkspace(); if (workspace.isScrolling) { From 20820b5861095eaddad74a622eb1a301d8017d61 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 21 Aug 2015 19:37:57 -0700 Subject: [PATCH 11/98] Fix drag events. --- blockly_compressed.js | 2 +- core/blockly.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index e22bb2e68..258d7c5b3 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -1316,7 +1316,7 @@ Blockly.OPPOSITE_TYPE=[];Blockly.OPPOSITE_TYPE[Blockly.INPUT_VALUE]=Blockly.OUTP Blockly.mainWorkspace=null;Blockly.clipboardXml_=null;Blockly.clipboardSource_=null;Blockly.dragMode_=0;Blockly.onTouchUpWrapper_=null;Blockly.svgSize=function(a){return{width:a.cachedWidth_,height:a.cachedHeight_}}; Blockly.svgResize=function(a){for(;a.options.parentWorkspace;)a=a.options.parentWorkspace;var b=a.options.svg,c=b.parentNode;if(c){var d=c.offsetWidth,c=c.offsetHeight;b.cachedWidth_!=d&&(b.setAttribute("width",d+"px"),b.cachedWidth_=d);b.cachedHeight_!=c&&(b.setAttribute("height",c+"px"),b.cachedHeight_=c);a.resize()}}; Blockly.onMouseUp_=function(a){a=Blockly.getMainWorkspace();Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN);a.isScrolling=!1;Blockly.onTouchUpWrapper_&&(Blockly.unbindEvent_(Blockly.onTouchUpWrapper_),Blockly.onTouchUpWrapper_=null);Blockly.onMouseMoveWrapper_&&(Blockly.unbindEvent_(Blockly.onMouseMoveWrapper_),Blockly.onMouseMoveWrapper_=null)}; -Blockly.onMouseMove_=function(a){if(!(event.touches&&2<=event.touches.length)){var b=Blockly.getMainWorkspace();if(b.isScrolling){Blockly.removeAllRanges();var c=a.clientX-b.startDragMouseX,d=a.clientY-b.startDragMouseY,e=b.startDragMetrics,f=b.startScrollX+c,g=b.startScrollY+d,f=Math.min(f,-e.contentLeft),g=Math.min(g,-e.contentTop),f=Math.max(f,e.viewWidth-e.contentLeft-e.contentWidth),g=Math.max(g,e.viewHeight-e.contentTop-e.contentHeight);b.scrollbar.set(-f-e.contentLeft,-g-e.contentTop);Math.sqrt(c* +Blockly.onMouseMove_=function(a){if(!(a.touches&&2<=a.touches.length)){var b=Blockly.getMainWorkspace();if(b.isScrolling){Blockly.removeAllRanges();var c=a.clientX-b.startDragMouseX,d=a.clientY-b.startDragMouseY,e=b.startDragMetrics,f=b.startScrollX+c,g=b.startScrollY+d,f=Math.min(f,-e.contentLeft),g=Math.min(g,-e.contentTop),f=Math.max(f,e.viewWidth-e.contentLeft-e.contentWidth),g=Math.max(g,e.viewHeight-e.contentTop-e.contentHeight);b.scrollbar.set(-f-e.contentLeft,-g-e.contentTop);Math.sqrt(c* c+d*d)>Blockly.DRAG_RADIUS&&Blockly.longStop_();a.stopPropagation()}}}; Blockly.onKeyDown_=function(a){if(!Blockly.isTargetInput_(a))if(27==a.keyCode)Blockly.hideChaff();else if(8==a.keyCode||46==a.keyCode)try{Blockly.selected&&Blockly.selected.isDeletable()&&(Blockly.hideChaff(),Blockly.selected.dispose(!0,!0))}finally{a.preventDefault()}else if(a.altKey||a.ctrlKey||a.metaKey)Blockly.selected&&Blockly.selected.isDeletable()&&Blockly.selected.isMovable()&&(Blockly.hideChaff(),67==a.keyCode?Blockly.copy_(Blockly.selected):88==a.keyCode&&(Blockly.copy_(Blockly.selected), Blockly.selected.dispose(!0,!0))),86==a.keyCode&&Blockly.clipboardXml_&&Blockly.clipboardSource_.paste(Blockly.clipboardXml_)};Blockly.terminateDrag_=function(){Blockly.BlockSvg.terminateDrag_();Blockly.Flyout.terminateDrag_()};Blockly.longPid_=0;Blockly.longStart_=function(a,b){Blockly.longStop_();Blockly.longPid_=setTimeout(function(){a.button=2;b.onMouseDown_(a)},Blockly.LONGPRESS)};Blockly.longStop_=function(){Blockly.longPid_&&(clearTimeout(Blockly.longPid_),Blockly.longPid_=0)}; diff --git a/core/blockly.js b/core/blockly.js index a751160ad..3a91a175d 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -294,7 +294,7 @@ Blockly.onMouseUp_ = function(e) { * @private */ Blockly.onMouseMove_ = function(e) { - if (event.touches && event.touches.length >= 2) { + if (e.touches && e.touches.length >= 2) { return; // Multi-touch gestures won't have e.clientX. } var workspace = Blockly.getMainWorkspace(); From 535b4202d922f70f0e413d479d8c2c78859932ef Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Mon, 24 Aug 2015 01:28:43 -0700 Subject: [PATCH 12/98] Convert 5 blocks to JSON. No functional change. --- blocks/colour.js | 33 +++++++++++++++++++++------------ blocks/lists.js | 13 +++++++------ blocks/logic.js | 39 ++++++++++++++++++++++++--------------- 3 files changed, 52 insertions(+), 33 deletions(-) diff --git a/blocks/colour.js b/blocks/colour.js index cdf2b2f00..7c92122ba 100644 --- a/blocks/colour.js +++ b/blocks/colour.js @@ -40,12 +40,20 @@ Blockly.Blocks['colour_picker'] = { * @this Blockly.Block */ init: function() { - this.setHelpUrl(Blockly.Msg.COLOUR_PICKER_HELPURL); - this.setColour(Blockly.Blocks.colour.HUE); - this.appendDummyInput() - .appendField(new Blockly.FieldColour('#ff0000'), 'COLOUR'); - this.setOutput(true, 'Colour'); - this.setTooltip(Blockly.Msg.COLOUR_PICKER_TOOLTIP); + this.jsonInit({ + "message0": "%1", + "args0": [ + { + "type": "field_colour", + "name": "COLOUR", + "colour": "#ff0000" + } + ], + "output": "Colour", + "colour": Blockly.Blocks.colour.HUE, + "tooltip": Blockly.Msg.COLOUR_PICKER_TOOLTIP, + "helpUrl": Blockly.Msg.COLOUR_PICKER_HELPURL + }); } }; @@ -55,12 +63,13 @@ Blockly.Blocks['colour_random'] = { * @this Blockly.Block */ init: function() { - this.setHelpUrl(Blockly.Msg.COLOUR_RANDOM_HELPURL); - this.setColour(Blockly.Blocks.colour.HUE); - this.appendDummyInput() - .appendField(Blockly.Msg.COLOUR_RANDOM_TITLE); - this.setOutput(true, 'Colour'); - this.setTooltip(Blockly.Msg.COLOUR_RANDOM_TOOLTIP); + this.jsonInit({ + "message0": Blockly.Msg.COLOUR_RANDOM_TITLE, + "output": "Colour", + "colour": Blockly.Blocks.colour.HUE, + "tooltip": Blockly.Msg.COLOUR_RANDOM_TOOLTIP, + "helpUrl": Blockly.Msg.COLOUR_RANDOM_HELPURL + }); } }; diff --git a/blocks/lists.js b/blocks/lists.js index 8f63cc1e0..65033551b 100644 --- a/blocks/lists.js +++ b/blocks/lists.js @@ -40,12 +40,13 @@ Blockly.Blocks['lists_create_empty'] = { * @this Blockly.Block */ init: function() { - this.setHelpUrl(Blockly.Msg.LISTS_CREATE_EMPTY_HELPURL); - this.setColour(Blockly.Blocks.lists.HUE); - this.setOutput(true, 'Array'); - this.appendDummyInput() - .appendField(Blockly.Msg.LISTS_CREATE_EMPTY_TITLE); - this.setTooltip(Blockly.Msg.LISTS_CREATE_EMPTY_TOOLTIP); + this.jsonInit({ + "message0": Blockly.Msg.LISTS_CREATE_EMPTY_TITLE, + "output": "Array", + "colour": Blockly.Blocks.lists.HUE, + "tooltip": Blockly.Msg.LISTS_CREATE_EMPTY_TOOLTIP, + "helpUrl": Blockly.Msg.LISTS_CREATE_EMPTY_HELPURL + }); } }; diff --git a/blocks/logic.js b/blocks/logic.js index 4aaf560bb..519039933 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -389,15 +389,23 @@ Blockly.Blocks['logic_boolean'] = { * @this Blockly.Block */ init: function() { - var BOOLEANS = - [[Blockly.Msg.LOGIC_BOOLEAN_TRUE, 'TRUE'], - [Blockly.Msg.LOGIC_BOOLEAN_FALSE, 'FALSE']]; - this.setHelpUrl(Blockly.Msg.LOGIC_BOOLEAN_HELPURL); - this.setColour(Blockly.Blocks.logic.HUE); - this.setOutput(true, 'Boolean'); - this.appendDummyInput() - .appendField(new Blockly.FieldDropdown(BOOLEANS), 'BOOL'); - this.setTooltip(Blockly.Msg.LOGIC_BOOLEAN_TOOLTIP); + this.jsonInit({ + "message0": "%1", + "args0": [ + { + "type": "field_dropdown", + "name": "BOOL", + "options": [ + [Blockly.Msg.LOGIC_BOOLEAN_TRUE, "TRUE"], + [Blockly.Msg.LOGIC_BOOLEAN_FALSE, "FALSE"] + ] + } + ], + "output": "Boolean", + "colour": Blockly.Blocks.logic.HUE, + "tooltip": Blockly.Msg.LOGIC_BOOLEAN_TOOLTIP, + "helpUrl": Blockly.Msg.LOGIC_BOOLEAN_HELPURL + }); } }; @@ -407,12 +415,13 @@ Blockly.Blocks['logic_null'] = { * @this Blockly.Block */ init: function() { - this.setHelpUrl(Blockly.Msg.LOGIC_NULL_HELPURL); - this.setColour(Blockly.Blocks.logic.HUE); - this.setOutput(true); - this.appendDummyInput() - .appendField(Blockly.Msg.LOGIC_NULL); - this.setTooltip(Blockly.Msg.LOGIC_NULL_TOOLTIP); + 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 + }); } }; From 218fdc667d4add125b7e8dc247a4514aa48b176e Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 25 Aug 2015 14:11:07 +0100 Subject: [PATCH 13/98] Fix duplicate procedure naming. https://groups.google.com/forum/#!topic/blockly/2q0pleoMIco --- blockly_compressed.js | 4 ++-- blocks/procedures.js | 21 +++++++++++++++------ blocks_compressed.js | 26 +++++++++++++------------- core/procedures.js | 2 +- core/xml.js | 4 ++++ 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 258d7c5b3..631127159 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -979,8 +979,8 @@ Blockly.Xml.domToBlockHeadless_=function(a,b,c){var d=null,e=b.getAttribute("typ (g=l);k=h.getAttribute("name");switch(h.nodeName.toLowerCase()){case "mutation":d.domToMutation&&(d.domToMutation(h),d.initSvg&&d.initSvg());break;case "comment":d.setCommentText(h.textContent);var q=h.getAttribute("pinned");q&&setTimeout(function(){d.comment&&d.comment.setVisible&&d.comment.setVisible("true"==q)},1);g=parseInt(h.getAttribute("w"),10);h=parseInt(h.getAttribute("h"),10);!isNaN(g)&&!isNaN(h)&&d.comment&&d.comment.setVisible&&d.comment.setBubbleSize(g,h);break;case "data":d.data=h.textContent; break;case "title":case "field":d.setFieldValue(h.textContent,k);break;case "value":case "statement":h=d.getInput(k);if(!h)throw"Input "+k+" does not exist in block "+e;if(g&&"block"==g.nodeName.toLowerCase())if(g=Blockly.Xml.domToBlockHeadless_(a,g,c),g.outputConnection)h.connection.connect(g.outputConnection);else if(g.previousConnection)h.connection.connect(g.previousConnection);else throw"Child block does not have output or previous statement.";break;case "next":if(g&&"block"==g.nodeName.toLowerCase()){if(!d.nextConnection)throw"Next statement does not exist."; if(d.nextConnection.targetConnection)throw"Next statement is already connected.";g=Blockly.Xml.domToBlockHeadless_(a,g,c);if(!g.previousConnection)throw"Next block does not have previous statement.";d.nextConnection.connect(g.previousConnection)}break;default:console.log("Ignoring unknown tag: "+h.nodeName)}}(a=b.getAttribute("inline"))&&d.setInputsInline("true"==a);(a=b.getAttribute("disabled"))&&d.setDisabled("true"==a);(a=b.getAttribute("deletable"))&&d.setDeletable("true"==a);(a=b.getAttribute("movable"))&& -d.setMovable("true"==a);(a=b.getAttribute("editable"))&&d.setEditable("true"==a);(b=b.getAttribute("collapsed"))&&d.setCollapsed("true"==b);return d};Blockly.Xml.deleteNext=function(a){for(var b=0,c;c=a.childNodes[b];b++)if("next"==c.nodeName.toLowerCase()){a.removeChild(c);break}};goog.global.Blockly||(goog.global.Blockly={});goog.global.Blockly.Xml||(goog.global.Blockly.Xml={});goog.global.Blockly.Xml.domToText=Blockly.Xml.domToText;goog.global.Blockly.Xml.domToWorkspace=Blockly.Xml.domToWorkspace; -goog.global.Blockly.Xml.textToDom=Blockly.Xml.textToDom;goog.global.Blockly.Xml.workspaceToDom=Blockly.Xml.workspaceToDom; +d.setMovable("true"==a);(a=b.getAttribute("editable"))&&d.setEditable("true"==a);(b=b.getAttribute("collapsed"))&&d.setCollapsed("true"==b);d.validate&&d.validate.call(d);return d};Blockly.Xml.deleteNext=function(a){for(var b=0,c;c=a.childNodes[b];b++)if("next"==c.nodeName.toLowerCase()){a.removeChild(c);break}};goog.global.Blockly||(goog.global.Blockly={});goog.global.Blockly.Xml||(goog.global.Blockly.Xml={});goog.global.Blockly.Xml.domToText=Blockly.Xml.domToText; +goog.global.Blockly.Xml.domToWorkspace=Blockly.Xml.domToWorkspace;goog.global.Blockly.Xml.textToDom=Blockly.Xml.textToDom;goog.global.Blockly.Xml.workspaceToDom=Blockly.Xml.workspaceToDom; // Copyright 2014 Google Inc. Apache License 2.0 Blockly.WorkspaceSvg=function(a){Blockly.WorkspaceSvg.superClass_.constructor.call(this,a);this.getMetrics=a.getMetrics;this.setMetrics=a.setMetrics;Blockly.ConnectionDB.init(this);this.SOUNDS_=Object.create(null);this.eventWrappers_=[]};goog.inherits(Blockly.WorkspaceSvg,Blockly.Workspace);Blockly.WorkspaceSvg.prototype.rendered=!0;Blockly.WorkspaceSvg.prototype.isFlyout=!1;Blockly.WorkspaceSvg.prototype.isScrolling=!1;Blockly.WorkspaceSvg.prototype.scrollX=0; Blockly.WorkspaceSvg.prototype.scrollY=0;Blockly.WorkspaceSvg.prototype.dragDeltaX_=0;Blockly.WorkspaceSvg.prototype.dragDeltaY_=0;Blockly.WorkspaceSvg.prototype.scale=1;Blockly.WorkspaceSvg.prototype.trashcan=null;Blockly.WorkspaceSvg.prototype.scrollbar=null; diff --git a/blocks/procedures.js b/blocks/procedures.js index 38703283b..9407b668a 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -42,9 +42,8 @@ Blockly.Blocks['procedures_defnoreturn'] = { init: function() { this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFNORETURN_HELPURL); this.setColour(Blockly.Blocks.procedures.HUE); - var name = Blockly.Procedures.findLegalName( - Blockly.Msg.PROCEDURES_DEFNORETURN_PROCEDURE, this); - var nameField = new Blockly.FieldTextInput(name, + var nameField = new Blockly.FieldTextInput( + Blockly.Msg.PROCEDURES_DEFNORETURN_PROCEDURE, Blockly.Procedures.rename); nameField.setSpellcheck(false); this.appendDummyInput() @@ -57,6 +56,16 @@ Blockly.Blocks['procedures_defnoreturn'] = { this.setStatements_(true); this.statementConnection_ = null; }, + /** + * Initialization of the block has completed, clean up anything that may be + * inconsistent as a result of the XML loading. + * @this Blockly.Block + */ + validate: function () { + var name = Blockly.Procedures.findLegalName( + this.getFieldValue('NAME'), this); + this.setFieldValue(name, 'NAME'); + }, /** * Add or remove the statement block from this function definition. * @param {boolean} hasStatements True if a statement block is needed. @@ -337,9 +346,8 @@ Blockly.Blocks['procedures_defreturn'] = { init: function() { this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFRETURN_HELPURL); this.setColour(Blockly.Blocks.procedures.HUE); - var name = Blockly.Procedures.findLegalName( - Blockly.Msg.PROCEDURES_DEFRETURN_PROCEDURE, this); - var nameField = new Blockly.FieldTextInput(name, + var nameField = new Blockly.FieldTextInput( + Blockly.Msg.PROCEDURES_DEFRETURN_PROCEDURE, Blockly.Procedures.rename); nameField.setSpellcheck(false); this.appendDummyInput() @@ -356,6 +364,7 @@ Blockly.Blocks['procedures_defreturn'] = { this.statementConnection_ = null; }, setStatements_: Blockly.Blocks['procedures_defnoreturn'].setStatements_, + validate: Blockly.Blocks['procedures_defnoreturn'].validate, updateParams_: Blockly.Blocks['procedures_defnoreturn'].updateParams_, mutationToDom: Blockly.Blocks['procedures_defnoreturn'].mutationToDom, domToMutation: Blockly.Blocks['procedures_defnoreturn'].domToMutation, diff --git a/blocks_compressed.js b/blocks_compressed.js index 52cfaf509..f34cbeca7 100644 --- a/blocks_compressed.js +++ b/blocks_compressed.js @@ -3,12 +3,12 @@ // Copyright 2012 Google Inc. Apache License 2.0 -Blockly.Blocks.colour={};Blockly.Blocks.colour.HUE=20;Blockly.Blocks.colour_picker={init:function(){this.setHelpUrl(Blockly.Msg.COLOUR_PICKER_HELPURL);this.setColour(Blockly.Blocks.colour.HUE);this.appendDummyInput().appendField(new Blockly.FieldColour("#ff0000"),"COLOUR");this.setOutput(!0,"Colour");this.setTooltip(Blockly.Msg.COLOUR_PICKER_TOOLTIP)}}; -Blockly.Blocks.colour_random={init:function(){this.setHelpUrl(Blockly.Msg.COLOUR_RANDOM_HELPURL);this.setColour(Blockly.Blocks.colour.HUE);this.appendDummyInput().appendField(Blockly.Msg.COLOUR_RANDOM_TITLE);this.setOutput(!0,"Colour");this.setTooltip(Blockly.Msg.COLOUR_RANDOM_TOOLTIP)}}; +Blockly.Blocks.colour={};Blockly.Blocks.colour.HUE=20;Blockly.Blocks.colour_picker={init:function(){this.jsonInit({message0:"%1",args0:[{type:"field_colour",name:"COLOUR",colour:"#ff0000"}],output:"Colour",colour:Blockly.Blocks.colour.HUE,tooltip:Blockly.Msg.COLOUR_PICKER_TOOLTIP,helpUrl:Blockly.Msg.COLOUR_PICKER_HELPURL})}}; +Blockly.Blocks.colour_random={init:function(){this.jsonInit({message0:Blockly.Msg.COLOUR_RANDOM_TITLE,output:"Colour",colour:Blockly.Blocks.colour.HUE,tooltip:Blockly.Msg.COLOUR_RANDOM_TOOLTIP,helpUrl:Blockly.Msg.COLOUR_RANDOM_HELPURL})}}; Blockly.Blocks.colour_rgb={init:function(){this.setHelpUrl(Blockly.Msg.COLOUR_RGB_HELPURL);this.setColour(Blockly.Blocks.colour.HUE);this.appendValueInput("RED").setCheck("Number").setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.COLOUR_RGB_TITLE).appendField(Blockly.Msg.COLOUR_RGB_RED);this.appendValueInput("GREEN").setCheck("Number").setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.COLOUR_RGB_GREEN);this.appendValueInput("BLUE").setCheck("Number").setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.COLOUR_RGB_BLUE); this.setOutput(!0,"Colour");this.setTooltip(Blockly.Msg.COLOUR_RGB_TOOLTIP)}}; Blockly.Blocks.colour_blend={init:function(){this.setHelpUrl(Blockly.Msg.COLOUR_BLEND_HELPURL);this.setColour(Blockly.Blocks.colour.HUE);this.appendValueInput("COLOUR1").setCheck("Colour").setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.COLOUR_BLEND_TITLE).appendField(Blockly.Msg.COLOUR_BLEND_COLOUR1);this.appendValueInput("COLOUR2").setCheck("Colour").setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.COLOUR_BLEND_COLOUR2);this.appendValueInput("RATIO").setCheck("Number").setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.COLOUR_BLEND_RATIO); -this.setOutput(!0,"Colour");this.setTooltip(Blockly.Msg.COLOUR_BLEND_TOOLTIP)}};Blockly.Blocks.lists={};Blockly.Blocks.lists.HUE=260;Blockly.Blocks.lists_create_empty={init:function(){this.setHelpUrl(Blockly.Msg.LISTS_CREATE_EMPTY_HELPURL);this.setColour(Blockly.Blocks.lists.HUE);this.setOutput(!0,"Array");this.appendDummyInput().appendField(Blockly.Msg.LISTS_CREATE_EMPTY_TITLE);this.setTooltip(Blockly.Msg.LISTS_CREATE_EMPTY_TOOLTIP)}}; +this.setOutput(!0,"Colour");this.setTooltip(Blockly.Msg.COLOUR_BLEND_TOOLTIP)}};Blockly.Blocks.lists={};Blockly.Blocks.lists.HUE=260;Blockly.Blocks.lists_create_empty={init:function(){this.jsonInit({message0:Blockly.Msg.LISTS_CREATE_EMPTY_TITLE,output:"Array",colour:Blockly.Blocks.lists.HUE,tooltip:Blockly.Msg.LISTS_CREATE_EMPTY_TOOLTIP,helpUrl:Blockly.Msg.LISTS_CREATE_EMPTY_HELPURL})}}; Blockly.Blocks.lists_create_with={init:function(){this.setHelpUrl(Blockly.Msg.LISTS_CREATE_WITH_HELPURL);this.setColour(Blockly.Blocks.lists.HUE);this.itemCount_=3;this.updateShape_();this.setOutput(!0,"Array");this.setMutator(new Blockly.Mutator(["lists_create_with_item"]));this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_TOOLTIP)},mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("items",this.itemCount_);return a},domToMutation:function(a){this.itemCount_=parseInt(a.getAttribute("items"), 10);this.updateShape_()},decompose:function(a){var b=Blockly.Block.obtain(a,"lists_create_with_container");b.initSvg();for(var c=b.getInput("STACK").connection,d=0;dd;d++){var e=1==d?a:b;e&&!e.outputConnection.checkType_(c)&&(c===this.prevParentConnection_?(this.setParent(null),c.sourceBlock_.bumpNeighbours_()):(e.setParent(null),e.bumpNeighbours_()))}this.prevParentConnection_=c}};Blockly.Blocks.loops={};Blockly.Blocks.loops.HUE=120;Blockly.Blocks.controls_repeat_ext={init:function(){this.jsonInit({message0:Blockly.Msg.CONTROLS_REPEAT_TITLE,args0:[{type:"input_value",name:"TIMES",check:"Number"}],previousStatement:null,nextStatement:null,colour:Blockly.Blocks.loops.HUE,tooltip:Blockly.Msg.CONTROLS_REPEAT_TOOLTIP,helpUrl:Blockly.Msg.CONTROLS_REPEAT_HELPURL});this.appendStatementInput("DO").appendField(Blockly.Msg.CONTROLS_REPEAT_INPUT_DO)}}; Blockly.Blocks.controls_repeat={init:function(){this.jsonInit({message0:Blockly.Msg.CONTROLS_REPEAT_TITLE,args0:[{type:"field_input",name:"TIMES",text:"10"}],previousStatement:null,nextStatement:null,colour:Blockly.Blocks.loops.HUE,tooltip:Blockly.Msg.CONTROLS_REPEAT_TOOLTIP,helpUrl:Blockly.Msg.CONTROLS_REPEAT_HELPURL});this.appendStatementInput("DO").appendField(Blockly.Msg.CONTROLS_REPEAT_INPUT_DO);this.getField("TIMES").setChangeHandler(Blockly.FieldTextInput.nonnegativeIntegerValidator)}}; @@ -82,19 +82,19 @@ Blockly.Blocks.math_modulo={init:function(){this.jsonInit({message0:Blockly.Msg. Blockly.Blocks.math_constrain={init: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:!0,output:"Number",colour:Blockly.Blocks.math.HUE,tooltip:Blockly.Msg.MATH_CONSTRAIN_TOOLTIP,helpUrl:Blockly.Msg.MATH_CONSTRAIN_HELPURL})}}; Blockly.Blocks.math_random_int={init:function(){this.jsonInit({message0:Blockly.Msg.MATH_RANDOM_INT_TITLE,args0:[{type:"input_value",name:"FROM",check:"Number"},{type:"input_value",name:"TO",check:"Number"}],inputsInline:!0,output:"Number",colour:Blockly.Blocks.math.HUE,tooltip:Blockly.Msg.MATH_RANDOM_INT_TOOLTIP,helpUrl:Blockly.Msg.MATH_RANDOM_INT_HELPURL})}}; Blockly.Blocks.math_random_float={init:function(){this.setHelpUrl(Blockly.Msg.MATH_RANDOM_FLOAT_HELPURL);this.setColour(Blockly.Blocks.math.HUE);this.setOutput(!0,"Number");this.appendDummyInput().appendField(Blockly.Msg.MATH_RANDOM_FLOAT_TITLE_RANDOM);this.setTooltip(Blockly.Msg.MATH_RANDOM_FLOAT_TOOLTIP)}};Blockly.Blocks.procedures={};Blockly.Blocks.procedures.HUE=290; -Blockly.Blocks.procedures_defnoreturn={init:function(){this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFNORETURN_HELPURL);this.setColour(Blockly.Blocks.procedures.HUE);var a=Blockly.Procedures.findLegalName(Blockly.Msg.PROCEDURES_DEFNORETURN_PROCEDURE,this),a=new Blockly.FieldTextInput(a,Blockly.Procedures.rename);a.setSpellcheck(!1);this.appendDummyInput().appendField(Blockly.Msg.PROCEDURES_DEFNORETURN_TITLE).appendField(a,"NAME").appendField("","PARAMS");this.setMutator(new Blockly.Mutator(["procedures_mutatorarg"])); -this.setTooltip(Blockly.Msg.PROCEDURES_DEFNORETURN_TOOLTIP);this.arguments_=[];this.setStatements_(!0);this.statementConnection_=null},setStatements_:function(a){this.hasStatements_!==a&&(a?(this.appendStatementInput("STACK").appendField(Blockly.Msg.PROCEDURES_DEFNORETURN_DO),this.getInput("RETURN")&&this.moveInputBefore("STACK","RETURN")):this.removeInput("STACK",!0),this.hasStatements_=a)},updateParams_:function(){for(var a=!1,b={},c=0;c Date: Tue, 25 Aug 2015 15:39:09 +0200 Subject: [PATCH 14/98] Update utils.js There is no global "getSelection()" function, see: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection --- core/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils.js b/core/utils.js index 149b365c6..4f1bdfb63 100644 --- a/core/utils.js +++ b/core/utils.js @@ -349,10 +349,10 @@ Blockly.createSvgElement = function(name, attrs, parent, opt_workspace) { * Deselect this text, so that it doesn't mess up any subsequent drag. */ Blockly.removeAllRanges = function() { - if (getSelection()) { + if (window.getSelection) { setTimeout(function() { try { - var selection = getSelection(); + var selection = window.getSelection(); if (!selection.isCollapsed) { selection.removeAllRanges(); } From ffe49a70205efb2098384b3a82a868cdb194916c Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 25 Aug 2015 15:09:55 +0100 Subject: [PATCH 15/98] Remove needless use of .call() --- core/procedures.js | 60 ++++++++++++++++++---------------------------- core/variables.js | 12 ++++------ 2 files changed, 28 insertions(+), 44 deletions(-) diff --git a/core/procedures.js b/core/procedures.js index 6d3c64ca6..5e84b5987 100644 --- a/core/procedures.js +++ b/core/procedures.js @@ -50,10 +50,9 @@ Blockly.Procedures.allProcedures = function(root) { var blocks = root.getAllBlocks(); var proceduresReturn = []; var proceduresNoReturn = []; - for (var x = 0; x < blocks.length; x++) { - var func = blocks[x].getProcedureDef; - if (func) { - var tuple = func.call(blocks[x]); + for (var i = 0; i < blocks.length; i++) { + if (blocks[i].getProcedureDef) { + var tuple = blocks[i].getProcedureDef(); if (tuple) { if (tuple[2]) { proceduresReturn.push(tuple); @@ -63,7 +62,6 @@ Blockly.Procedures.allProcedures = function(root) { } } } - proceduresNoReturn.sort(Blockly.Procedures.procTupleComparator_); proceduresReturn.sort(Blockly.Procedures.procTupleComparator_); return [proceduresNoReturn, proceduresReturn]; @@ -78,15 +76,7 @@ Blockly.Procedures.allProcedures = function(root) { * @private */ Blockly.Procedures.procTupleComparator_ = function(ta, tb) { - var a = ta[0].toLowerCase(); - var b = tb[0].toLowerCase(); - if (a > b) { - return 1; - } - if (a < b) { - return -1; - } - return 0; + return ta[0].toLowerCase().localeCompare(tb[0].toLowerCase()); }; /** @@ -124,13 +114,12 @@ Blockly.Procedures.findLegalName = function(name, block) { Blockly.Procedures.isLegalName = function(name, workspace, opt_exclude) { var blocks = workspace.getAllBlocks(); // Iterate through every block and check the name. - for (var x = 0; x < blocks.length; x++) { - if (blocks[x] == opt_exclude) { + for (var i = 0; i < blocks.length; i++) { + if (blocks[i] == opt_exclude) { continue; } - var func = blocks[x].getProcedureDef; - if (func) { - var procName = func.call(blocks[x]); + if (blocks[i].getProcedureDef) { + var procName = blocks[i].getProcedureDef(); if (Blockly.Names.equals(procName[0], name)) { return false; } @@ -153,10 +142,9 @@ Blockly.Procedures.rename = function(text) { text = Blockly.Procedures.findLegalName(text, this.sourceBlock_); // Rename any callers. var blocks = this.sourceBlock_.workspace.getAllBlocks(); - for (var x = 0; x < blocks.length; x++) { - var func = blocks[x].renameProcedure; - if (func) { - func.call(blocks[x], this.text_, text); + for (var i = 0; i < blocks.length; i++) { + if (blocks[i].renameProcedure) { + blocks[i].renameProcedure(this.text_, text); } } return text; @@ -223,13 +211,12 @@ Blockly.Procedures.getCallers = function(name, workspace) { var callers = []; var blocks = workspace.getAllBlocks(); // Iterate through every block and check the name. - for (var x = 0; x < blocks.length; x++) { - var func = blocks[x].getProcedureCall; - if (func) { - var procName = func.call(blocks[x]); + for (var i = 0; i < blocks.length; i++) { + if (blocks[i].getProcedureCall) { + var procName = blocks[i].getProcedureCall(); // Procedure name may be null if the block is only half-built. if (procName && Blockly.Names.equals(procName, name)) { - callers.push(blocks[x]); + callers.push(blocks[i]); } } } @@ -244,8 +231,8 @@ Blockly.Procedures.getCallers = function(name, workspace) { */ Blockly.Procedures.disposeCallers = function(name, workspace) { var callers = Blockly.Procedures.getCallers(name, workspace); - for (var x = 0; x < callers.length; x++) { - callers[x].dispose(true, false); + for (var i = 0; i < callers.length; i++) { + callers[i].dispose(true, false); } }; @@ -260,8 +247,8 @@ Blockly.Procedures.disposeCallers = function(name, workspace) { Blockly.Procedures.mutateCallers = function(name, workspace, paramNames, paramIds) { var callers = Blockly.Procedures.getCallers(name, workspace); - for (var x = 0; x < callers.length; x++) { - callers[x].setProcedureParameters(paramNames, paramIds); + for (var i = 0; i < callers.length; i++) { + callers[i].setProcedureParameters(paramNames, paramIds); } }; @@ -273,12 +260,11 @@ Blockly.Procedures.mutateCallers = function(name, workspace, */ Blockly.Procedures.getDefinition = function(name, workspace) { var blocks = workspace.getAllBlocks(); - for (var x = 0; x < blocks.length; x++) { - var func = blocks[x].getProcedureDef; - if (func) { - var tuple = func.call(blocks[x]); + for (var i = 0; i < blocks.length; i++) { + if (blocks[i].getProcedureDef) { + var tuple = blocks[i].getProcedureDef(); if (tuple && Blockly.Names.equals(tuple[0], name)) { - return blocks[x]; + return blocks[i]; } } } diff --git a/core/variables.js b/core/variables.js index a95c44f6d..4d5a695c0 100644 --- a/core/variables.js +++ b/core/variables.js @@ -56,9 +56,8 @@ Blockly.Variables.allVariables = function(root) { var variableHash = Object.create(null); // Iterate through every block and add each variable to the hash. for (var x = 0; x < blocks.length; x++) { - var func = blocks[x].getVars; - if (func) { - var blockVariables = func.call(blocks[x]); + if (blocks[x].getVars) { + var blockVariables = blocks[x].getVars(); for (var y = 0; y < blockVariables.length; y++) { var varName = blockVariables[y]; // Variable name may be null if the block is only half-built. @@ -85,10 +84,9 @@ Blockly.Variables.allVariables = function(root) { Blockly.Variables.renameVariable = function(oldName, newName, workspace) { var blocks = workspace.getAllBlocks(); // Iterate through every block. - for (var x = 0; x < blocks.length; x++) { - var func = blocks[x].renameVar; - if (func) { - func.call(blocks[x], oldName, newName); + for (var i = 0; i < blocks.length; i++) { + if (blocks[i].renameVar) { + blocks[i].renameVar(oldName, newName); } } }; From f81a5bd11ae64a4fade4db94fa3c0b175eae7263 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 26 Aug 2015 14:08:03 +0100 Subject: [PATCH 16/98] Expand regex to handle IE's scientific notation. --- core/utils.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/core/utils.js b/core/utils.js index 4f1bdfb63..bc59cfc2b 100644 --- a/core/utils.js +++ b/core/utils.js @@ -266,12 +266,7 @@ Blockly.getRelativeXY_ = function(element) { } // Second, check for transform="translate(...)" attribute. var transform = element.getAttribute('transform'); - // Note that Firefox and IE (9,10) return 'translate(12)' instead of - // 'translate(12, 0)'. - // Note that IE (9,10) returns 'translate(16 8)' instead of - // 'translate(16, 8)'. - var r = transform && - transform.match(/translate\(\s*([-\d.]+)([ ,]\s*([-\d.]+)\s*\))?/); + var r = transform && transform.match(Blockly.getRelativeXY_.XY_REGEXP_); if (r) { xy.x += parseFloat(r[1]); if (r[3]) { @@ -281,6 +276,18 @@ Blockly.getRelativeXY_ = function(element) { return xy; }; +/** + * Static regex to pull the x,y values out of an SVG translate() directive. + * Note that Firefox and IE (9,10) return 'translate(12)' instead of + * 'translate(12, 0)'. + * Note that IE (9,10) returns 'translate(16 8)' instead of 'translate(16, 8)'. + * Note that IE has been reported to return scientific notation (0.123456e-42). + * @type {!RegExp} + * @private + */ +Blockly.getRelativeXY_.XY_REGEXP_ = + /translate\(\s*([-+\d.e]+)([ ,]\s*([-+\d.e]+)\s*\))?/; + /** * Return the absolute coordinates of the top-left corner of this element, * scales that after canvas SVG element, if it's a descendant. From 8540118fe0b370d7738e62244354f6656ad01f08 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 26 Aug 2015 14:27:30 +0100 Subject: [PATCH 17/98] Add optional class to FieldLabel. --- core/field_label.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/field_label.js b/core/field_label.js index fbf1ecb0b..45063bdeb 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -35,12 +35,14 @@ goog.require('goog.math.Size'); /** * Class for a non-editable field. * @param {string} text The initial content of the field. + * @param {string=} opt_class Optional CSS class for the field's text. * @extends {Blockly.Field} * @constructor */ -Blockly.FieldLabel = function(text) { +Blockly.FieldLabel = function(text, opt_class) { this.sourceBlock_ = null; this.size_ = new goog.math.Size(0, 25); + this.class_ = opt_class; this.setText(text); }; goog.inherits(Blockly.FieldLabel, Blockly.Field); @@ -64,6 +66,9 @@ Blockly.FieldLabel.prototype.init = function(block) { // Build the DOM. this.textElement_ = Blockly.createSvgElement('text', {'class': 'blocklyText'}, null); + if (this.class_) { + Blockly.addClass_(this.textElement_, this.class_); + } if (!this.visible_) { this.textElement_.style.display = 'none'; } From d1d89abca84e7af7f9a377dbd1f3b4b68a133636 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 27 Aug 2015 15:08:26 +0100 Subject: [PATCH 18/98] Fix block locations on flyouts. Output tabs are negative coordinates. --- core/flyout.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/flyout.js b/core/flyout.js index d93d518db..36b1a5b69 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -468,9 +468,11 @@ Blockly.Flyout.prototype.reflow = function() { var margin = this.CORNER_RADIUS; var blocks = this.workspace_.getTopBlocks(false); for (var x = 0, block; block = blocks[x]; x++) { - var root = block.getSvgRoot(); - var blockHW = block.getHeightWidth(); - flyoutWidth = Math.max(flyoutWidth, blockHW.width); + var width = block.getHeightWidth().width; + if (block.outputConnection) { + width -= Blockly.BlockSvg.TAB_WIDTH; + } + flyoutWidth = Math.max(flyoutWidth, width); } flyoutWidth += margin + Blockly.BlockSvg.TAB_WIDTH + margin / 2 + Blockly.Scrollbar.scrollbarThickness; @@ -487,8 +489,10 @@ Blockly.Flyout.prototype.reflow = function() { if (block.flyoutRect_) { block.flyoutRect_.setAttribute('width', blockHW.width); block.flyoutRect_.setAttribute('height', blockHW.height); + // Blocks with output tabs are shifted a bit. + var tab = block.outputConnection ? Blockly.BlockSvg.TAB_WIDTH : 0; block.flyoutRect_.setAttribute('x', - this.RTL ? blockXY.x - blockHW.width : blockXY.x); + this.RTL ? blockXY.x - blockHW.width + tab : blockXY.x - tab); block.flyoutRect_.setAttribute('y', blockXY.y); } } From 8aa8bbb53efda394e694f52c3a20b512f0168e10 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 27 Aug 2015 16:46:45 +0100 Subject: [PATCH 19/98] Fix placement of blocks on zoomed flyouts. --- blockly_compressed.js | 36 ++++++++++++++++++------------------ core/flyout.js | 17 ++++++++++------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 631127159..c6f57cb1a 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -926,9 +926,9 @@ a?"rtl":"ltr";Blockly.Tooltip.DIV.style.display="block";Blockly.Tooltip.visible= (c=b.width-Blockly.Tooltip.DIV.offsetWidth-2*Blockly.Tooltip.MARGINS);Blockly.Tooltip.DIV.style.top=d+"px";Blockly.Tooltip.DIV.style.left=c+"px"}}; Blockly.Tooltip.wrap_=function(a,b){if(a.length<=b)return a;for(var c=a.trim().split(/\s+/),d=0;db&&(b=c[d].length);var e,d=-Infinity,f,g=1;do{e=d;f=a;for(var h=[],k=c.length/g,l=1,d=0;de);return f}; Blockly.Tooltip.wrapScore_=function(a,b,c){for(var d=[0],e=[],f=0;fd&&(d=h,e=g)}return e?Blockly.Tooltip.wrapMutate_(a,e,c):b};Blockly.Tooltip.wrapToText_=function(a,b){for(var c=[],d=0;dd&&(d=h,e=g)}return e?Blockly.Tooltip.wrapMutate_(a,e,c):b};Blockly.Tooltip.wrapToText_=function(a,b){for(var c=[],d=0;dd?1:c Date: Fri, 28 Aug 2015 09:53:03 +0100 Subject: [PATCH 20/98] Remove 'id' from XML unless realtime is enabled. --- core/xml.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/xml.js b/core/xml.js index 730541e79..5d090fbea 100644 --- a/core/xml.js +++ b/core/xml.js @@ -62,7 +62,10 @@ Blockly.Xml.workspaceToDom = function(workspace) { Blockly.Xml.blockToDom_ = function(block) { var element = goog.dom.createDom('block'); element.setAttribute('type', block.type); - element.setAttribute('id', block.id); + if (Blockly.Realtime.isEnabled()) { + // Only used by realtime. + element.setAttribute('id', block.id); + } if (block.mutationToDom) { // Custom data for an advanced block. var mutation = block.mutationToDom(); @@ -297,6 +300,7 @@ Blockly.Xml.domToBlockHeadless_ = } var id = xmlBlock.getAttribute('id'); if (opt_reuseBlock && id) { + // Only used by realtime. block = Blockly.Block.getById(id, workspace); // TODO: The following is for debugging. It should never actually happen. if (!block) { @@ -441,7 +445,7 @@ Blockly.Xml.domToBlockHeadless_ = } // Give the block a chance to clean up any initial inputs. if (block.validate) { - block.validate.call(block); + block.validate(); } return block; }; From 8f73c6b04262bc3fc36b1698880d7bd6594c9573 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 1 Sep 2015 12:22:50 +0100 Subject: [PATCH 21/98] Clean getSvgXY_. No functional change. --- core/utils.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/utils.js b/core/utils.js index bc59cfc2b..f81026695 100644 --- a/core/utils.js +++ b/core/utils.js @@ -28,9 +28,10 @@ goog.provide('Blockly.utils'); -goog.require('goog.events.BrowserFeature'); -goog.require('goog.userAgent'); goog.require('goog.dom'); +goog.require('goog.events.BrowserFeature'); +goog.require('goog.math.Coordinate'); +goog.require('goog.userAgent'); /** @@ -294,33 +295,33 @@ Blockly.getRelativeXY_.XY_REGEXP_ = * The origin (0,0) is the top-left corner of the Blockly SVG. * @param {!Element} element Element to find the coordinates of. * @param {!Blockly.Workspace} workspace Element must be in this workspace. - * @return {!Object} Object with .x and .y properties. + * @return {!goog.math.Coordinate} Object with .x and .y properties. * @private */ Blockly.getSvgXY_ = function(element, workspace) { var x = 0; var y = 0; // Evaluate if element isn't child of a canvas. - var canvasFlag = !goog.dom.contains(workspace.getCanvas(), element) && - !goog.dom.contains(workspace.getBubbleCanvas(), element); + var inCanvas = goog.dom.contains(workspace.getCanvas(), element) || + goog.dom.contains(workspace.getBubbleCanvas(), element); do { // Loop through this block and every parent. var xy = Blockly.getRelativeXY_(element); if (element == workspace.getCanvas() || element == workspace.getBubbleCanvas()) { - canvasFlag = true; + inCanvas = false; } // Before the SVG canvas scale the coordinates. - if (canvasFlag) { - x += xy.x; - y += xy.y; - } else { + if (inCanvas) { x += xy.x * workspace.scale; y += xy.y * workspace.scale; + } else { + x += xy.x; + y += xy.y; } element = element.parentNode; } while (element && element != workspace.options.svg); - return {x: x, y: y}; + return new goog.math.Coordinate(x, y); }; /** From 7568015c8cff38ceda82e647f6178bead9d0b39d Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 1 Sep 2015 20:00:13 +0100 Subject: [PATCH 22/98] Scale the flyout as the workspace zooms. --- core/flyout.js | 35 +++++++++++------------------------ core/utils.js | 26 ++++++++++++-------------- core/workspace_svg.js | 20 +++++++++++++------- 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/core/flyout.js b/core/flyout.js index 6aa6624ab..c0ca62305 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -363,6 +363,7 @@ Blockly.Flyout.prototype.show = function(xmlList) { } this.buttons_.length = 0; + this.workspace_.scale = this.targetWorkspace_.scale; var margin = this.CORNER_RADIUS; this.svgGroup_.style.display = 'block'; @@ -630,34 +631,20 @@ Blockly.Flyout.prototype.createBlockFunc_ = function(originBlock) { throw 'originBlock is not rendered.'; } var xyOld = Blockly.getSvgXY_(svgRootOld, workspace); + // Scale the scroll (getSvgXY_ did not do this). + xyOld.x += flyout.workspace_.scrollX / flyout.workspace_.scale - + flyout.workspace_.scrollX; + xyOld.y += flyout.workspace_.scrollY / flyout.workspace_.scale - + flyout.workspace_.scrollY; var svgRootNew = block.getSvgRoot(); if (!svgRootNew) { throw 'block is not rendered.'; } - if (workspace.scale == 1) { - // No scaling issues. - var xyNew = Blockly.getSvgXY_(svgRootNew, workspace); - block.moveBy(xyOld.x - xyNew.x, xyOld.y - xyNew.y); - } else { - // Scale the block while keeping the mouse location constant. - var mouseXY = Blockly.mouseToSvg(e, workspace.options.svg); - // Relative mouse position to the block. - var rMouseX = mouseXY.x - xyOld.x; - var rMouseY = mouseXY.y - xyOld.y; - // Fix scale. - xyOld.x /= workspace.scale; - xyOld.y /= workspace.scale; - // Calculate the position to create the block, fixing scale. - var xyCanvastoSvg = Blockly.getRelativeXY_(workspace.getCanvas()); - var xyNewtoCanvas = Blockly.getRelativeXY_(svgRootNew); - var newX = xyCanvastoSvg.x / workspace.scale + xyNewtoCanvas.x; - var newY = xyCanvastoSvg.y / workspace.scale + xyNewtoCanvas.y; - var placePositionX = xyOld.x - newX; - var placePositionY = xyOld.y - newY; - var dx = rMouseX - rMouseX / workspace.scale; - var dy = rMouseY - rMouseY / workspace.scale; - block.moveBy(placePositionX - dx, placePositionY - dy); - } + var xyNew = Blockly.getSvgXY_(svgRootNew, workspace); + // Scale the scroll (getSvgXY_ did not do this). + xyNew.x += workspace.scrollX / workspace.scale - workspace.scrollX; + xyNew.y += workspace.scrollY / workspace.scale - workspace.scrollY; + block.moveBy(xyOld.x - xyNew.x, xyOld.y - xyNew.y); if (flyout.autoClose) { flyout.hide(); } else { diff --git a/core/utils.js b/core/utils.js index f81026695..d02ca16fe 100644 --- a/core/utils.js +++ b/core/utils.js @@ -251,11 +251,11 @@ Blockly.isTargetInput_ = function(e) { * Return the coordinates of the top-left corner of this element relative to * its parent. Only for SVG elements and children (e.g. rect, g, path). * @param {!Element} element SVG element to find the coordinates of. - * @return {!Object} Object with .x and .y properties. + * @return {!goog.math.Coordinate} Object with .x and .y properties. * @private */ Blockly.getRelativeXY_ = function(element) { - var xy = {x: 0, y: 0}; + var xy = new goog.math.Coordinate(0, 0); // First, check for x and y attributes. var x = element.getAttribute('x'); if (x) { @@ -301,24 +301,22 @@ Blockly.getRelativeXY_.XY_REGEXP_ = Blockly.getSvgXY_ = function(element, workspace) { var x = 0; var y = 0; - // Evaluate if element isn't child of a canvas. - var inCanvas = goog.dom.contains(workspace.getCanvas(), element) || - goog.dom.contains(workspace.getBubbleCanvas(), element); + var scale = 1; + if (goog.dom.contains(workspace.getCanvas(), element) || + goog.dom.contains(workspace.getBubbleCanvas(), element)) { + // Before the SVG canvas, scale the coordinates. + scale = workspace.scale; + } do { // Loop through this block and every parent. var xy = Blockly.getRelativeXY_(element); if (element == workspace.getCanvas() || element == workspace.getBubbleCanvas()) { - inCanvas = false; - } - // Before the SVG canvas scale the coordinates. - if (inCanvas) { - x += xy.x * workspace.scale; - y += xy.y * workspace.scale; - } else { - x += xy.x; - y += xy.y; + // After the SVG canvas, don't scale the coordinates. + scale = 1; } + x += xy.x * scale; + y += xy.y * scale; element = element.parentNode; } while (element && element != workspace.options.svg); return new goog.math.Coordinate(x, y); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 9bea8211e..0365a0e74 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -635,7 +635,6 @@ Blockly.WorkspaceSvg.prototype.moveDrag = function(e) { * @private */ Blockly.WorkspaceSvg.prototype.onMouseWheel_ = function(e) { - Blockly.hideChaff(true); // TODO: Remove terminateDrag and compensate for coordinate skew during zoom. Blockly.terminateDrag_(); var delta = e.deltaY > 0 ? -1 : 1; @@ -881,12 +880,19 @@ Blockly.WorkspaceSvg.prototype.zoom = function(x, y, type) { .translate(x * (1 - scaleChange), y * (1 - scaleChange)) .scale(scaleChange); // newScale and matrix.a should be identical (within a rounding error). - if (this.scale != matrix.a) { - this.scale = matrix.a; - this.scrollX = matrix.e - metrics.absoluteLeft; - this.scrollY = matrix.f - metrics.absoluteTop; - this.updateGridPattern_(); - this.scrollbar.resize(); + if (this.scale == matrix.a) { + return; // No change in zoom. + } + this.scale = matrix.a; + this.scrollX = matrix.e - metrics.absoluteLeft; + this.scrollY = matrix.f - metrics.absoluteTop; + this.updateGridPattern_(); + this.scrollbar.resize(); + Blockly.hideChaff(false); + if (this.flyout_) { + // No toolbox, resize flyout. + this.flyout_.workspace_.scale = this.scale; + this.flyout_.reflow(); } }; From f9d47bd39e6c59a0a622f8d53acf17d9f751242f Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 1 Sep 2015 22:44:33 +0100 Subject: [PATCH 23/98] Lay out trashcan and zoom controls more flexibly. --- core/trashcan.js | 16 ++++++++++------ core/workspace_svg.js | 17 +++++++++++------ core/zoom_controls.js | 17 ++++++++++------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/core/trashcan.js b/core/trashcan.js index 35249e16b..1f8f72447 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -67,14 +67,14 @@ Blockly.Trashcan.prototype.LID_HEIGHT_ = 15; * @type {number} * @private */ -Blockly.Trashcan.prototype.MARGIN_BOTTOM_ = 35; +Blockly.Trashcan.prototype.MARGIN_BOTTOM_ = 20; /** * Distance between trashcan and right edge of workspace. * @type {number} * @private */ -Blockly.Trashcan.prototype.MARGIN_SIDE_ = 35; +Blockly.Trashcan.prototype.MARGIN_SIDE_ = 20; /** * Extent of hotspot on all sides beyond the size of the image. @@ -185,9 +185,13 @@ Blockly.Trashcan.prototype.createDom = function() { /** * Initialize the trash can. + * @param {number} bottom Distance from workspace bottom to bottom of trashcan. + * @return {number} Distance from workspace bottom to the top of trashcan. */ -Blockly.Trashcan.prototype.init = function() { +Blockly.Trashcan.prototype.init = function(bottom) { + this.bottom_ = this.MARGIN_BOTTOM_ + bottom; this.setOpen_(false); + return this.bottom_ + this.BODY_HEIGHT_ + this.LID_HEIGHT_; }; /** @@ -214,13 +218,13 @@ Blockly.Trashcan.prototype.position = function() { return; } if (this.workspace_.RTL) { - this.left_ = this.MARGIN_SIDE_; + this.left_ = this.MARGIN_SIDE_ + Blockly.Scrollbar.scrollbarThickness; } else { this.left_ = metrics.viewWidth + metrics.absoluteLeft - - this.WIDTH_ - this.MARGIN_SIDE_; + this.WIDTH_ - this.MARGIN_SIDE_ - Blockly.Scrollbar.scrollbarThickness; } this.top_ = metrics.viewHeight + metrics.absoluteTop - - (this.BODY_HEIGHT_ + this.LID_HEIGHT_) - this.MARGIN_BOTTOM_; + (this.BODY_HEIGHT_ + this.LID_HEIGHT_) - this.bottom_; this.svgGroup_.setAttribute('transform', 'translate(' + this.left_ + ',' + this.top_ + ')'); }; diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 0365a0e74..867080910 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -162,11 +162,12 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) { {'class': 'blocklyBlockCanvas'}, this.svgGroup_, this); this.svgBubbleCanvas_ = Blockly.createSvgElement('g', {'class': 'blocklyBubbleCanvas'}, this.svgGroup_, this); + var bottom = Blockly.Scrollbar.scrollbarThickness; if (this.options.hasTrashcan) { - this.addTrashcan_(); + bottom = this.addTrashcan_(bottom); } if (this.options.zoomOptions && this.options.zoomOptions.controls) { - this.addZoomControls_(); + bottom = this.addZoomControls_(bottom); } Blockly.bindEvent_(this.svgGroup_, 'mousedown', this, this.onMouseDown_); var thisWorkspace = this; @@ -231,26 +232,30 @@ Blockly.WorkspaceSvg.prototype.dispose = function() { /** * Add a trashcan. + * @param {number} bottom Distance from workspace bottom to bottom of trashcan. + * @return {number} Distance from workspace bottom to the top of trashcan. * @private */ -Blockly.WorkspaceSvg.prototype.addTrashcan_ = function() { +Blockly.WorkspaceSvg.prototype.addTrashcan_ = function(bottom) { /** @type {Blockly.Trashcan} */ this.trashcan = new Blockly.Trashcan(this); var svgTrashcan = this.trashcan.createDom(); this.svgGroup_.insertBefore(svgTrashcan, this.svgBlockCanvas_); - this.trashcan.init(); + return this.trashcan.init(bottom); }; /** * Add zoom controls. + * @param {number} bottom Distance from workspace bottom to bottom of controls. + * @return {number} Distance from workspace bottom to the top of controls. * @private */ -Blockly.WorkspaceSvg.prototype.addZoomControls_ = function() { +Blockly.WorkspaceSvg.prototype.addZoomControls_ = function(bottom) { /** @type {Blockly.ZoomControls} */ this.zoomControls_ = new Blockly.ZoomControls(this); var svgZoomControls = this.zoomControls_.createDom(); this.svgGroup_.appendChild(svgZoomControls); - this.zoomControls_.init(); + return this.zoomControls_.init(bottom); }; /** diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 5e5077379..c60622c75 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -57,14 +57,14 @@ Blockly.ZoomControls.prototype.HEIGHT_ = 110; * @type {number} * @private */ -Blockly.ZoomControls.prototype.MARGIN_BOTTOM_ = 100; +Blockly.ZoomControls.prototype.MARGIN_BOTTOM_ = 20; /** * Distance between zoom controls and right edge of workspace. * @type {number} * @private */ -Blockly.ZoomControls.prototype.MARGIN_SIDE_ = 35; +Blockly.ZoomControls.prototype.MARGIN_SIDE_ = 20; /** * The SVG group containing the zoom controls. @@ -175,9 +175,12 @@ Blockly.ZoomControls.prototype.createDom = function() { /** * Initialize the zoom controls. + * @param {number} bottom Distance from workspace bottom to bottom of controls. + * @return {number} Distance from workspace bottom to the top of controls. */ -Blockly.ZoomControls.prototype.init = function() { - // Initialize some stuff... (animations?) +Blockly.ZoomControls.prototype.init = function(bottom) { + this.bottom_ = this.MARGIN_BOTTOM_ + bottom; + return this.bottom_ + this.HEIGHT_; }; /** @@ -202,13 +205,13 @@ Blockly.ZoomControls.prototype.position = function() { return; } if (this.workspace_.RTL) { - this.left_ = this.MARGIN_SIDE_; + this.left_ = this.MARGIN_SIDE_ + Blockly.Scrollbar.scrollbarThickness; } else { this.left_ = metrics.viewWidth + metrics.absoluteLeft - - this.WIDTH_ - this.MARGIN_SIDE_; + this.WIDTH_ - this.MARGIN_SIDE_ - Blockly.Scrollbar.scrollbarThickness; } this.top_ = metrics.viewHeight + metrics.absoluteTop - - this.HEIGHT_ - this.MARGIN_BOTTOM_; + this.HEIGHT_ - this.bottom_; this.svgGroup_.setAttribute('transform', 'translate(' + this.left_ + ',' + this.top_ + ')'); }; From e4c902a105a8713fbc704c0630a1573a8c8339bf Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 2 Sep 2015 00:09:49 +0100 Subject: [PATCH 24/98] Fix RTL alignment of new blocks when zoomed. --- core/flyout.js | 14 ++++++++++---- core/workspace_svg.js | 6 +++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/flyout.js b/core/flyout.js index c0ca62305..18f37397d 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -363,7 +363,6 @@ Blockly.Flyout.prototype.show = function(xmlList) { } this.buttons_.length = 0; - this.workspace_.scale = this.targetWorkspace_.scale; var margin = this.CORNER_RADIUS; this.svgGroup_.style.display = 'block'; @@ -466,6 +465,7 @@ Blockly.Flyout.prototype.show = function(xmlList) { * For RTL: Lay out the blocks right-aligned. */ Blockly.Flyout.prototype.reflow = function() { + this.workspace_.scale = this.targetWorkspace_.scale; var flyoutWidth = 0; var margin = this.CORNER_RADIUS; var blocks = this.workspace_.getTopBlocks(false); @@ -484,10 +484,11 @@ Blockly.Flyout.prototype.reflow = function() { var blockHW = block.getHeightWidth(); if (this.RTL) { // With the flyoutWidth known, right-align the blocks. + var oldX = block.getRelativeToSurfaceXY().x; var dx = flyoutWidth - margin; dx /= this.workspace_.scale; dx -= Blockly.BlockSvg.TAB_WIDTH; - block.moveBy(dx, 0); + block.moveBy(dx - oldX, 0); } if (block.flyoutRect_) { block.flyoutRect_.setAttribute('width', blockHW.width); @@ -632,8 +633,13 @@ Blockly.Flyout.prototype.createBlockFunc_ = function(originBlock) { } var xyOld = Blockly.getSvgXY_(svgRootOld, workspace); // Scale the scroll (getSvgXY_ did not do this). - xyOld.x += flyout.workspace_.scrollX / flyout.workspace_.scale - - flyout.workspace_.scrollX; + if (flyout.RTL) { + var width = workspace.getMetrics().viewWidth - flyout.width_; + xyOld.x += width / workspace.scale - width; + } else { + xyOld.x += flyout.workspace_.scrollX / flyout.workspace_.scale - + flyout.workspace_.scrollX; + } xyOld.y += flyout.workspace_.scrollY / flyout.workspace_.scale - flyout.workspace_.scrollY; var svgRootNew = block.getSvgRoot(); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 867080910..53d319331 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -896,7 +896,6 @@ Blockly.WorkspaceSvg.prototype.zoom = function(x, y, type) { Blockly.hideChaff(false); if (this.flyout_) { // No toolbox, resize flyout. - this.flyout_.workspace_.scale = this.scale; this.flyout_.reflow(); } }; @@ -921,6 +920,11 @@ Blockly.WorkspaceSvg.prototype.zoomReset = function() { var metrics = this.getMetrics(); this.scrollbar.set((metrics.contentWidth - metrics.viewWidth) / 2, (metrics.contentHeight - metrics.viewHeight) / 2); + Blockly.hideChaff(false); + if (this.flyout_) { + // No toolbox, resize flyout. + this.flyout_.reflow(); + } }; /** From ea962664088d4013048b53ef40443860b9d91b9a Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 2 Sep 2015 15:15:28 -0700 Subject: [PATCH 25/98] Routine recompile. --- blockly_compressed.js | 45 +++++++++++++++++++++-------------------- blockly_uncompressed.js | 2 +- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index c6f57cb1a..73a91e511 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -952,25 +952,25 @@ Blockly.Scrollbar.prototype.onMouseMoveKnob_=function(a){this.svgKnob_.setAttrib Blockly.Scrollbar.prototype.onMouseUpKnob_=function(){Blockly.removeAllRanges();Blockly.hideChaff(!0);Blockly.Scrollbar.onMouseUpWrapper_&&(Blockly.unbindEvent_(Blockly.Scrollbar.onMouseUpWrapper_),Blockly.Scrollbar.onMouseUpWrapper_=null);Blockly.Scrollbar.onMouseMoveWrapper_&&(Blockly.unbindEvent_(Blockly.Scrollbar.onMouseMoveWrapper_),Blockly.Scrollbar.onMouseMoveWrapper_=null)}; Blockly.Scrollbar.prototype.constrainKnob_=function(a){if(0>=a||isNaN(a))a=0;else{var b=this.horizontal_?"width":"height",c=parseFloat(this.svgBackground_.getAttribute(b)),b=parseFloat(this.svgKnob_.getAttribute(b));a=Math.min(a,c-b)}return a}; Blockly.Scrollbar.prototype.onScroll_=function(){var a=parseFloat(this.svgKnob_.getAttribute(this.horizontal_?"x":"y")),b=parseFloat(this.svgBackground_.getAttribute(this.horizontal_?"width":"height")),a=a/b;isNaN(a)&&(a=0);b={};this.horizontal_?b.x=a:b.y=a;this.workspace_.setMetrics(b)};Blockly.Scrollbar.prototype.set=function(a){this.svgKnob_.setAttribute(this.horizontal_?"x":"y",a*this.ratio_);this.onScroll_()}; -Blockly.Scrollbar.insertAfter_=function(a,b){var c=b.nextSibling,d=b.parentNode;if(!d)throw"Reference node has no parent.";c?d.insertBefore(a,c):d.appendChild(a)};Blockly.Trashcan=function(a){this.workspace_=a};Blockly.Trashcan.prototype.WIDTH_=47;Blockly.Trashcan.prototype.BODY_HEIGHT_=45;Blockly.Trashcan.prototype.LID_HEIGHT_=15;Blockly.Trashcan.prototype.MARGIN_BOTTOM_=35;Blockly.Trashcan.prototype.MARGIN_SIDE_=35;Blockly.Trashcan.prototype.MARGIN_HOTSPOT_=25;Blockly.Trashcan.prototype.isOpen=!1;Blockly.Trashcan.prototype.svgGroup_=null;Blockly.Trashcan.prototype.svgLid_=null;Blockly.Trashcan.prototype.lidTask_=0;Blockly.Trashcan.prototype.lidOpen_=0; +Blockly.Scrollbar.insertAfter_=function(a,b){var c=b.nextSibling,d=b.parentNode;if(!d)throw"Reference node has no parent.";c?d.insertBefore(a,c):d.appendChild(a)};Blockly.Trashcan=function(a){this.workspace_=a};Blockly.Trashcan.prototype.WIDTH_=47;Blockly.Trashcan.prototype.BODY_HEIGHT_=45;Blockly.Trashcan.prototype.LID_HEIGHT_=15;Blockly.Trashcan.prototype.MARGIN_BOTTOM_=20;Blockly.Trashcan.prototype.MARGIN_SIDE_=20;Blockly.Trashcan.prototype.MARGIN_HOTSPOT_=25;Blockly.Trashcan.prototype.isOpen=!1;Blockly.Trashcan.prototype.svgGroup_=null;Blockly.Trashcan.prototype.svgLid_=null;Blockly.Trashcan.prototype.lidTask_=0;Blockly.Trashcan.prototype.lidOpen_=0; Blockly.Trashcan.prototype.left_=0;Blockly.Trashcan.prototype.top_=0; Blockly.Trashcan.prototype.createDom=function(){this.svgGroup_=Blockly.createSvgElement("g",{"class":"blocklyTrash"},null);var a=String(Math.random()).substring(2),b=Blockly.createSvgElement("clipPath",{id:"blocklyTrashBodyClipPath"+a},this.svgGroup_);Blockly.createSvgElement("rect",{width:this.WIDTH_,height:this.BODY_HEIGHT_,y:this.LID_HEIGHT_},b);Blockly.createSvgElement("image",{width:Blockly.SPRITE.width,height:Blockly.SPRITE.height,y:-32,"clip-path":"url(#blocklyTrashBodyClipPath"+a+")"},this.svgGroup_).setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href",this.workspace_.options.pathToMedia+Blockly.SPRITE.url);b=Blockly.createSvgElement("clipPath",{id:"blocklyTrashLidClipPath"+a},this.svgGroup_);Blockly.createSvgElement("rect",{width:this.WIDTH_,height:this.LID_HEIGHT_},b);this.svgLid_=Blockly.createSvgElement("image",{width:Blockly.SPRITE.width,height:Blockly.SPRITE.height,y:-32,"clip-path":"url(#blocklyTrashLidClipPath"+a+")"},this.svgGroup_);this.svgLid_.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.workspace_.options.pathToMedia+ -Blockly.SPRITE.url);this.animateLid_();return this.svgGroup_};Blockly.Trashcan.prototype.init=function(){this.setOpen_(!1)};Blockly.Trashcan.prototype.dispose=function(){this.svgGroup_&&(goog.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.workspace_=this.svgLid_=null;goog.Timer.clear(this.lidTask_)}; -Blockly.Trashcan.prototype.position=function(){var a=this.workspace_.getMetrics();a&&(this.left_=this.workspace_.RTL?this.MARGIN_SIDE_:a.viewWidth+a.absoluteLeft-this.WIDTH_-this.MARGIN_SIDE_,this.top_=a.viewHeight+a.absoluteTop-(this.BODY_HEIGHT_+this.LID_HEIGHT_)-this.MARGIN_BOTTOM_,this.svgGroup_.setAttribute("transform","translate("+this.left_+","+this.top_+")"))}; +Blockly.SPRITE.url);this.animateLid_();return this.svgGroup_};Blockly.Trashcan.prototype.init=function(a){this.bottom_=this.MARGIN_BOTTOM_+a;this.setOpen_(!1);return this.bottom_+this.BODY_HEIGHT_+this.LID_HEIGHT_};Blockly.Trashcan.prototype.dispose=function(){this.svgGroup_&&(goog.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.workspace_=this.svgLid_=null;goog.Timer.clear(this.lidTask_)}; +Blockly.Trashcan.prototype.position=function(){var a=this.workspace_.getMetrics();a&&(this.left_=this.workspace_.RTL?this.MARGIN_SIDE_+Blockly.Scrollbar.scrollbarThickness:a.viewWidth+a.absoluteLeft-this.WIDTH_-this.MARGIN_SIDE_-Blockly.Scrollbar.scrollbarThickness,this.top_=a.viewHeight+a.absoluteTop-(this.BODY_HEIGHT_+this.LID_HEIGHT_)-this.bottom_,this.svgGroup_.setAttribute("transform","translate("+this.left_+","+this.top_+")"))}; Blockly.Trashcan.prototype.getRect=function(){var a=Blockly.getSvgXY_(this.svgGroup_,this.workspace_);return new goog.math.Rect(a.x-this.MARGIN_HOTSPOT_,a.y-this.MARGIN_HOTSPOT_,this.WIDTH_+2*this.MARGIN_HOTSPOT_,this.BODY_HEIGHT_+this.LID_HEIGHT_+2*this.MARGIN_HOTSPOT_)};Blockly.Trashcan.prototype.setOpen_=function(a){this.isOpen!=a&&(goog.Timer.clear(this.lidTask_),this.isOpen=a,this.animateLid_())}; Blockly.Trashcan.prototype.animateLid_=function(){this.lidOpen_+=this.isOpen?.2:-.2;this.lidOpen_=goog.math.clamp(this.lidOpen_,0,1);var a=45*this.lidOpen_;this.svgLid_.setAttribute("transform","rotate("+(this.workspace_.RTL?-a:a)+","+(this.workspace_.RTL?4:this.WIDTH_-4)+","+(this.LID_HEIGHT_-2)+")");a=goog.math.lerp(.4,.8,this.lidOpen_);this.svgGroup_.style.opacity=a;0this.lidOpen_&&(this.lidTask_=goog.Timer.callOnce(this.animateLid_,20,this))}; Blockly.Trashcan.prototype.close=function(){this.setOpen_(!1)}; // Copyright 2015 Google Inc. Apache License 2.0 -Blockly.ZoomControls=function(a){this.workspace_=a};Blockly.ZoomControls.prototype.WIDTH_=32;Blockly.ZoomControls.prototype.HEIGHT_=110;Blockly.ZoomControls.prototype.MARGIN_BOTTOM_=100;Blockly.ZoomControls.prototype.MARGIN_SIDE_=35;Blockly.ZoomControls.prototype.svgGroup_=null;Blockly.ZoomControls.prototype.left_=0;Blockly.ZoomControls.prototype.top_=0; +Blockly.ZoomControls=function(a){this.workspace_=a};Blockly.ZoomControls.prototype.WIDTH_=32;Blockly.ZoomControls.prototype.HEIGHT_=110;Blockly.ZoomControls.prototype.MARGIN_BOTTOM_=20;Blockly.ZoomControls.prototype.MARGIN_SIDE_=20;Blockly.ZoomControls.prototype.svgGroup_=null;Blockly.ZoomControls.prototype.left_=0;Blockly.ZoomControls.prototype.top_=0; Blockly.ZoomControls.prototype.createDom=function(){var a=this.workspace_;this.svgGroup_=Blockly.createSvgElement("g",{"class":"blocklyZoom"},null);var b=String(Math.random()).substring(2),c=Blockly.createSvgElement("clipPath",{id:"blocklyZoomoutClipPath"+b},this.svgGroup_);Blockly.createSvgElement("rect",{width:32,height:32,y:77},c);var d=Blockly.createSvgElement("image",{width:Blockly.SPRITE.width,height:Blockly.SPRITE.height,x:-64,y:-15,"clip-path":"url(#blocklyZoomoutClipPath"+b+")"},this.svgGroup_); d.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",a.options.pathToMedia+Blockly.SPRITE.url);c=Blockly.createSvgElement("clipPath",{id:"blocklyZoominClipPath"+b},this.svgGroup_);Blockly.createSvgElement("rect",{width:32,height:32,y:43},c);var e=Blockly.createSvgElement("image",{width:Blockly.SPRITE.width,height:Blockly.SPRITE.height,x:-32,y:-49,"clip-path":"url(#blocklyZoominClipPath"+b+")"},this.svgGroup_);e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",a.options.pathToMedia+ Blockly.SPRITE.url);c=Blockly.createSvgElement("clipPath",{id:"blocklyZoomresetClipPath"+b},this.svgGroup_);Blockly.createSvgElement("rect",{width:32,height:32},c);b=Blockly.createSvgElement("image",{width:Blockly.SPRITE.width,height:Blockly.SPRITE.height,y:-92,"clip-path":"url(#blocklyZoomresetClipPath"+b+")"},this.svgGroup_);b.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",a.options.pathToMedia+Blockly.SPRITE.url);Blockly.bindEvent_(b,"mousedown",a,a.zoomReset);Blockly.bindEvent_(e, -"mousedown",null,function(){a.zoomCenter(1)});Blockly.bindEvent_(d,"mousedown",null,function(){a.zoomCenter(-1)});return this.svgGroup_};Blockly.ZoomControls.prototype.init=function(){};Blockly.ZoomControls.prototype.dispose=function(){this.svgGroup_&&(goog.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.workspace_=null}; -Blockly.ZoomControls.prototype.position=function(){var a=this.workspace_.getMetrics();a&&(this.left_=this.workspace_.RTL?this.MARGIN_SIDE_:a.viewWidth+a.absoluteLeft-this.WIDTH_-this.MARGIN_SIDE_,this.top_=a.viewHeight+a.absoluteTop-this.HEIGHT_-this.MARGIN_BOTTOM_,this.svgGroup_.setAttribute("transform","translate("+this.left_+","+this.top_+")"))};Blockly.Xml={};Blockly.Xml.workspaceToDom=function(a){var b;a.RTL&&(b=a.getWidth());for(var c=goog.dom.createDom("xml"),d=a.getTopBlocks(!0),e=0,f;f=d[e];e++){var g=Blockly.Xml.blockToDom_(f);f=f.getRelativeToSurfaceXY();g.setAttribute("x",Math.round(a.RTL?b-f.x:f.x));g.setAttribute("y",Math.round(f.y));c.appendChild(g)}return c}; -Blockly.Xml.blockToDom_=function(a){var b=goog.dom.createDom("block");b.setAttribute("type",a.type);b.setAttribute("id",a.id);if(a.mutationToDom){var c=a.mutationToDom();c&&(c.hasChildNodes()||c.hasAttributes())&&b.appendChild(c)}for(var c=0,d;d=a.inputList[c];c++)for(var e=0,f;f=d.fieldRow[e];e++)if(f.name&&f.EDITABLE){var g=goog.dom.createDom("field",null,f.getValue());g.setAttribute("name",f.name);b.appendChild(g)}if(c=a.getCommentText())c=goog.dom.createDom("comment",null,c),"object"==typeof a.comment&& -(c.setAttribute("pinned",a.comment.isVisible()),d=a.comment.getBubbleSize(),c.setAttribute("h",d.height),c.setAttribute("w",d.width)),b.appendChild(c);a.data&&(c=goog.dom.createDom("data",null,a.data),b.appendChild(c));for(c=0;d=a.inputList[c];c++){var h,e=!0;d.type!=Blockly.DUMMY_INPUT&&(f=d.connection.targetBlock(),d.type==Blockly.INPUT_VALUE?h=goog.dom.createDom("value"):d.type==Blockly.NEXT_STATEMENT&&(h=goog.dom.createDom("statement")),f&&(h.appendChild(Blockly.Xml.blockToDom_(f)),e=!1),h.setAttribute("name", -d.name),e||b.appendChild(h))}a.inputsInlineDefault!=a.inputsInline&&b.setAttribute("inline",a.inputsInline);a.isCollapsed()&&b.setAttribute("collapsed",!0);a.disabled&&b.setAttribute("disabled",!0);a.isDeletable()||b.setAttribute("deletable",!1);a.isMovable()||b.setAttribute("movable",!1);a.isEditable()||b.setAttribute("editable",!1);if(a=a.getNextBlock())h=goog.dom.createDom("next",null,Blockly.Xml.blockToDom_(a)),b.appendChild(h);return b};Blockly.Xml.domToText=function(a){return(new XMLSerializer).serializeToString(a)}; +"mousedown",null,function(){a.zoomCenter(1)});Blockly.bindEvent_(d,"mousedown",null,function(){a.zoomCenter(-1)});return this.svgGroup_};Blockly.ZoomControls.prototype.init=function(a){this.bottom_=this.MARGIN_BOTTOM_+a;return this.bottom_+this.HEIGHT_};Blockly.ZoomControls.prototype.dispose=function(){this.svgGroup_&&(goog.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.workspace_=null}; +Blockly.ZoomControls.prototype.position=function(){var a=this.workspace_.getMetrics();a&&(this.left_=this.workspace_.RTL?this.MARGIN_SIDE_+Blockly.Scrollbar.scrollbarThickness:a.viewWidth+a.absoluteLeft-this.WIDTH_-this.MARGIN_SIDE_-Blockly.Scrollbar.scrollbarThickness,this.top_=a.viewHeight+a.absoluteTop-this.HEIGHT_-this.bottom_,this.svgGroup_.setAttribute("transform","translate("+this.left_+","+this.top_+")"))};Blockly.Xml={};Blockly.Xml.workspaceToDom=function(a){var b;a.RTL&&(b=a.getWidth());for(var c=goog.dom.createDom("xml"),d=a.getTopBlocks(!0),e=0,f;f=d[e];e++){var g=Blockly.Xml.blockToDom_(f);f=f.getRelativeToSurfaceXY();g.setAttribute("x",Math.round(a.RTL?b-f.x:f.x));g.setAttribute("y",Math.round(f.y));c.appendChild(g)}return c}; +Blockly.Xml.blockToDom_=function(a){var b=goog.dom.createDom("block");b.setAttribute("type",a.type);Blockly.Realtime.isEnabled()&&b.setAttribute("id",a.id);if(a.mutationToDom){var c=a.mutationToDom();c&&(c.hasChildNodes()||c.hasAttributes())&&b.appendChild(c)}for(var c=0,d;d=a.inputList[c];c++)for(var e=0,f;f=d.fieldRow[e];e++)if(f.name&&f.EDITABLE){var g=goog.dom.createDom("field",null,f.getValue());g.setAttribute("name",f.name);b.appendChild(g)}if(c=a.getCommentText())c=goog.dom.createDom("comment", +null,c),"object"==typeof a.comment&&(c.setAttribute("pinned",a.comment.isVisible()),d=a.comment.getBubbleSize(),c.setAttribute("h",d.height),c.setAttribute("w",d.width)),b.appendChild(c);a.data&&(c=goog.dom.createDom("data",null,a.data),b.appendChild(c));for(c=0;d=a.inputList[c];c++){var h,e=!0;d.type!=Blockly.DUMMY_INPUT&&(f=d.connection.targetBlock(),d.type==Blockly.INPUT_VALUE?h=goog.dom.createDom("value"):d.type==Blockly.NEXT_STATEMENT&&(h=goog.dom.createDom("statement")),f&&(h.appendChild(Blockly.Xml.blockToDom_(f)), +e=!1),h.setAttribute("name",d.name),e||b.appendChild(h))}a.inputsInlineDefault!=a.inputsInline&&b.setAttribute("inline",a.inputsInline);a.isCollapsed()&&b.setAttribute("collapsed",!0);a.disabled&&b.setAttribute("disabled",!0);a.isDeletable()||b.setAttribute("deletable",!1);a.isMovable()||b.setAttribute("movable",!1);a.isEditable()||b.setAttribute("editable",!1);if(a=a.getNextBlock())h=goog.dom.createDom("next",null,Blockly.Xml.blockToDom_(a)),b.appendChild(h);return b};Blockly.Xml.domToText=function(a){return(new XMLSerializer).serializeToString(a)}; Blockly.Xml.domToPrettyText=function(a){a=Blockly.Xml.domToText(a).split("<");for(var b="",c=1;c"!=d.slice(-2)&&(b+=" ")}a=a.join("\n");a=a.replace(/(<(\w+)\b[^>]*>[^\n]*)\n *<\/\2>/g,"$1");return a.replace(/^\n/,"")}; Blockly.Xml.textToDom=function(a){a=(new DOMParser).parseFromString(a,"text/xml");if(!a||!a.firstChild||"xml"!=a.firstChild.nodeName.toLowerCase()||a.firstChild!==a.lastChild)throw"Blockly.Xml.textToDom did not obtain a valid XML tree.";return a.firstChild}; Blockly.Xml.domToWorkspace=function(a,b){var c;a.RTL&&(c=a.getWidth());for(var d=b.childNodes.length,e=0;ethis.options.zoomOptions.maxScale?c=this.options.zoomOptions.maxScale/this.scale:d=a.clientX&&0==a.clientY&&0==a.button)a.stopPropagation();else{Blockly.removeAllRanges();var b=a.clientX-Blockly.Flyout.startDownEvent_.clientX;a=a.clientY-Blockly.Flyout.startDownEvent_.clientY;Math.sqrt(b*b+a*a)>Blockly.DRAG_RADIUS&&Blockly.Flyout.startFlyout_.createBlockFunc_(Blockly.Flyout.startBlock_)(Blockly.Flyout.startDownEvent_)}}; -Blockly.Flyout.prototype.createBlockFunc_=function(a){var b=this,c=this.targetWorkspace_;return function(d){if(!Blockly.isRightButton(d)&&!a.disabled){var e=Blockly.Xml.blockToDom_(a),e=Blockly.Xml.domToBlock(c,e),f=a.getSvgRoot();if(!f)throw"originBlock is not rendered.";var f=Blockly.getSvgXY_(f,c),g=e.getSvgRoot();if(!g)throw"block is not rendered.";if(1==c.scale){var h=Blockly.getSvgXY_(g,c);e.moveBy(f.x-h.x,f.y-h.y)}else{var k=Blockly.mouseToSvg(d,c.options.svg),h=k.x-f.x,k=k.y-f.y;f.x/=c.scale; -f.y/=c.scale;var l=Blockly.getRelativeXY_(c.getCanvas()),g=Blockly.getRelativeXY_(g);e.moveBy(f.x-(l.x/c.scale+g.x)-(h-h/c.scale),f.y-(l.y/c.scale+g.y)-(k-k/c.scale))}b.autoClose?b.hide():b.filterForCapacity_();e.onMouseDown_(d)}}};Blockly.Flyout.prototype.filterForCapacity_=function(){for(var a=this.targetWorkspace_.remainingCapacity(),b=this.workspace_.getTopBlocks(!1),c=0,d;d=b[c];c++){var e=d.getDescendants().length>a;d.setDisabled(e)}}; +Blockly.Flyout.prototype.createBlockFunc_=function(a){var b=this,c=this.targetWorkspace_;return function(d){if(!Blockly.isRightButton(d)&&!a.disabled){var e=Blockly.Xml.blockToDom_(a),e=Blockly.Xml.domToBlock(c,e),f=a.getSvgRoot();if(!f)throw"originBlock is not rendered.";f=Blockly.getSvgXY_(f,c);if(b.RTL){var g=c.getMetrics().viewWidth-b.width_;f.x+=g/c.scale-g}else f.x+=b.workspace_.scrollX/b.workspace_.scale-b.workspace_.scrollX;f.y+=b.workspace_.scrollY/b.workspace_.scale-b.workspace_.scrollY; +g=e.getSvgRoot();if(!g)throw"block is not rendered.";g=Blockly.getSvgXY_(g,c);g.x+=c.scrollX/c.scale-c.scrollX;g.y+=c.scrollY/c.scale-c.scrollY;e.moveBy(f.x-g.x,f.y-g.y);b.autoClose?b.hide():b.filterForCapacity_();e.onMouseDown_(d)}}};Blockly.Flyout.prototype.filterForCapacity_=function(){for(var a=this.targetWorkspace_.remainingCapacity(),b=this.workspace_.getTopBlocks(!1),c=0,d;d=b[c];c++){var e=d.getDescendants().length>a;d.setDisabled(e)}}; Blockly.Flyout.prototype.getRect=function(){var a=Blockly.mainWorkspace,b=Blockly.getSvgXY_(this.svgGroup_,a).x;this.RTL||(b-=1E9);return new goog.math.Rect(b,-1E9,1E9+this.width_*(this.targetWorkspace_==a?1:a.scale),2E9)}; Blockly.Flyout.terminateDrag_=function(){Blockly.Flyout.onMouseUpWrapper_&&(Blockly.unbindEvent_(Blockly.Flyout.onMouseUpWrapper_),Blockly.Flyout.onMouseUpWrapper_=null);Blockly.Flyout.onMouseMoveBlockWrapper_&&(Blockly.unbindEvent_(Blockly.Flyout.onMouseMoveBlockWrapper_),Blockly.Flyout.onMouseMoveBlockWrapper_=null);Blockly.Flyout.onMouseMoveWrapper_&&(Blockly.unbindEvent_(Blockly.Flyout.onMouseMoveWrapper_),Blockly.Flyout.onMouseMoveWrapper_=null);Blockly.Flyout.onMouseUpWrapper_&&(Blockly.unbindEvent_(Blockly.Flyout.onMouseUpWrapper_), Blockly.Flyout.onMouseUpWrapper_=null);Blockly.Flyout.startDownEvent_=null;Blockly.Flyout.startBlock_=null;Blockly.Flyout.startFlyout_=null};Blockly.Toolbox=function(a){this.workspace_=a};Blockly.Toolbox.prototype.width=0;Blockly.Toolbox.prototype.selectedOption_=null;Blockly.Toolbox.prototype.lastCategory_=null;Blockly.Toolbox.prototype.CONFIG_={indentWidth:19,cssRoot:"blocklyTreeRoot",cssHideRoot:"blocklyHidden",cssItem:"",cssTreeRow:"blocklyTreeRow",cssItemLabel:"blocklyTreeLabel",cssTreeIcon:"blocklyTreeIcon",cssExpandedFolderIcon:"blocklyTreeIconOpen",cssFileIcon:"blocklyTreeIconNone",cssSelectedRow:"blocklyTreeSelected"}; @@ -1305,8 +1306,8 @@ Blockly.bindEvent_.TOUCH_MAP={};goog.events.BrowserFeature.TOUCH_ENABLED&&(Block Blockly.fireUiEventNow=function(a,b){var c=Blockly.fireUiEvent.DB_[b];if(c){var d=c.indexOf(a);-1!=d&&c.splice(d,1)}if(document.createEvent)c=document.createEvent("UIEvents"),c.initEvent(b,!0,!0),a.dispatchEvent(c);else if(document.createEventObject)c=document.createEventObject(),a.fireEvent("on"+b,c);else throw"FireEvent: No event creation mechanism.";}; Blockly.fireUiEvent=function(a,b){var c=Blockly.fireUiEvent.DB_[b];if(c){if(-1!=c.indexOf(a))return;c.push(a)}else Blockly.fireUiEvent.DB_[b]=[a];setTimeout(function(){Blockly.fireUiEventNow(a,b)},0)};Blockly.fireUiEvent.DB_={};Blockly.noEvent=function(a){a.preventDefault();a.stopPropagation()}; Blockly.isTargetInput_=function(a){return"textarea"==a.target.type||"text"==a.target.type||"number"==a.target.type||"email"==a.target.type||"password"==a.target.type||"search"==a.target.type||"tel"==a.target.type||"url"==a.target.type||a.target.isContentEditable}; -Blockly.getRelativeXY_=function(a){var b={x:0,y:0},c=a.getAttribute("x");c&&(b.x=parseInt(c,10));if(c=a.getAttribute("y"))b.y=parseInt(c,10);if(a=(a=a.getAttribute("transform"))&&a.match(Blockly.getRelativeXY_.XY_REGEXP_))b.x+=parseFloat(a[1]),a[3]&&(b.y+=parseFloat(a[3]));return b};Blockly.getRelativeXY_.XY_REGEXP_=/translate\(\s*([-+\d.e]+)([ ,]\s*([-+\d.e]+)\s*\))?/; -Blockly.getSvgXY_=function(a,b){var c=0,d=0,e=!goog.dom.contains(b.getCanvas(),a)&&!goog.dom.contains(b.getBubbleCanvas(),a);do{var f=Blockly.getRelativeXY_(a);if(a==b.getCanvas()||a==b.getBubbleCanvas())e=!0;e?(c+=f.x,d+=f.y):(c+=f.x*b.scale,d+=f.y*b.scale);a=a.parentNode}while(a&&a!=b.options.svg);return{x:c,y:d}}; +Blockly.getRelativeXY_=function(a){var b=new goog.math.Coordinate(0,0),c=a.getAttribute("x");c&&(b.x=parseInt(c,10));if(c=a.getAttribute("y"))b.y=parseInt(c,10);if(a=(a=a.getAttribute("transform"))&&a.match(Blockly.getRelativeXY_.XY_REGEXP_))b.x+=parseFloat(a[1]),a[3]&&(b.y+=parseFloat(a[3]));return b};Blockly.getRelativeXY_.XY_REGEXP_=/translate\(\s*([-+\d.e]+)([ ,]\s*([-+\d.e]+)\s*\))?/; +Blockly.getSvgXY_=function(a,b){var c=0,d=0,e=1;if(goog.dom.contains(b.getCanvas(),a)||goog.dom.contains(b.getBubbleCanvas(),a))e=b.scale;do{var f=Blockly.getRelativeXY_(a);if(a==b.getCanvas()||a==b.getBubbleCanvas())e=1;c+=f.x*e;d+=f.y*e;a=a.parentNode}while(a&&a!=b.options.svg);return new goog.math.Coordinate(c,d)}; Blockly.createSvgElement=function(a,b,c,d){a=document.createElementNS(Blockly.SVG_NS,a);for(var e in b)a.setAttribute(e,b[e]);document.body.runtimeStyle&&(a.runtimeStyle=a.currentStyle=a.style);c&&c.appendChild(a);return a};Blockly.removeAllRanges=function(){window.getSelection&&setTimeout(function(){try{var a=window.getSelection();a.isCollapsed||a.removeAllRanges()}catch(b){}},0)};Blockly.isRightButton=function(a){return a.ctrlKey&&goog.userAgent.MAC?!0:2==a.button}; Blockly.mouseToSvg=function(a,b){var c=b.createSVGPoint();c.x=a.clientX;c.y=a.clientY;var d=b.getScreenCTM(),d=d.inverse();return c.matrixTransform(d)};Blockly.shortestStringLength=function(a){if(!a.length)return 0;for(var b=a[0].length,c=1;c Date: Thu, 3 Sep 2015 08:21:31 -0700 Subject: [PATCH 26/98] Make XML parser less fragile. This allows fields and inputs to be deprecated. --- blockly_compressed.js | 83 ++++++++++++++++++++--------------------- blockly_uncompressed.js | 10 +++-- core/xml.js | 14 +++++-- 3 files changed, 58 insertions(+), 49 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 73a91e511..ebccb9b76 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -5,24 +5,22 @@ var COMPILED=!0,goog=goog||{};goog.global=this;goog.isDef=function(a){return voi goog.define=function(a,b){var c=b;COMPILED||(goog.global.CLOSURE_UNCOMPILED_DEFINES&&Object.prototype.hasOwnProperty.call(goog.global.CLOSURE_UNCOMPILED_DEFINES,a)?c=goog.global.CLOSURE_UNCOMPILED_DEFINES[a]:goog.global.CLOSURE_DEFINES&&Object.prototype.hasOwnProperty.call(goog.global.CLOSURE_DEFINES,a)&&(c=goog.global.CLOSURE_DEFINES[a]));goog.exportPath_(a,c)};goog.DEBUG=!0;goog.LOCALE="en";goog.TRUSTED_SITE=!0;goog.STRICT_MODE_COMPATIBLE=!1;goog.DISALLOW_TEST_ONLY_CODE=COMPILED&&!goog.DEBUG; goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING=!1;goog.provide=function(a){if(!COMPILED&&goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');goog.constructNamespace_(a)};goog.constructNamespace_=function(a,b){if(!COMPILED){delete goog.implicitNamespaces_[a];for(var c=a;(c=c.substring(0,c.lastIndexOf(".")))&&!goog.getObjectByName(c);)goog.implicitNamespaces_[c]=!0}goog.exportPath_(a,b)};goog.VALID_MODULE_RE_=/^[a-zA-Z_$][a-zA-Z0-9._$]*$/; goog.module=function(a){if(!goog.isString(a)||!a||-1==a.search(goog.VALID_MODULE_RE_))throw Error("Invalid module identifier");if(!goog.isInModuleLoader_())throw Error("Module "+a+" has been loaded incorrectly.");if(goog.moduleLoaderState_.moduleName)throw Error("goog.module may only be called once per module.");goog.moduleLoaderState_.moduleName=a;if(!COMPILED){if(goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');delete goog.implicitNamespaces_[a]}};goog.module.get=function(a){return goog.module.getInternal_(a)}; -goog.module.getInternal_=function(a){if(!COMPILED)return goog.isProvided_(a)?a in goog.loadedModules_?goog.loadedModules_[a]:goog.getObjectByName(a):null};goog.moduleLoaderState_=null;goog.isInModuleLoader_=function(){return null!=goog.moduleLoaderState_};goog.module.declareTestMethods=function(){if(!goog.isInModuleLoader_())throw Error("goog.module.declareTestMethods must be called from within a goog.module");goog.moduleLoaderState_.declareTestMethods=!0}; +goog.module.getInternal_=function(a){if(!COMPILED)return goog.isProvided_(a)?a in goog.loadedModules_?goog.loadedModules_[a]:goog.getObjectByName(a):null};goog.moduleLoaderState_=null;goog.isInModuleLoader_=function(){return null!=goog.moduleLoaderState_}; goog.module.declareLegacyNamespace=function(){if(!COMPILED&&!goog.isInModuleLoader_())throw Error("goog.module.declareLegacyNamespace must be called from within a goog.module");if(!COMPILED&&!goog.moduleLoaderState_.moduleName)throw Error("goog.module must be called prior to goog.module.declareLegacyNamespace.");goog.moduleLoaderState_.declareLegacyNamespace=!0}; goog.setTestOnly=function(a){if(goog.DISALLOW_TEST_ONLY_CODE)throw a=a||"",Error("Importing test-only code into non-debug environment"+(a?": "+a:"."));};goog.forwardDeclare=function(a){};COMPILED||(goog.isProvided_=function(a){return a in goog.loadedModules_||!goog.implicitNamespaces_[a]&&goog.isDefAndNotNull(goog.getObjectByName(a))},goog.implicitNamespaces_={"goog.module":!0}); goog.getObjectByName=function(a,b){for(var c=a.split("."),d=b||goog.global,e;e=c.shift();)if(goog.isDefAndNotNull(d[e]))d=d[e];else return null;return d};goog.globalize=function(a,b){var c=b||goog.global,d;for(d in a)c[d]=a[d]};goog.addDependency=function(a,b,c,d){if(goog.DEPENDENCIES_ENABLED){var e;a=a.replace(/\\/g,"/");for(var f=goog.dependencies_,g=0;e=b[g];g++)f.nameToPath[e]=a,f.pathIsModule[a]=!!d;for(d=0;b=c[d];d++)a in f.requires||(f.requires[a]={}),f.requires[a][b]=!0}}; -goog.ENABLE_DEBUG_LOADER=!0;goog.logToConsole_=function(a){goog.global.console&&goog.global.console.error(a)}; -goog.require=function(a){if(!COMPILED){goog.ENABLE_DEBUG_LOADER&&goog.IS_OLD_IE_&&goog.maybeProcessDeferredDep_(a);if(goog.isProvided_(a))return goog.isInModuleLoader_()?goog.module.getInternal_(a):null;if(goog.ENABLE_DEBUG_LOADER){var b=goog.getPathFromDeps_(a);if(b)return goog.included_[b]=!0,goog.writeScripts_(),null}a="goog.require could not find: "+a;goog.logToConsole_(a);throw Error(a);}};goog.basePath="";goog.nullFunction=function(){}; -goog.abstractMethod=function(){throw Error("unimplemented abstract method");};goog.addSingletonGetter=function(a){a.getInstance=function(){if(a.instance_)return a.instance_;goog.DEBUG&&(goog.instantiatedSingletons_[goog.instantiatedSingletons_.length]=a);return a.instance_=new a}};goog.instantiatedSingletons_=[];goog.LOAD_MODULE_USING_EVAL=!0;goog.SEAL_MODULE_EXPORTS=goog.DEBUG;goog.loadedModules_={};goog.DEPENDENCIES_ENABLED=!COMPILED&&goog.ENABLE_DEBUG_LOADER; -goog.DEPENDENCIES_ENABLED&&(goog.included_={},goog.dependencies_={pathIsModule:{},nameToPath:{},requires:{},visited:{},written:{},deferred:{}},goog.inHtmlDocument_=function(){var a=goog.global.document;return"undefined"!=typeof a&&"write"in a},goog.findBasePath_=function(){if(goog.global.CLOSURE_BASE_PATH)goog.basePath=goog.global.CLOSURE_BASE_PATH;else if(goog.inHtmlDocument_())for(var a=goog.global.document.getElementsByTagName("SCRIPT"),b=a.length-1;0<=b;--b){var c=a[b].src,d=c.lastIndexOf("?"), -d=-1==d?c.length:d;if("base.js"==c.substr(d-7,7)){goog.basePath=c.substr(0,d-7);break}}},goog.importScript_=function(a,b){(goog.global.CLOSURE_IMPORT_SCRIPT||goog.writeScriptTag_)(a,b)&&(goog.dependencies_.written[a]=!0)},goog.IS_OLD_IE_=!(goog.global.atob||!goog.global.document||!goog.global.document.all),goog.importModule_=function(a){goog.importScript_("",'goog.retrieveAndExecModule_("'+a+'");')&&(goog.dependencies_.written[a]=!0)},goog.queuedModules_=[],goog.wrapModule_=function(a,b){return goog.LOAD_MODULE_USING_EVAL&& +goog.ENABLE_DEBUG_LOADER=!0;goog.logToConsole_=function(a){goog.global.console&&goog.global.console.error(a)};goog.require=function(a){if(!COMPILED){goog.ENABLE_DEBUG_LOADER&&goog.IS_OLD_IE_&&goog.maybeProcessDeferredDep_(a);if(goog.isProvided_(a))return goog.isInModuleLoader_()?goog.module.getInternal_(a):null;if(goog.ENABLE_DEBUG_LOADER){var b=goog.getPathFromDeps_(a);if(b)return goog.writeScripts_(b),null}a="goog.require could not find: "+a;goog.logToConsole_(a);throw Error(a);}}; +goog.basePath="";goog.nullFunction=function(){};goog.abstractMethod=function(){throw Error("unimplemented abstract method");};goog.addSingletonGetter=function(a){a.getInstance=function(){if(a.instance_)return a.instance_;goog.DEBUG&&(goog.instantiatedSingletons_[goog.instantiatedSingletons_.length]=a);return a.instance_=new a}};goog.instantiatedSingletons_=[];goog.LOAD_MODULE_USING_EVAL=!0;goog.SEAL_MODULE_EXPORTS=goog.DEBUG;goog.loadedModules_={};goog.DEPENDENCIES_ENABLED=!COMPILED&&goog.ENABLE_DEBUG_LOADER; +goog.DEPENDENCIES_ENABLED&&(goog.dependencies_={pathIsModule:{},nameToPath:{},requires:{},visited:{},written:{},deferred:{}},goog.inHtmlDocument_=function(){var a=goog.global.document;return"undefined"!=typeof a&&"write"in a},goog.findBasePath_=function(){if(goog.isDef(goog.global.CLOSURE_BASE_PATH))goog.basePath=goog.global.CLOSURE_BASE_PATH;else if(goog.inHtmlDocument_())for(var a=goog.global.document.getElementsByTagName("SCRIPT"),b=a.length-1;0<=b;--b){var c=a[b].src,d=c.lastIndexOf("?"),d=-1== +d?c.length:d;if("base.js"==c.substr(d-7,7)){goog.basePath=c.substr(0,d-7);break}}},goog.importScript_=function(a,b){(goog.global.CLOSURE_IMPORT_SCRIPT||goog.writeScriptTag_)(a,b)&&(goog.dependencies_.written[a]=!0)},goog.IS_OLD_IE_=!(goog.global.atob||!goog.global.document||!goog.global.document.all),goog.importModule_=function(a){goog.importScript_("",'goog.retrieveAndExecModule_("'+a+'");')&&(goog.dependencies_.written[a]=!0)},goog.queuedModules_=[],goog.wrapModule_=function(a,b){return goog.LOAD_MODULE_USING_EVAL&& goog.isDef(goog.global.JSON)?"goog.loadModule("+goog.global.JSON.stringify(b+"\n//# sourceURL="+a+"\n")+");":'goog.loadModule(function(exports) {"use strict";'+b+"\n;return exports});\n//# sourceURL="+a+"\n"},goog.loadQueuedModules_=function(){var a=goog.queuedModules_.length;if(0\x3c/script>')},goog.appendScriptSrcNode_= -function(a){var b=goog.global.document,c=b.createElement("script");c.type="text/javascript";c.src=a;c.defer=!1;c.async=!1;b.head.appendChild(c)},goog.writeScriptTag_=function(a,b){if(goog.inHtmlDocument_()){var c=goog.global.document;if(!goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING&&"complete"==c.readyState){if(/\bdeps.js$/.test(a))return!1;throw Error('Cannot write "'+a+'" after document load');}var d=goog.IS_OLD_IE_;void 0===b?d?(d=" onreadystatechange='goog.onScriptLoad_(this, "+ ++goog.lastNonModuleScriptIndex_+ -")' ",c.write(' From abd8833dbc2fa4fe93c5955b5230556596be16b3 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Fri, 25 Sep 2015 16:05:59 +0200 Subject: [PATCH 55/98] Localisation updates from https://translatewiki.net. --- msg/json/pl.json | 9 ++++++++- msg/json/sc.json | 35 ++++++++++++++++++----------------- msg/json/sk.json | 5 +++-- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/msg/json/pl.json b/msg/json/pl.json index 85fec64f8..50f451503 100644 --- a/msg/json/pl.json +++ b/msg/json/pl.json @@ -6,10 +6,12 @@ "Vengir", "Pbz", "Pio387", - "아라" + "아라", + "Mateon1" ] }, "VARIABLES_DEFAULT_NAME": "element", + "TODAY": "Dzisiaj", "DUPLICATE_BLOCK": "Powiel", "ADD_COMMENT": "Dodaj komentarz", "REMOVE_COMMENT": "Usuń Komentarz", @@ -294,6 +296,11 @@ "LISTS_GET_SUBLIST_END_LAST": "do ostatniego", "LISTS_GET_SUBLIST_TAIL": "", "LISTS_GET_SUBLIST_TOOLTIP": "Tworzy kopię z określoną część listy.", + "LISTS_SPLIT_LIST_FROM_TEXT": "stwórz listę z tekstu", + "LISTS_SPLIT_TEXT_FROM_LIST": "stwórz tekst z listy", + "LISTS_SPLIT_WITH_DELIMITER": "z separatorem", + "LISTS_SPLIT_TOOLTIP_SPLIT": "Rozdziela tekst na listę mniejszych tekstów, dzieląc na każdym separatorze.", + "LISTS_SPLIT_TOOLTIP_JOIN": "Łączy listę tekstów w jeden tekst, rozdzielany separatorem.", "ORDINAL_NUMBER_SUFFIX": "", "VARIABLES_GET_TOOLTIP": "Zwraca wartość tej zmiennej.", "VARIABLES_GET_CREATE_SET": "Utwórz blok 'ustaw %1'", diff --git a/msg/json/sc.json b/msg/json/sc.json index b709356e2..596788640 100644 --- a/msg/json/sc.json +++ b/msg/json/sc.json @@ -2,28 +2,29 @@ "@metadata": { "authors": [ "Via maxima", - "Taxandru" + "Taxandru", + "Uharteko" ] }, "VARIABLES_DEFAULT_NAME": "item", - "TODAY": "Oi", - "DUPLICATE_BLOCK": "Dòpia", - "ADD_COMMENT": "Aciungi unu cumentu", + "TODAY": "Oe", + "DUPLICATE_BLOCK": "Dùplica", + "ADD_COMMENT": "Agiunghe unu cumentu", "REMOVE_COMMENT": "Fùlia unu cumentu", - "EXTERNAL_INPUTS": "Inputs esternus", - "INLINE_INPUTS": "Inputs in lìnia", - "DELETE_BLOCK": "Fulia Brocu", - "DELETE_X_BLOCKS": "Fulia %1 Brocus", - "COLLAPSE_BLOCK": "Serra e stringi Brocu", - "COLLAPSE_ALL": "Serra e stringi Brocus", - "EXPAND_BLOCK": "Aberi Brocu", - "EXPAND_ALL": "Aberi Brocus", - "DISABLE_BLOCK": "Disabìlita Brocu", - "ENABLE_BLOCK": "Abìlita Brocu", + "EXTERNAL_INPUTS": "Intradas esternas", + "INLINE_INPUTS": "Intradas in lìnia", + "DELETE_BLOCK": "Fùlia Blocu", + "DELETE_X_BLOCKS": "Fulia %1 Blocus", + "COLLAPSE_BLOCK": "Serra e astringhe Blocu", + "COLLAPSE_ALL": "Serra e astringhe Boocos", + "EXPAND_BLOCK": "Aberi Blocu", + "EXPAND_ALL": "Aberi Brocos", + "DISABLE_BLOCK": "Disabìlita Blocu", + "ENABLE_BLOCK": "Abìlita Blocu", "HELP": "Agiudu", - "CHAT": "Fuedda cun su cumpàngiu tuu scriendi innoi!", - "AUTH": "Permiti a custa app de sarvai su traballu tuu e de ti ddu fàiri cundividi.", - "ME": "Deu", + "CHAT": "Faedda cun su cumpàngiu tuo iscriende inoghe!", + "AUTH": "Permiti a custa app de sarvare su traballu tuo e de ti lu fàghere cumpartzire.", + "ME": "Deo", "CHANGE_VALUE_TITLE": "Muda valori:", "NEW_VARIABLE": "Variabili noa...", "NEW_VARIABLE_TITLE": "Nòmini de sa variabili noa:", diff --git a/msg/json/sk.json b/msg/json/sk.json index 6442ee099..5be412a6b 100644 --- a/msg/json/sk.json +++ b/msg/json/sk.json @@ -2,7 +2,8 @@ "@metadata": { "authors": [ "Jaroslav.micek", - "Marian.stano" + "Marian.stano", + "Mark" ] }, "VARIABLES_DEFAULT_NAME": "prvok", @@ -51,7 +52,7 @@ "CONTROLS_WHILEUNTIL_OPERATOR_UNTIL": "opakuj kým nebude", "CONTROLS_WHILEUNTIL_TOOLTIP_WHILE": "Kým je hodnota pravdivá, vykonávaj príkazy.", "CONTROLS_WHILEUNTIL_TOOLTIP_UNTIL": "Kým je hodnota nepravdivá, vykonávaj príkazy.", - "CONTROLS_FOR_TOOLTIP": "Nechá premennú \"%1\" nadobúdať hodnoty od začiatočného čísla po konečné s daným medzikrokom a vykoná zadané bloky.", + "CONTROLS_FOR_TOOLTIP": "Nechá premennú '%1' nadobúdať hodnoty od začiatočného čísla po konečné s daným medzikrokom a vykoná zadané bloky.", "CONTROLS_FOR_TITLE": "počítať s %1 od %2 do %3 o %4", "CONTROLS_FOREACH_TITLE": "pre každý prvok %1 v zozname %2", "CONTROLS_FOREACH_TOOLTIP": "Pre každý prvok v zozname priraď jeho hodnotu do premenej '%1' a vykonaj príkazy.", From 8ecfab014f4488fc707c41bf87f8b85b1cbdb9bf Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Mon, 28 Sep 2015 12:17:54 -0700 Subject: [PATCH 56/98] Separate overlapping emboss filter and disabled pattern across multiple Blockly instances. Issue 184. --- blockly_compressed.js | 17 +++++++++-------- blockly_uncompressed.js | 2 +- core/block_svg.js | 3 ++- core/blocks.js | 2 +- core/bubble.js | 8 ++++++-- core/inject.js | 34 +++++++++++++++------------------- core/workspace_svg.js | 2 +- 7 files changed, 35 insertions(+), 33 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 2937a552a..bb8ae09dd 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -857,8 +857,9 @@ Blockly.Workspace.prototype.getWidth=function(){return 0};Blockly.Workspace.prot "mousedown",this,this.bubbleMouseDown_),this.resizeGroup_&&Blockly.bindEvent_(this.resizeGroup_,"mousedown",this,this.resizeMouseDown_))};Blockly.Bubble.BORDER_WIDTH=6;Blockly.Bubble.ARROW_THICKNESS=10;Blockly.Bubble.ARROW_ANGLE=20;Blockly.Bubble.ARROW_BEND=4;Blockly.Bubble.ANCHOR_RADIUS=8;Blockly.Bubble.onMouseUpWrapper_=null;Blockly.Bubble.onMouseMoveWrapper_=null; Blockly.Bubble.unbindDragEvents_=function(){Blockly.Bubble.onMouseUpWrapper_&&(Blockly.unbindEvent_(Blockly.Bubble.onMouseUpWrapper_),Blockly.Bubble.onMouseUpWrapper_=null);Blockly.Bubble.onMouseMoveWrapper_&&(Blockly.unbindEvent_(Blockly.Bubble.onMouseMoveWrapper_),Blockly.Bubble.onMouseMoveWrapper_=null)};Blockly.Bubble.prototype.rendered_=!1;Blockly.Bubble.prototype.anchorX_=0;Blockly.Bubble.prototype.anchorY_=0;Blockly.Bubble.prototype.relativeLeft_=0;Blockly.Bubble.prototype.relativeTop_=0; Blockly.Bubble.prototype.width_=0;Blockly.Bubble.prototype.height_=0;Blockly.Bubble.prototype.autoLayout_=!0; -Blockly.Bubble.prototype.createDom_=function(a,b){this.bubbleGroup_=Blockly.createSvgElement("g",{},null);var c={filter:"url(#blocklyEmboss)"};-1!=goog.userAgent.getUserAgentString().indexOf("JavaFX")&&(c={});c=Blockly.createSvgElement("g",c,this.bubbleGroup_);this.bubbleArrow_=Blockly.createSvgElement("path",{},c);this.bubbleBack_=Blockly.createSvgElement("rect",{"class":"blocklyDraggable",x:0,y:0,rx:Blockly.Bubble.BORDER_WIDTH,ry:Blockly.Bubble.BORDER_WIDTH},c);b?(this.resizeGroup_=Blockly.createSvgElement("g", -{"class":this.workspace_.RTL?"blocklyResizeSW":"blocklyResizeSE"},this.bubbleGroup_),c=2*Blockly.Bubble.BORDER_WIDTH,Blockly.createSvgElement("polygon",{points:"0,x x,x x,0".replace(/x/g,c.toString())},this.resizeGroup_),Blockly.createSvgElement("line",{"class":"blocklyResizeLine",x1:c/3,y1:c-1,x2:c-1,y2:c/3},this.resizeGroup_),Blockly.createSvgElement("line",{"class":"blocklyResizeLine",x1:2*c/3,y1:c-1,x2:c-1,y2:2*c/3},this.resizeGroup_)):this.resizeGroup_=null;this.bubbleGroup_.appendChild(a);return this.bubbleGroup_}; +Blockly.Bubble.prototype.createDom_=function(a,b){this.bubbleGroup_=Blockly.createSvgElement("g",{},null);var c={filter:"url(#"+this.workspace_.options.embossFilterId+")"};-1!=goog.userAgent.getUserAgentString().indexOf("JavaFX")&&(c={});c=Blockly.createSvgElement("g",c,this.bubbleGroup_);this.bubbleArrow_=Blockly.createSvgElement("path",{},c);this.bubbleBack_=Blockly.createSvgElement("rect",{"class":"blocklyDraggable",x:0,y:0,rx:Blockly.Bubble.BORDER_WIDTH,ry:Blockly.Bubble.BORDER_WIDTH},c);b?(this.resizeGroup_= +Blockly.createSvgElement("g",{"class":this.workspace_.RTL?"blocklyResizeSW":"blocklyResizeSE"},this.bubbleGroup_),c=2*Blockly.Bubble.BORDER_WIDTH,Blockly.createSvgElement("polygon",{points:"0,x x,x x,0".replace(/x/g,c.toString())},this.resizeGroup_),Blockly.createSvgElement("line",{"class":"blocklyResizeLine",x1:c/3,y1:c-1,x2:c-1,y2:c/3},this.resizeGroup_),Blockly.createSvgElement("line",{"class":"blocklyResizeLine",x1:2*c/3,y1:c-1,x2:c-1,y2:2*c/3},this.resizeGroup_)):this.resizeGroup_=null;this.bubbleGroup_.appendChild(a); +return this.bubbleGroup_}; Blockly.Bubble.prototype.bubbleMouseDown_=function(a){this.promote_();Blockly.Bubble.unbindDragEvents_();Blockly.isRightButton(a)?a.stopPropagation():Blockly.isTargetInput_(a)||(Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED),this.workspace_.startDrag(a,this.workspace_.RTL?-this.relativeLeft_:this.relativeLeft_,this.relativeTop_),Blockly.Bubble.onMouseUpWrapper_=Blockly.bindEvent_(document,"mouseup",this,Blockly.Bubble.unbindDragEvents_),Blockly.Bubble.onMouseMoveWrapper_=Blockly.bindEvent_(document, "mousemove",this,this.bubbleMouseMove_),Blockly.hideChaff(),a.stopPropagation())};Blockly.Bubble.prototype.bubbleMouseMove_=function(a){this.autoLayout_=!1;a=this.workspace_.moveDrag(a);this.relativeLeft_=this.workspace_.RTL?-a.x:a.x;this.relativeTop_=a.y;this.positionBubble_();this.renderArrow_()}; Blockly.Bubble.prototype.resizeMouseDown_=function(a){this.promote_();Blockly.Bubble.unbindDragEvents_();Blockly.isRightButton(a)||(Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED),this.workspace_.startDrag(a,this.workspace_.RTL?-this.width_:this.width_,this.height_),Blockly.Bubble.onMouseUpWrapper_=Blockly.bindEvent_(document,"mouseup",this,Blockly.Bubble.unbindDragEvents_),Blockly.Bubble.onMouseMoveWrapper_=Blockly.bindEvent_(document,"mousemove",this,this.resizeMouseMove_),Blockly.hideChaff()); @@ -871,7 +872,7 @@ Blockly.Bubble.prototype.setBubbleSize=function(a,b){var c=2*Blockly.Bubble.BORD this.layoutBubble_(),this.positionBubble_(),this.renderArrow_());Blockly.fireUiEvent(this.bubbleGroup_,"resize")}; Blockly.Bubble.prototype.renderArrow_=function(){var a=[],b=this.width_/2,c=this.height_/2,d=-this.relativeLeft_,e=-this.relativeTop_;if(b==d&&c==e)a.push("M "+b+","+c);else{e-=c;d-=b;this.workspace_.RTL&&(d*=-1);var f=Math.sqrt(e*e+d*d),g=Math.acos(d/f);0>e&&(g=2*Math.PI-g);var h=g+Math.PI/2;h>2*Math.PI&&(h-=2*Math.PI);var k=Math.sin(h),l=Math.cos(h),q=this.getBubbleSize(),h=(q.width+q.height)/Blockly.Bubble.ARROW_THICKNESS,h=Math.min(h,q.width,q.height)/2,q=1-Blockly.Bubble.ANCHOR_RADIUS/f,d=b+ q*d,e=c+q*e,q=b+h*l,m=c+h*k,b=b-h*l,c=c-h*k,k=g+this.arrow_radians_;k>2*Math.PI&&(k-=2*Math.PI);g=Math.sin(k)*f/Blockly.Bubble.ARROW_BEND;f=Math.cos(k)*f/Blockly.Bubble.ARROW_BEND;a.push("M"+q+","+m);a.push("C"+(q+f)+","+(m+g)+" "+d+","+e+" "+d+","+e);a.push("C"+d+","+e+" "+(b+f)+","+(c+g)+" "+b+","+c)}a.push("z");this.bubbleArrow_.setAttribute("d",a.join(" "))};Blockly.Bubble.prototype.setColour=function(a){this.bubbleBack_.setAttribute("fill",a);this.bubbleArrow_.setAttribute("fill",a)}; -Blockly.Bubble.prototype.dispose=function(){Blockly.Bubble.unbindDragEvents_();goog.dom.removeNode(this.bubbleGroup_);this.shape_=this.content_=this.workspace_=this.bubbleGroup_=null};Blockly.Icon=function(a){this.block_=a};Blockly.Icon.prototype.collapseHidden=!0;Blockly.Icon.prototype.SIZE=17;Blockly.Icon.prototype.png_="";Blockly.Icon.prototype.bubble_=null;Blockly.Icon.prototype.iconX_=0;Blockly.Icon.prototype.iconY_=0; +Blockly.Bubble.prototype.dispose=function(){Blockly.Bubble.unbindDragEvents_();goog.dom.removeNode(this.bubbleGroup_);this.shape_=this.content_=this.workspace_=this.resizeGroup_=this.bubbleBack_=this.bubbleArrow_=this.bubbleGroup_=null};Blockly.Icon=function(a){this.block_=a};Blockly.Icon.prototype.collapseHidden=!0;Blockly.Icon.prototype.SIZE=17;Blockly.Icon.prototype.png_="";Blockly.Icon.prototype.bubble_=null;Blockly.Icon.prototype.iconX_=0;Blockly.Icon.prototype.iconY_=0; Blockly.Icon.prototype.createIcon=function(){this.iconGroup_||(this.iconGroup_=Blockly.createSvgElement("g",{"class":"blocklyIconGroup"},null),Blockly.createSvgElement("image",{width:this.SIZE,height:this.SIZE},this.iconGroup_).setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.png_),this.block_.getSvgRoot().appendChild(this.iconGroup_),Blockly.bindEvent_(this.iconGroup_,"mouseup",this,this.iconClick_),this.updateEditable())}; Blockly.Icon.prototype.dispose=function(){goog.dom.removeNode(this.iconGroup_);this.iconGroup_=null;this.setVisible(!1);this.block_=null};Blockly.Icon.prototype.updateEditable=function(){this.block_.isInFlyout||!this.block_.isEditable()?Blockly.addClass_(this.iconGroup_,"blocklyIconGroupReadonly"):Blockly.removeClass_(this.iconGroup_,"blocklyIconGroupReadonly")};Blockly.Icon.prototype.isVisible=function(){return!!this.bubble_}; Blockly.Icon.prototype.iconClick_=function(a){2!=Blockly.dragMode_&&(this.block_.isInFlyout||Blockly.isRightButton(a)||this.setVisible(!this.isVisible()))};Blockly.Icon.prototype.updateColour=function(){if(this.isVisible()){var a=Blockly.makeColour(this.block_.getColour());this.bubble_.setColour(a)}}; @@ -1107,7 +1108,7 @@ Blockly.BlockSvg.prototype.disconnectUiEffect=function(){this.workspace.playAudi Blockly.BlockSvg.disconnectUiStep_=function(a,b,c){var d=(new Date-c)/200;1a.viewHeight+f||a.contentLeft<(b.RTL? a.viewLeft:e)||a.contentLeft+a.contentWidth>(b.RTL?a.viewWidth:a.viewWidth+e))for(var g=c.getTopBlocks(!1),h=0,k;k=g[h];h++){var l=k.getRelativeToSurfaceXY(),q=k.getHeightWidth(),m=f+25-q.height-l.y;0m&&k.moveBy(0,m);m=25+e-l.x-(b.RTL?0:q.width);0m&&k.moveBy(m,0)}}});Blockly.svgResize(c);Blockly.WidgetDiv.createDom();Blockly.Tooltip.createDom();return c}; Blockly.init_=function(a){var b=a.options;Blockly.bindEvent_(a.options.svg,"contextmenu",null,function(a){Blockly.isTargetInput_(a)||a.preventDefault()});Blockly.bindEvent_(window,"resize",null,function(){Blockly.svgResize(a)});Blockly.documentEventsBound_||(Blockly.bindEvent_(document,"keydown",null,Blockly.onKeyDown_),Blockly.bindEvent_(document,"touchend",null,Blockly.longStop_),Blockly.bindEvent_(document,"touchcancel",null,Blockly.longStop_),document.addEventListener("mouseup",Blockly.onMouseUp_, diff --git a/blockly_uncompressed.js b/blockly_uncompressed.js index d2d931b14..4e1a93e88 100644 --- a/blockly_uncompressed.js +++ b/blockly_uncompressed.js @@ -28,7 +28,7 @@ var dir = this.BLOCKLY_DIR.match(/[^\/]+$/)[0]; goog.addDependency("../../../" + dir + "/core/block.js", ['Blockly.Block'], ['Blockly.Blocks', 'Blockly.Comment', 'Blockly.Connection', 'Blockly.Input', 'Blockly.Mutator', 'Blockly.Warning', 'Blockly.Workspace', 'Blockly.Xml', 'goog.array', 'goog.asserts', 'goog.math.Coordinate', 'goog.string']); goog.addDependency("../../../" + dir + "/core/block_svg.js", ['Blockly.BlockSvg'], ['Blockly.Block', 'Blockly.ContextMenu', 'goog.Timer', 'goog.asserts', 'goog.dom', 'goog.math.Coordinate']); goog.addDependency("../../../" + dir + "/core/blockly.js", ['Blockly'], ['Blockly.BlockSvg', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Generator', 'Blockly.Msg', 'Blockly.Procedures', 'Blockly.Toolbox', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.inject', 'Blockly.utils', 'goog.color', 'goog.userAgent']); -goog.addDependency("../../../" + dir + "/core/blocks.js", ['Blockly.Blocks'], ['goog.asserts']); +goog.addDependency("../../../" + dir + "/core/blocks.js", ['Blockly.Blocks'], []); goog.addDependency("../../../" + dir + "/core/bubble.js", ['Blockly.Bubble'], ['Blockly.Workspace', 'goog.dom', 'goog.math', 'goog.userAgent']); goog.addDependency("../../../" + dir + "/core/comment.js", ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Icon', 'goog.userAgent']); goog.addDependency("../../../" + dir + "/core/connection.js", ['Blockly.Connection', 'Blockly.ConnectionDB'], ['goog.dom']); diff --git a/core/block_svg.js b/core/block_svg.js index 192be18d9..510d48130 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -1254,7 +1254,8 @@ Blockly.BlockSvg.prototype.updateDisabled = function() { if (!hasClass) { Blockly.addClass_(/** @type {!Element} */ (this.svgGroup_), 'blocklyDisabled'); - this.svgPath_.setAttribute('fill', 'url(#blocklyDisabledPattern)'); + this.svgPath_.setAttribute('fill', + 'url(#' + this.workspace.options.disabledPatternId + ')'); } } else { if (hasClass) { diff --git a/core/blocks.js b/core/blocks.js index b4f0cb50a..d6afbadd7 100644 --- a/core/blocks.js +++ b/core/blocks.js @@ -23,7 +23,7 @@ * @author spertus@google.com (Ellen Spertus) */ 'use strict'; -goog.require('goog.asserts'); + /** * Name space for the Blocks singleton. diff --git a/core/bubble.js b/core/bubble.js index 4f375a070..144ff05a2 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -197,7 +197,7 @@ Blockly.Bubble.prototype.autoLayout_ = true; Blockly.Bubble.prototype.createDom_ = function(content, hasResize) { /* Create the bubble. Here's the markup that will be generated: - + @@ -210,7 +210,8 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) { */ this.bubbleGroup_ = Blockly.createSvgElement('g', {}, null); - var filter = {'filter': 'url(#blocklyEmboss)'}; + var filter = + {'filter': 'url(#' + this.workspace_.options.embossFilterId + ')'}; if (goog.userAgent.getUserAgentString().indexOf('JavaFX') != -1) { // Multiple reports that JavaFX can't handle filters. UserAgent: // Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.44 @@ -568,6 +569,9 @@ Blockly.Bubble.prototype.dispose = function() { // Dispose of and unlink the bubble. goog.dom.removeNode(this.bubbleGroup_); this.bubbleGroup_ = null; + this.bubbleArrow_ = null; + this.bubbleBack_ = null; + this.resizeGroup_ = null; this.workspace_ = null; this.content_ = null; this.shape_ = null; diff --git a/core/inject.js b/core/inject.js index 8554d43da..fd18dbd0c 100644 --- a/core/inject.js +++ b/core/inject.js @@ -292,9 +292,9 @@ Blockly.createDom_ = function(container, options) { */ var defs = Blockly.createSvgElement('defs', {}, svg); - var filter, feSpecularLighting, feMerge; + var rnd = String(Math.random()).substring(2); /* - + */ - filter = Blockly.createSvgElement('filter', {'id': 'blocklyEmboss'}, defs); + var embossFilter = Blockly.createSvgElement('filter', + {'id': 'blocklyEmbossFilter' + rnd}, defs); Blockly.createSvgElement('feGaussianBlur', - {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, filter); - feSpecularLighting = Blockly.createSvgElement('feSpecularLighting', + {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); + var feSpecularLighting = Blockly.createSvgElement('feSpecularLighting', {'in': 'blur', 'surfaceScale': 1, 'specularConstant': 0.5, 'specularExponent': 10, 'lighting-color': 'white', 'result': 'specOut'}, - filter); + embossFilter); Blockly.createSvgElement('fePointLight', {'x': -5000, 'y': -10000, 'z': 20000}, feSpecularLighting); Blockly.createSvgElement('feComposite', {'in': 'specOut', 'in2': 'SourceAlpha', 'operator': 'in', - 'result': 'specOut'}, filter); + 'result': 'specOut'}, embossFilter); Blockly.createSvgElement('feComposite', {'in': 'SourceGraphic', 'in2': 'specOut', 'operator': 'arithmetic', - 'k1': 0, 'k2': 1, 'k3': 1, 'k4': 0}, filter); + 'k1': 0, 'k2': 1, 'k3': 1, 'k4': 0}, embossFilter); + options.embossFilterId = embossFilter.id; /* - - - - */ - filter = Blockly.createSvgElement('filter', - {'id': 'blocklyShadowFilter'}, defs); - Blockly.createSvgElement('feGaussianBlur', {'stdDeviation': 2}, filter); - /* - */ var disabledPattern = Blockly.createSvgElement('pattern', - {'id': 'blocklyDisabledPattern', 'patternUnits': 'userSpaceOnUse', + {'id': 'blocklyDisabledPattern' + rnd, + 'patternUnits': 'userSpaceOnUse', 'width': 10, 'height': 10}, defs); Blockly.createSvgElement('rect', {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); Blockly.createSvgElement('path', {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, disabledPattern); + options.disabledPatternId = disabledPattern.id; /* @@ -351,7 +347,7 @@ Blockly.createDom_ = function(container, options) { */ var gridPattern = Blockly.createSvgElement('pattern', - {'id': 'blocklyGridPattern' + String(Math.random()).substring(2), + {'id': 'blocklyGridPattern' + rnd, 'patternUnits': 'userSpaceOnUse'}, defs); if (options.gridOptions['length'] > 0 && options.gridOptions['spacing'] > 0) { Blockly.createSvgElement('line', diff --git a/core/workspace_svg.js b/core/workspace_svg.js index e97fde435..5c939fbb1 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -148,7 +148,7 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) { */ this.svgGroup_ = Blockly.createSvgElement('g', - {'class': 'blocklyWorkspace'}, null); + {'class': 'blocklyWorkspace'}, null); if (opt_backgroundClass) { this.svgBackground_ = Blockly.createSvgElement('rect', {'height': '100%', 'width': '100%', From fbab06082e4a9d5171f3eebcf8e3c05bfa87a862 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Mon, 28 Sep 2015 14:17:53 -0700 Subject: [PATCH 57/98] Recompile language updates. --- core/workspace_svg.js | 2 +- msg/js/pl.js | 12 ++++++------ msg/js/sc.js | 32 ++++++++++++++++---------------- msg/js/sk.js | 2 +- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 5c939fbb1..e6c62b10a 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -132,7 +132,7 @@ Blockly.WorkspaceSvg.prototype.trashcan = null; Blockly.WorkspaceSvg.prototype.scrollbar = null; /** - * Create the trash can elements. + * Create the workspace DOM elements. * @param {string=} opt_backgroundClass Either 'blocklyMainBackground' or * 'blocklyMutatorBackground'. * @return {!Element} The workspace's SVG group. diff --git a/msg/js/pl.js b/msg/js/pl.js index 1bf285c32..c26b816f5 100644 --- a/msg/js/pl.js +++ b/msg/js/pl.js @@ -142,11 +142,11 @@ Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_SET_FROM_START = "Ustawia element w odpowied Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_SET_LAST = "Ustawia ostatni element na liście."; Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_SET_RANDOM = "Ustawia losowy element na liście."; Blockly.Msg.LISTS_SPLIT_HELPURL = "https://github.com/google/blockly/wiki/Lists#splitting-strings-and-joining-lists"; // untranslated -Blockly.Msg.LISTS_SPLIT_LIST_FROM_TEXT = "make list from text"; // untranslated -Blockly.Msg.LISTS_SPLIT_TEXT_FROM_LIST = "make text from list"; // untranslated -Blockly.Msg.LISTS_SPLIT_TOOLTIP_JOIN = "Join a list of texts into one text, separated by a delimiter."; // untranslated -Blockly.Msg.LISTS_SPLIT_TOOLTIP_SPLIT = "Split text into a list of texts, breaking at each delimiter."; // untranslated -Blockly.Msg.LISTS_SPLIT_WITH_DELIMITER = "with delimiter"; // untranslated +Blockly.Msg.LISTS_SPLIT_LIST_FROM_TEXT = "stwórz listę z tekstu"; +Blockly.Msg.LISTS_SPLIT_TEXT_FROM_LIST = "stwórz tekst z listy"; +Blockly.Msg.LISTS_SPLIT_TOOLTIP_JOIN = "Łączy listę tekstów w jeden tekst, rozdzielany separatorem."; +Blockly.Msg.LISTS_SPLIT_TOOLTIP_SPLIT = "Rozdziela tekst na listę mniejszych tekstów, dzieląc na każdym separatorze."; +Blockly.Msg.LISTS_SPLIT_WITH_DELIMITER = "z separatorem"; Blockly.Msg.LOGIC_BOOLEAN_FALSE = "fałsz"; Blockly.Msg.LOGIC_BOOLEAN_HELPURL = "https://github.com/google/blockly/wiki/Logic#values"; // untranslated Blockly.Msg.LOGIC_BOOLEAN_TOOLTIP = "Zwraca 'prawda' lub 'fałsz'."; @@ -350,7 +350,7 @@ Blockly.Msg.TEXT_TRIM_OPERATOR_BOTH = "usuń spacje po obu stronach"; Blockly.Msg.TEXT_TRIM_OPERATOR_LEFT = "usuń spacje z lewej strony"; Blockly.Msg.TEXT_TRIM_OPERATOR_RIGHT = "usuń spacje z prawej strony"; Blockly.Msg.TEXT_TRIM_TOOLTIP = "Zwraca kopię tekstu z usuniętymi spacjami z jednego lub z obu końców tekstu."; -Blockly.Msg.TODAY = "Today"; // untranslated +Blockly.Msg.TODAY = "Dzisiaj"; Blockly.Msg.VARIABLES_DEFAULT_NAME = "element"; Blockly.Msg.VARIABLES_GET_CREATE_SET = "Utwórz blok 'ustaw %1'"; Blockly.Msg.VARIABLES_GET_HELPURL = "https://github.com/google/blockly/wiki/Variables#get"; // untranslated diff --git a/msg/js/sc.js b/msg/js/sc.js index bbfd21bd0..2e8434f0c 100644 --- a/msg/js/sc.js +++ b/msg/js/sc.js @@ -6,12 +6,12 @@ goog.provide('Blockly.Msg.sc'); goog.require('Blockly.Msg'); -Blockly.Msg.ADD_COMMENT = "Aciungi unu cumentu"; -Blockly.Msg.AUTH = "Permiti a custa app de sarvai su traballu tuu e de ti ddu fàiri cundividi."; +Blockly.Msg.ADD_COMMENT = "Agiunghe unu cumentu"; +Blockly.Msg.AUTH = "Permiti a custa app de sarvare su traballu tuo e de ti lu fàghere cumpartzire."; Blockly.Msg.CHANGE_VALUE_TITLE = "Muda valori:"; -Blockly.Msg.CHAT = "Fuedda cun su cumpàngiu tuu scriendi innoi!"; -Blockly.Msg.COLLAPSE_ALL = "Serra e stringi Brocus"; -Blockly.Msg.COLLAPSE_BLOCK = "Serra e stringi Brocu"; +Blockly.Msg.CHAT = "Faedda cun su cumpàngiu tuo iscriende inoghe!"; +Blockly.Msg.COLLAPSE_ALL = "Serra e astringhe Boocos"; +Blockly.Msg.COLLAPSE_BLOCK = "Serra e astringhe Blocu"; Blockly.Msg.COLOUR_BLEND_COLOUR1 = "colori 1"; Blockly.Msg.COLOUR_BLEND_COLOUR2 = "colori 2"; Blockly.Msg.COLOUR_BLEND_HELPURL = "http://meyerweb.com/eric/tools/color-blend/"; // untranslated @@ -61,16 +61,16 @@ Blockly.Msg.CONTROLS_WHILEUNTIL_OPERATOR_UNTIL = "repiti fintzas"; Blockly.Msg.CONTROLS_WHILEUNTIL_OPERATOR_WHILE = "repiti interis"; Blockly.Msg.CONTROLS_WHILEUNTIL_TOOLTIP_UNTIL = "Interis su valori est frassu, tandu fai pariga de cumandus."; Blockly.Msg.CONTROLS_WHILEUNTIL_TOOLTIP_WHILE = "Interis su valori est berus, tandu fai pariga de cumandus."; -Blockly.Msg.DELETE_BLOCK = "Fulia Brocu"; -Blockly.Msg.DELETE_X_BLOCKS = "Fulia %1 Brocus"; -Blockly.Msg.DISABLE_BLOCK = "Disabìlita Brocu"; -Blockly.Msg.DUPLICATE_BLOCK = "Dòpia"; -Blockly.Msg.ENABLE_BLOCK = "Abìlita Brocu"; -Blockly.Msg.EXPAND_ALL = "Aberi Brocus"; -Blockly.Msg.EXPAND_BLOCK = "Aberi Brocu"; -Blockly.Msg.EXTERNAL_INPUTS = "Inputs esternus"; +Blockly.Msg.DELETE_BLOCK = "Fùlia Blocu"; +Blockly.Msg.DELETE_X_BLOCKS = "Fulia %1 Blocus"; +Blockly.Msg.DISABLE_BLOCK = "Disabìlita Blocu"; +Blockly.Msg.DUPLICATE_BLOCK = "Dùplica"; +Blockly.Msg.ENABLE_BLOCK = "Abìlita Blocu"; +Blockly.Msg.EXPAND_ALL = "Aberi Brocos"; +Blockly.Msg.EXPAND_BLOCK = "Aberi Blocu"; +Blockly.Msg.EXTERNAL_INPUTS = "Intradas esternas"; Blockly.Msg.HELP = "Agiudu"; -Blockly.Msg.INLINE_INPUTS = "Inputs in lìnia"; +Blockly.Msg.INLINE_INPUTS = "Intradas in lìnia"; Blockly.Msg.LISTS_CREATE_EMPTY_HELPURL = "https://github.com/google/blockly/wiki/Lists#create-empty-list"; // untranslated Blockly.Msg.LISTS_CREATE_EMPTY_TITLE = "fait una lista buida"; Blockly.Msg.LISTS_CREATE_EMPTY_TOOLTIP = "Torrat una lista, de longària 0, chena records de datus."; @@ -257,7 +257,7 @@ Blockly.Msg.MATH_TRIG_TOOLTIP_ATAN = "Torrat su arctangenti de unu numeru."; Blockly.Msg.MATH_TRIG_TOOLTIP_COS = "Torrat su cosinu de unu gradu (no radianti)."; Blockly.Msg.MATH_TRIG_TOOLTIP_SIN = "Torrat su sinu de unu gradu (no radianti)."; Blockly.Msg.MATH_TRIG_TOOLTIP_TAN = "Torrat sa tangenti de unu gradu (no radianti)."; -Blockly.Msg.ME = "Deu"; +Blockly.Msg.ME = "Deo"; Blockly.Msg.NEW_VARIABLE = "Variabili noa..."; Blockly.Msg.NEW_VARIABLE_TITLE = "Nòmini de sa variabili noa:"; Blockly.Msg.ORDINAL_NUMBER_SUFFIX = ""; // untranslated @@ -350,7 +350,7 @@ Blockly.Msg.TEXT_TRIM_OPERATOR_BOTH = "bogat spàtzius de ambus càbudus de"; Blockly.Msg.TEXT_TRIM_OPERATOR_LEFT = "bogat spàtzius de su càbudu de manca de"; Blockly.Msg.TEXT_TRIM_OPERATOR_RIGHT = "bogat spàtzius de su càbudu de dereta de"; Blockly.Msg.TEXT_TRIM_TOOLTIP = "Torrat una copia de su testu bogaus is spàtzius de unu o de ambus is càbudus."; -Blockly.Msg.TODAY = "Oi"; +Blockly.Msg.TODAY = "Oe"; Blockly.Msg.VARIABLES_DEFAULT_NAME = "item"; Blockly.Msg.VARIABLES_GET_CREATE_SET = "Fait 'imposta %1'"; Blockly.Msg.VARIABLES_GET_HELPURL = "https://github.com/google/blockly/wiki/Variables#get"; // untranslated diff --git a/msg/js/sk.js b/msg/js/sk.js index cad4b327a..e9635b88b 100644 --- a/msg/js/sk.js +++ b/msg/js/sk.js @@ -40,7 +40,7 @@ Blockly.Msg.CONTROLS_FOREACH_TITLE = "pre každý prvok %1 v zozname %2"; Blockly.Msg.CONTROLS_FOREACH_TOOLTIP = "Pre každý prvok v zozname priraď jeho hodnotu do premenej '%1' a vykonaj príkazy."; Blockly.Msg.CONTROLS_FOR_HELPURL = "https://github.com/google/blockly/wiki/Loops#count-with"; // untranslated Blockly.Msg.CONTROLS_FOR_TITLE = "počítať s %1 od %2 do %3 o %4"; -Blockly.Msg.CONTROLS_FOR_TOOLTIP = "Nechá premennú \"%1\" nadobúdať hodnoty od začiatočného čísla po konečné s daným medzikrokom a vykoná zadané bloky."; +Blockly.Msg.CONTROLS_FOR_TOOLTIP = "Nechá premennú '%1' nadobúdať hodnoty od začiatočného čísla po konečné s daným medzikrokom a vykoná zadané bloky."; Blockly.Msg.CONTROLS_IF_ELSEIF_TOOLTIP = "Pridať podmienku k \"ak\" bloku."; Blockly.Msg.CONTROLS_IF_ELSE_TOOLTIP = "Pridať poslednú záchytnú podmienku k \"ak\" bloku."; Blockly.Msg.CONTROLS_IF_HELPURL = "https://github.com/google/blockly/wiki/IfElse"; // untranslated From 349146743bded9c1f4d91c287f17076c06b6678e Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 29 Sep 2015 15:40:19 -0700 Subject: [PATCH 58/98] Remove dependency on goog.cssom. --- blockly_compressed.js | 13 +++---------- blockly_uncompressed.js | 3 +-- core/blockly.js | 3 --- core/blocks.js | 9 ++------- core/css.js | 25 +++++++++---------------- core/msg.js | 1 + 6 files changed, 16 insertions(+), 38 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index bb8ae09dd..50bf5c63b 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -839,14 +839,7 @@ goog.ui.tree.TreeControl.prototype.attachEvents_=function(){var a=this.getElemen goog.events.EventType.CLICK,this.handleMouseEvent_).listen(a,goog.events.EventType.DBLCLICK,this.handleMouseEvent_)};goog.ui.tree.TreeControl.prototype.detachEvents_=function(){this.keyHandler_.dispose();this.keyHandler_=null;this.focusHandler_.dispose();this.focusHandler_=null}; goog.ui.tree.TreeControl.prototype.handleMouseEvent_=function(a){goog.log.fine(this.logger_,"Received event "+a.type);var b=this.getNodeFromEvent_(a);if(b)switch(a.type){case goog.events.EventType.MOUSEDOWN:b.onMouseDown(a);break;case goog.events.EventType.CLICK:b.onClick_(a);break;case goog.events.EventType.DBLCLICK:b.onDoubleClick_(a)}}; goog.ui.tree.TreeControl.prototype.handleKeyEvent=function(a){var b=!1;(b=this.typeAhead_.handleNavigation(a)||this.selectedItem_&&this.selectedItem_.onKeyDown(a)||this.typeAhead_.handleTypeAheadChar(a))&&a.preventDefault();return b};goog.ui.tree.TreeControl.prototype.getNodeFromEvent_=function(a){var b=null;for(a=a.target;null!=a;){if(b=goog.ui.tree.BaseNode.allNodes[a.id])return b;if(a==this.getElement())break;a=a.parentNode}return null}; -goog.ui.tree.TreeControl.prototype.createNode=function(a){return new goog.ui.tree.TreeNode(a||goog.html.SafeHtml.EMPTY,this.getConfig(),this.getDomHelper())};goog.ui.tree.TreeControl.prototype.setNode=function(a){this.typeAhead_.setNodeInMap(a)};goog.ui.tree.TreeControl.prototype.removeNode=function(a){this.typeAhead_.removeNodeFromMap(a)};goog.ui.tree.TreeControl.prototype.clearTypeAhead=function(){this.typeAhead_.clear()};goog.ui.tree.TreeControl.defaultConfig=goog.ui.tree.BaseNode.defaultConfig;goog.cssom={};goog.cssom.CssRuleType={STYLE:1,IMPORT:3,MEDIA:4,FONT_FACE:5,PAGE:6,NAMESPACE:7};goog.cssom.getAllCssText=function(a){return goog.cssom.getAllCss_(a||document.styleSheets,!0)};goog.cssom.getAllCssStyleRules=function(a){return goog.cssom.getAllCss_(a||document.styleSheets,!1)};goog.cssom.getCssRulesFromStyleSheet=function(a){var b=null;try{b=a.cssRules||a.rules}catch(c){if(15==c.code)throw c.styleSheet=a,c;}return b}; -goog.cssom.getAllCssStyleSheets=function(a,b){var c=[],d=a||document.styleSheets,e=goog.isDef(b)?b:!1;if(d.imports&&d.imports.length)for(var f=0,g=d.imports.length;fc||void 0==c)c=goog.cssom.getCssRulesFromStyleSheet(a).length;if(a.insertRule)a.insertRule(b,c);else if(b=/^([^\{]+)\{([^\{]+)\}/.exec(b),3==b.length)a.addRule(b[1],b[2],c);else throw Error("Your CSSRule appears to be ill-formatted.");};goog.cssom.removeCssRule=function(a,b){a.deleteRule?a.deleteRule(b):a.removeRule(b)}; -goog.cssom.addCssText=function(a,b){var c=b?b.getDocument():goog.dom.getDocument(),d=c.createElement(goog.dom.TagName.STYLE);d.type="text/css";c.getElementsByTagName(goog.dom.TagName.HEAD)[0].appendChild(d);d.styleSheet?d.styleSheet.cssText=a:(c=c.createTextNode(a),d.appendChild(c));return d};goog.cssom.getFileNameFromStyleSheet=function(a){return(a=a.href)?/([^\/\?]+)[^\/]*$/.exec(a)[1]:null}; -goog.cssom.getAllCss_=function(a,b){for(var c=[],d=goog.cssom.getAllCssStyleSheets(a),e=0;a=d[e];e++){var f=goog.cssom.getCssRulesFromStyleSheet(a);if(f&&f.length){if(!b)var g=0;for(var h=0,k=f.length,l;h>>/g,Blockly.Css.mediaPath_);Blockly.Css.styleSheet_=goog.cssom.addCssText(c).sheet;Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN)}}; -Blockly.Css.setCursor=function(a){if(Blockly.Css.currentCursor_!=a){Blockly.Css.currentCursor_=a;var b="url("+Blockly.Css.mediaPath_+"/"+a+".cur) "+(a==Blockly.Css.Cursor.OPEN?"8 5":"7 3")+", auto";goog.cssom.replaceCssRule("",".blocklyDraggable {\n cursor: "+b+";\n}\n",Blockly.Css.styleSheet_,0);for(var c=document.getElementsByClassName("blocklyToolboxDiv"),d=0,e;e=c[d];d++)e.style.cursor=a==Blockly.Css.Cursor.DELETE?b:"";document.body.parentNode.style.cursor=a==Blockly.Css.Cursor.OPEN?"":b}}; +Blockly.Css.inject=function(a,b){if(!Blockly.Css.styleSheet_){var c=".blocklyDraggable {}\n";a&&(c+=Blockly.Css.CONTENT.join("\n"),Blockly.FieldDate&&(c+=Blockly.FieldDate.CSS.join("\n")));Blockly.Css.mediaPath_=b.replace(/[\\\/]$/,"");var c=c.replace(/<<>>/g,Blockly.Css.mediaPath_),d=document.createElement("style");document.head.appendChild(d);c=document.createTextNode(c);d.appendChild(c);Blockly.Css.styleSheet_=d.sheet;Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN)}}; +Blockly.Css.setCursor=function(a){if(Blockly.Css.currentCursor_!=a){Blockly.Css.currentCursor_=a;var b="url("+Blockly.Css.mediaPath_+"/"+a+".cur), auto",c=".blocklyDraggable {\n cursor: "+b+";\n}\n";Blockly.Css.styleSheet_.deleteRule(0);Blockly.Css.styleSheet_.insertRule(c,0);for(var c=document.getElementsByClassName("blocklyToolboxDiv"),d=0,e;e=c[d];d++)e.style.cursor=a==Blockly.Css.Cursor.DELETE?b:"";document.body.parentNode.style.cursor=a==Blockly.Css.Cursor.OPEN?"":b}}; Blockly.Css.CONTENT=[".blocklySvg {"," background-color: #fff;"," outline: none;"," overflow: hidden;","}",".blocklyWidgetDiv {"," display: none;"," position: absolute;"," z-index: 999;","}",".blocklyTooltipDiv {"," background-color: #ffffc7;"," border: 1px solid #ddc;"," box-shadow: 4px 4px 20px 1px rgba(0,0,0,.15);"," color: #000;"," display: none;"," font-family: sans-serif;"," font-size: 9pt;"," opacity: 0.9;"," padding: 2px;"," position: absolute;"," z-index: 1000;","}",".blocklyResizeSE {", " cursor: se-resize;"," fill: #aaa;","}",".blocklyResizeSW {"," cursor: sw-resize;"," fill: #aaa;","}",".blocklyResizeLine {"," stroke: #888;"," stroke-width: 1;","}",".blocklyHighlightedConnectionPath {"," fill: none;"," stroke: #fc3;"," stroke-width: 4px;","}",".blocklyPathLight {"," fill: none;"," stroke-linecap: round;"," stroke-width: 1;","}",".blocklySelected>.blocklyPath {"," stroke: #fc3;"," stroke-width: 3px;","}",".blocklySelected>.blocklyPathLight {"," display: none;","}", ".blocklyDragging>.blocklyPath,",".blocklyDragging>.blocklyPathLight {"," fill-opacity: .8;"," stroke-opacity: .8;","}",".blocklyDragging>.blocklyPathDark {"," display: none;","}",".blocklyDisabled>.blocklyPath {"," fill-opacity: .5;"," stroke-opacity: .5;","}",".blocklyDisabled>.blocklyPathLight,",".blocklyDisabled>.blocklyPathDark {"," display: none;","}",".blocklyText {"," cursor: default;"," fill: #fff;"," font-family: sans-serif;"," font-size: 11pt;","}",".blocklyNonEditableText>text {", diff --git a/blockly_uncompressed.js b/blockly_uncompressed.js index 4e1a93e88..b7f220cbc 100644 --- a/blockly_uncompressed.js +++ b/blockly_uncompressed.js @@ -33,7 +33,7 @@ goog.addDependency("../../../" + dir + "/core/bubble.js", ['Blockly.Bubble'], [' goog.addDependency("../../../" + dir + "/core/comment.js", ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Icon', 'goog.userAgent']); goog.addDependency("../../../" + dir + "/core/connection.js", ['Blockly.Connection', 'Blockly.ConnectionDB'], ['goog.dom']); goog.addDependency("../../../" + dir + "/core/contextmenu.js", ['Blockly.ContextMenu'], ['goog.dom', 'goog.events', 'goog.style', 'goog.ui.Menu', 'goog.ui.MenuItem']); -goog.addDependency("../../../" + dir + "/core/css.js", ['Blockly.Css'], ['goog.cssom']); +goog.addDependency("../../../" + dir + "/core/css.js", ['Blockly.Css'], []); goog.addDependency("../../../" + dir + "/core/field.js", ['Blockly.Field'], ['goog.asserts', 'goog.dom', 'goog.math.Size', 'goog.style', 'goog.userAgent']); goog.addDependency("../../../" + dir + "/core/field_angle.js", ['Blockly.FieldAngle'], ['Blockly.FieldTextInput', 'goog.math', 'goog.userAgent']); goog.addDependency("../../../" + dir + "/core/field_checkbox.js", ['Blockly.FieldCheckbox'], ['Blockly.Field']); @@ -77,7 +77,6 @@ goog.addDependency("async/run.js", ['goog.async.run'], ['goog.async.WorkQueue', goog.addDependency("async/workqueue.js", ['goog.async.WorkItem', 'goog.async.WorkQueue'], ['goog.asserts', 'goog.async.FreeList']); goog.addDependency("color/color.js", ['goog.color', 'goog.color.Hsl', 'goog.color.Hsv', 'goog.color.Rgb'], ['goog.color.names', 'goog.math']); goog.addDependency("color/names.js", ['goog.color.names'], []); -goog.addDependency("cssom/cssom.js", ['goog.cssom', 'goog.cssom.CssRuleType'], ['goog.array', 'goog.dom', 'goog.dom.TagName']); goog.addDependency("debug/debug.js", ['goog.debug'], ['goog.array', 'goog.html.SafeHtml', 'goog.html.SafeUrl', 'goog.html.uncheckedconversions', 'goog.string.Const', 'goog.structs.Set', 'goog.userAgent']); goog.addDependency("debug/entrypointregistry.js", ['goog.debug.EntryPointMonitor', 'goog.debug.entryPointRegistry'], ['goog.asserts']); goog.addDependency("debug/error.js", ['goog.debug.Error'], []); diff --git a/core/blockly.js b/core/blockly.js index e5936518d..e024237b1 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -27,7 +27,6 @@ // Top level object for Blockly. goog.provide('Blockly'); -// Blockly core dependencies. goog.require('Blockly.BlockSvg'); goog.require('Blockly.FieldAngle'); goog.require('Blockly.FieldCheckbox'); @@ -54,8 +53,6 @@ goog.require('Blockly.WidgetDiv'); goog.require('Blockly.WorkspaceSvg'); goog.require('Blockly.inject'); goog.require('Blockly.utils'); - -// Closure dependencies. goog.require('goog.color'); goog.require('goog.userAgent'); diff --git a/core/blocks.js b/core/blocks.js index d6afbadd7..26e1eaa2d 100644 --- a/core/blocks.js +++ b/core/blocks.js @@ -19,19 +19,14 @@ */ /** - * @fileoverview Flexible templating system for defining blocks. + * @fileoverview Name space for the Blocks singleton. * @author spertus@google.com (Ellen Spertus) */ 'use strict'; - -/** - * Name space for the Blocks singleton. - * Blocks gets populated in the blocks files, possibly through calls to - * Blocks.addTemplate(). - */ goog.provide('Blockly.Blocks'); + /** * Unique ID counter for created blocks. * @private diff --git a/core/css.js b/core/css.js index a025f75ef..de8494f94 100644 --- a/core/css.js +++ b/core/css.js @@ -26,8 +26,6 @@ goog.provide('Blockly.Css'); -goog.require('goog.cssom'); - /** * List of cursors. @@ -86,7 +84,12 @@ Blockly.Css.inject = function(hasCss, pathToMedia) { // Strip off any trailing slash (either Unix or Windows). Blockly.Css.mediaPath_ = pathToMedia.replace(/[\\\/]$/, ''); text = text.replace(/<<>>/g, Blockly.Css.mediaPath_); - Blockly.Css.styleSheet_ = goog.cssom.addCssText(text).sheet; + // Inject CSS tag. + var cssNode = document.createElement('style'); + document.head.appendChild(cssNode); + var cssTextNode = document.createTextNode(text); + cssNode.appendChild(cssTextNode); + Blockly.Css.styleSheet_ = cssNode.sheet; Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN); }; @@ -99,22 +102,12 @@ Blockly.Css.setCursor = function(cursor) { return; } Blockly.Css.currentCursor_ = cursor; - /* - Hotspot coordinates are baked into the CUR file, but they are still - required in the CSS due to a Chrome bug. - https://code.google.com/p/chromium/issues/detail?id=1446 - */ - if (cursor == Blockly.Css.Cursor.OPEN) { - var xy = '8 5'; - } else { - var xy = '7 3'; - } - var url = 'url(' + Blockly.Css.mediaPath_ + '/' + cursor + - '.cur) ' + xy + ', auto'; + var url = 'url(' + Blockly.Css.mediaPath_ + '/' + cursor + '.cur), auto'; // There are potentially hundreds of draggable objects. Changing their style // properties individually is too slow, so change the CSS rule instead. var rule = '.blocklyDraggable {\n cursor: ' + url + ';\n}\n'; - goog.cssom.replaceCssRule('', rule, Blockly.Css.styleSheet_, 0); + Blockly.Css.styleSheet_.deleteRule(0); + Blockly.Css.styleSheet_.insertRule(rule, 0); // There is probably only one toolbox, so just change its style property. var toolboxen = document.getElementsByClassName('blocklyToolboxDiv'); for (var i = 0, toolbox; toolbox = toolboxen[i]; i++) { diff --git a/core/msg.js b/core/msg.js index 9056885f7..7bea1f6cc 100644 --- a/core/msg.js +++ b/core/msg.js @@ -30,6 +30,7 @@ */ goog.provide('Blockly.Msg'); + /** * Back up original getMsg function. * @type {!Function} From 7db8ce94de9c2fde999bdd59180031fbf5f2fd9d Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 29 Sep 2015 23:12:32 -0700 Subject: [PATCH 59/98] Minor simplifications to connections. --- core/connection.js | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/core/connection.js b/core/connection.js index 468c68a15..eb55e61b0 100644 --- a/core/connection.js +++ b/core/connection.js @@ -42,8 +42,10 @@ Blockly.Connection = function(source, type) { /** @type {number} */ this.type = type; // Shortcut for the databases for this connection's workspace. - this.dbList_ = source.workspace.connectionDBList; - this.hidden_ = !this.dbList_; + this.db_ = source.workspace.connectionDBList[type]; + this.dbOpposite_ = + source.workspace.connectionDBList[Blockly.OPPOSITE_TYPE[type]]; + this.hidden_ = !this.db_; }; /** @@ -88,7 +90,7 @@ Blockly.Connection.prototype.dispose = function() { throw 'Disconnect connection before disposing of it.'; } if (this.inDB_) { - this.dbList_[this.type].removeConnection_(this); + this.db_.removeConnection_(this); } if (Blockly.highlightedConnection_ == this) { Blockly.highlightedConnection_ = null; @@ -96,6 +98,8 @@ Blockly.Connection.prototype.dispose = function() { if (Blockly.localConnection_ == this) { Blockly.localConnection_ = null; } + this.db_ = null; + this.dbOpposite_ = null; }; /** @@ -242,8 +246,8 @@ Blockly.Connection.prototype.connect = function(otherConnection) { */ Blockly.Connection.singleConnection_ = function(block, orphanBlock) { var connection = false; - for (var x = 0; x < block.inputList.length; x++) { - var thisConnection = block.inputList[x].connection; + for (var i = 0; i < block.inputList.length; i++) { + var thisConnection = block.inputList[i].connection; if (thisConnection && thisConnection.type == Blockly.INPUT_VALUE && orphanBlock.outputConnection.checkType_(thisConnection)) { if (connection) { @@ -351,13 +355,13 @@ Blockly.Connection.prototype.bumpAwayFrom_ = function(staticConnection) { Blockly.Connection.prototype.moveTo = function(x, y) { // Remove it from its old location in the database (if already present) if (this.inDB_) { - this.dbList_[this.type].removeConnection_(this); + this.db_.removeConnection_(this); } this.x_ = x; this.y_ = y; // Insert it into its new location in the database. if (!this.hidden_) { - this.dbList_[this.type].addConnection_(this); + this.db_.addConnection_(this); } }; @@ -441,8 +445,7 @@ Blockly.Connection.prototype.closest = function(maxLimit, dx, dy) { return {connection: null, radius: maxLimit}; } // Determine the opposite type of connection. - var oppositeType = Blockly.OPPOSITE_TYPE[this.type]; - var db = this.dbList_[oppositeType]; + var db = this.dbOpposite_; // Since this connection is probably being dragged, add the delta. var currentX = this.x_ + dx; @@ -560,8 +563,8 @@ Blockly.Connection.prototype.checkType_ = function(otherConnection) { return true; } // Find any intersection in the check lists. - for (var x = 0; x < this.check_.length; x++) { - if (otherConnection.check_.indexOf(this.check_[x]) != -1) { + for (var i = 0; i < this.check_.length; i++) { + if (otherConnection.check_.indexOf(this.check_[i]) != -1) { return true; } } @@ -608,8 +611,7 @@ Blockly.Connection.prototype.setCheck = function(check) { */ Blockly.Connection.prototype.neighbours_ = function(maxLimit) { // Determine the opposite type of connection. - var oppositeType = Blockly.OPPOSITE_TYPE[this.type]; - var db = this.dbList_[oppositeType]; + var db = this.dbOpposite_; var currentX = this.x_; var currentY = this.y_; @@ -668,9 +670,9 @@ Blockly.Connection.prototype.neighbours_ = function(maxLimit) { Blockly.Connection.prototype.setHidden = function(hidden) { this.hidden_ = hidden; if (hidden && this.inDB_) { - this.dbList_[this.type].removeConnection_(this); + this.db_.removeConnection_(this); } else if (!hidden && !this.inDB_) { - this.dbList_[this.type].addConnection_(this); + this.db_.addConnection_(this); } }; @@ -692,8 +694,8 @@ Blockly.Connection.prototype.hideAll = function() { } // Close all bubbles of all children. var icons = block.getIcons(); - for (var x = 0; x < icons.length; x++) { - icons[x].setVisible(false); + for (var i = 0; i < icons.length; i++) { + icons[i].setVisible(false); } } } @@ -799,6 +801,7 @@ Blockly.ConnectionDB.prototype.removeConnection_ = function(connection) { } connection.inDB_ = false; // Find the connection using a binary search. + // About 10% faster than a linear search using indexOf. var pointerMin = 0; var pointerMax = this.length - 2; var pointerMid = pointerMax; From c82c460da83b613049dc70cda5a609d566c7b70e Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 30 Sep 2015 19:33:05 -0700 Subject: [PATCH 60/98] Move icon reference to block SVG. No functional change. --- core/block.js | 6 ------ core/block_svg.js | 13 +++++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/core/block.js b/core/block.js index 5d4170ea9..a3c320103 100644 --- a/core/block.js +++ b/core/block.js @@ -508,12 +508,6 @@ Blockly.Block.prototype.setEditable = function(editable) { field.updateEditable(); } } - if (this.rendered) { - var icons = this.getIcons(); - for (var i = 0; i < icons.length; i++) { - icons[i].updateEditable(); - } - } }; /** diff --git a/core/block_svg.js b/core/block_svg.js index 510d48130..50c6bd0b6 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -789,6 +789,19 @@ Blockly.BlockSvg.prototype.setMovable = function(movable) { this.updateMovable(); }; +/** + * Set whether this block is editable or not. + * @param {boolean} movable True if editable. + */ +Blockly.BlockSvg.prototype.setEditable = function(editable) { + Blockly.BlockSvg.superClass_.setEditable.call(this, editable); + if (this.rendered) { + for (var i = 0; i < this.icons_.length; i++) { + this.icons_[i].updateEditable(); + } + } +}; + /** * Return the root node of the SVG or null if none exists. * @return {Element} The root SVG node (probably a group). From 6f924e349afffe3668456c85f8954855c14e8184 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 1 Oct 2015 14:09:14 -0700 Subject: [PATCH 61/98] Speed up connection matching. Fix theoretical race condition. --- blockly_compressed.js | 33 +++++++++++++++++---------------- core/connection.js | 8 ++++---- core/xml.js | 4 +++- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 50bf5c63b..11d40ad69 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -879,8 +879,8 @@ this.foreignObject_.appendChild(a);Blockly.bindEvent_(this.textarea_,"mouseup",t Blockly.Comment.prototype.resizeBubble_=function(){var a=this.bubble_.getBubbleSize(),b=2*Blockly.Bubble.BORDER_WIDTH;this.foreignObject_.setAttribute("width",a.width-b);this.foreignObject_.setAttribute("height",a.height-b);this.textarea_.style.width=a.width-b-4+"px";this.textarea_.style.height=a.height-b-4+"px"}; Blockly.Comment.prototype.setVisible=function(a){if(a!=this.isVisible())if(!this.block_.isEditable()&&!this.textarea_||goog.userAgent.IE)Blockly.Warning.prototype.setVisible.call(this,a);else{var b=this.getText(),c=this.getBubbleSize();a?(this.bubble_=new Blockly.Bubble(this.block_.workspace,this.createEditor_(),this.block_.svgPath_,this.iconX_,this.iconY_,this.width_,this.height_),this.bubble_.registerResizeEvent(this,this.resizeBubble_),this.updateColour(),this.text_=null):(this.bubble_.dispose(), this.foreignObject_=this.textarea_=this.bubble_=null);this.setText(b);this.setBubbleSize(c.width,c.height)}};Blockly.Comment.prototype.textareaFocus_=function(a){this.bubble_.promote_();this.textarea_.focus()};Blockly.Comment.prototype.getBubbleSize=function(){return this.isVisible()?this.bubble_.getBubbleSize():{width:this.width_,height:this.height_}};Blockly.Comment.prototype.setBubbleSize=function(a,b){this.textarea_?this.bubble_.setBubbleSize(a,b):(this.width_=a,this.height_=b)}; -Blockly.Comment.prototype.getText=function(){return this.textarea_?this.textarea_.value:this.text_};Blockly.Comment.prototype.setText=function(a){this.textarea_?this.textarea_.value=a:this.text_=a};Blockly.Comment.prototype.dispose=function(){this.block_.comment=null;Blockly.Icon.prototype.dispose.call(this)};Blockly.Connection=function(a,b){this.sourceBlock_=a;this.type=b;this.dbList_=a.workspace.connectionDBList;this.hidden_=!this.dbList_};Blockly.Connection.prototype.targetConnection=null;Blockly.Connection.prototype.check_=null;Blockly.Connection.prototype.x_=0;Blockly.Connection.prototype.y_=0;Blockly.Connection.prototype.inDB_=!1; -Blockly.Connection.prototype.dispose=function(){if(this.targetConnection)throw"Disconnect connection before disposing of it.";this.inDB_&&this.dbList_[this.type].removeConnection_(this);Blockly.highlightedConnection_==this&&(Blockly.highlightedConnection_=null);Blockly.localConnection_==this&&(Blockly.localConnection_=null)};Blockly.Connection.prototype.isSuperior=function(){return this.type==Blockly.INPUT_VALUE||this.type==Blockly.NEXT_STATEMENT}; +Blockly.Comment.prototype.getText=function(){return this.textarea_?this.textarea_.value:this.text_};Blockly.Comment.prototype.setText=function(a){this.textarea_?this.textarea_.value=a:this.text_=a};Blockly.Comment.prototype.dispose=function(){this.block_.comment=null;Blockly.Icon.prototype.dispose.call(this)};Blockly.Connection=function(a,b){this.sourceBlock_=a;this.type=b;this.db_=a.workspace.connectionDBList[b];this.dbOpposite_=a.workspace.connectionDBList[Blockly.OPPOSITE_TYPE[b]];this.hidden_=!this.db_};Blockly.Connection.prototype.targetConnection=null;Blockly.Connection.prototype.check_=null;Blockly.Connection.prototype.x_=0;Blockly.Connection.prototype.y_=0;Blockly.Connection.prototype.inDB_=!1; +Blockly.Connection.prototype.dispose=function(){if(this.targetConnection)throw"Disconnect connection before disposing of it.";this.inDB_&&this.db_.removeConnection_(this);Blockly.highlightedConnection_==this&&(Blockly.highlightedConnection_=null);Blockly.localConnection_==this&&(Blockly.localConnection_=null);this.dbOpposite_=this.db_=null};Blockly.Connection.prototype.isSuperior=function(){return this.type==Blockly.INPUT_VALUE||this.type==Blockly.NEXT_STATEMENT}; Blockly.Connection.prototype.connect=function(a){if(this.sourceBlock_==a.sourceBlock_)throw"Attempted to connect a block to itself.";if(this.sourceBlock_.workspace!==a.sourceBlock_.workspace)throw"Blocks are on different workspaces.";if(Blockly.OPPOSITE_TYPE[this.type]!=a.type)throw"Attempt to connect incompatible types.";if(this.type==Blockly.INPUT_VALUE||this.type==Blockly.OUTPUT_VALUE){if(this.targetConnection)throw"Source connection already connected (value).";if(a.targetConnection){var b=a.targetBlock(); b.setParent(null);if(!b.outputConnection)throw"Orphan block does not have an output connection.";for(var c=this.sourceBlock_;c=Blockly.Connection.singleConnection_(c,b);)if(c.targetBlock())c=c.targetBlock();else{c.connect(b.outputConnection);b=null;break}b&&setTimeout(function(){b.outputConnection.bumpAwayFrom_(a)},Blockly.BUMP_DELAY)}}else{if(this.targetConnection)throw"Source connection already connected (block).";if(a.targetConnection){if(this.type!=Blockly.PREVIOUS_STATEMENT)throw"Can only do a mid-stack connection with the top of a block."; b=a.targetBlock();b.setParent(null);if(!b.previousConnection)throw"Orphan block does not have a previous connection.";for(c=this.sourceBlock_;c.nextConnection;)if(c.nextConnection.targetConnection)c=c.getNextBlock();else{b.previousConnection.checkType_(c.nextConnection)&&(c.nextConnection.connect(b.previousConnection),b=null);break}b&&setTimeout(function(){b.previousConnection.bumpAwayFrom_(a)},Blockly.BUMP_DELAY)}}var d;this.isSuperior()?(c=this.sourceBlock_,d=a.sourceBlock_):(c=a.sourceBlock_,d= @@ -888,16 +888,16 @@ this.sourceBlock_);this.targetConnection=a;a.targetConnection=this;d.setParent(c Blockly.Connection.prototype.disconnect=function(){var a=this.targetConnection;if(!a)throw"Source connection not connected.";if(a.targetConnection!=this)throw"Target connection not connected to source connection.";this.targetConnection=a.targetConnection=null;var b;this.isSuperior()?(b=this.sourceBlock_,a=a.sourceBlock_):(b=a.sourceBlock_,a=this.sourceBlock_);b.rendered&&b.render();a.rendered&&(a.updateDisabled(),a.render())}; Blockly.Connection.prototype.targetBlock=function(){return this.targetConnection?this.targetConnection.sourceBlock_:null}; Blockly.Connection.prototype.bumpAwayFrom_=function(a){if(0==Blockly.dragMode_){var b=this.sourceBlock_.getRootBlock();if(!b.isInFlyout){var c=!1;if(!b.isMovable()){b=a.sourceBlock_.getRootBlock();if(!b.isMovable())return;a=this;c=!0}b.getSvgRoot().parentNode.appendChild(b.getSvgRoot());var d=a.x_+Blockly.SNAP_RADIUS-this.x_;a=a.y_+Blockly.SNAP_RADIUS-this.y_;c&&(a=-a);b.RTL&&(d=-d);b.moveBy(d,a)}}}; -Blockly.Connection.prototype.moveTo=function(a,b){this.inDB_&&this.dbList_[this.type].removeConnection_(this);this.x_=a;this.y_=b;this.hidden_||this.dbList_[this.type].addConnection_(this)};Blockly.Connection.prototype.moveBy=function(a,b){this.moveTo(this.x_+a,this.y_+b)}; +Blockly.Connection.prototype.moveTo=function(a,b){this.inDB_&&this.db_.removeConnection_(this);this.x_=a;this.y_=b;this.hidden_||this.db_.addConnection_(this)};Blockly.Connection.prototype.moveBy=function(a,b){this.moveTo(this.x_+a,this.y_+b)}; Blockly.Connection.prototype.highlight=function(){var a;this.type==Blockly.INPUT_VALUE||this.type==Blockly.OUTPUT_VALUE?(a=this.sourceBlock_.RTL?-Blockly.BlockSvg.TAB_WIDTH:Blockly.BlockSvg.TAB_WIDTH,a="m 0,0 v 5 c 0,10 "+-a+",-8 "+-a+",7.5 s "+a+",-2.5 "+a+",7.5 v 5"):a=this.sourceBlock_.RTL?"m 20,0 h -5 "+Blockly.BlockSvg.NOTCH_PATH_RIGHT+" h -5":"m -20,0 h 5 "+Blockly.BlockSvg.NOTCH_PATH_LEFT+" h 5";var b=this.sourceBlock_.getRelativeToSurfaceXY();Blockly.Connection.highlightedPath_=Blockly.createSvgElement("path", {"class":"blocklyHighlightedConnectionPath",d:a,transform:"translate("+(this.x_-b.x)+","+(this.y_-b.y)+")"},this.sourceBlock_.getSvgRoot())};Blockly.Connection.prototype.unhighlight=function(){goog.dom.removeNode(Blockly.Connection.highlightedPath_);delete Blockly.Connection.highlightedPath_}; Blockly.Connection.prototype.tighten_=function(){var a=this.targetConnection.x_-this.x_,b=this.targetConnection.y_-this.y_;if(0!=a||0!=b){var c=this.targetBlock(),d=c.getSvgRoot();if(!d)throw"block is not rendered.";d=Blockly.getRelativeXY_(d);c.getSvgRoot().setAttribute("transform","translate("+(d.x-a)+","+(d.y-b)+")");c.moveConnections_(-a,-b)}}; -Blockly.Connection.prototype.closest=function(a,b,c){function d(b){var c=e[b];if((c.type==Blockly.OUTPUT_VALUE||c.type==Blockly.PREVIOUS_STATEMENT)&&c.targetConnection||c.type==Blockly.INPUT_VALUE&&c.targetConnection&&!c.targetBlock().isMovable()||!q.checkType_(c))return!0;c=c.sourceBlock_;do{if(l==c)return!0;c=c.getParent()}while(c);var d=f-e[b].x_,c=g-e[b].y_,d=Math.sqrt(d*d+c*c);d<=a&&(k=e[b],a=d);return ca.y_)c=d;else{b=d;break}}this.splice(b,0,a);a.inDB_=!0}}; Blockly.ConnectionDB.prototype.removeConnection_=function(a){if(!a.inDB_)throw"Connection not in database.";a.inDB_=!1;for(var b=0,c=this.length-2,d=c;b"!=d.slice(-2)&&(b+=" ")}a=a.join("\n");a=a.replace(/(<(\w+)\b[^>]*>[^\n]*)\n *<\/\2>/g,"$1");return a.replace(/^\n/,"")}; Blockly.Xml.textToDom=function(a){a=(new DOMParser).parseFromString(a,"text/xml");if(!a||!a.firstChild||"xml"!=a.firstChild.nodeName.toLowerCase()||a.firstChild!==a.lastChild)throw"Blockly.Xml.textToDom did not obtain a valid XML tree.";return a.firstChild}; Blockly.Xml.domToWorkspace=function(a,b){var c;a.RTL&&(c=a.getWidth());Blockly.Field.startCache();for(var d=b.childNodes.length,e=0;e=a.clientX&&0==a.clientY&&0==a.button)){Blockly.removeAllRanges();var d=b.getRelativeToSurfaceXY(),e=c.moveDrag(a),f=b.getSvgRoot();1==Blockly.dragMode_&&goog.math.Coordinate.distance(d,e)*c.scale>Blockly.DRAG_RADIUS&&(Blockly.dragMode_=2,Blockly.longStop_(),f.translate_="",f.skew_="",b.parentBlock_&&(b.setParent(null),b.disconnectUiEffect()),b.setDragging_(!0), c.recordDeleteAreas());if(2==Blockly.dragMode_){var g=d.x-b.dragStartXY_.x,d=d.y-b.dragStartXY_.y;f.translate_="translate("+e.x+","+e.y+")";f.setAttribute("transform",f.translate_+f.skew_);for(e=0;e Date: Thu, 1 Oct 2015 20:23:46 -0700 Subject: [PATCH 62/98] Stop Firefox from jumping when widget div is displayed. Issue 186. --- core/widgetdiv.js | 5 +++++ tests/playground.html | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/widgetdiv.js b/core/widgetdiv.js index 36eb916b7..3342aa365 100644 --- a/core/widgetdiv.js +++ b/core/widgetdiv.js @@ -30,6 +30,7 @@ goog.provide('Blockly.WidgetDiv'); goog.require('Blockly.Css'); goog.require('goog.dom'); +goog.require('goog.style'); /** @@ -75,6 +76,10 @@ Blockly.WidgetDiv.show = function(newOwner, rtl, dispose) { Blockly.WidgetDiv.hide(); Blockly.WidgetDiv.owner_ = newOwner; Blockly.WidgetDiv.dispose_ = dispose; + // Temporarily move the widget to the top of the screen so that it does not + // cause a scrollbar jump in Firefox when displayed. + var xy = goog.style.getViewportPageOffset(document); + Blockly.WidgetDiv.DIV.style.top = xy.y + 'px'; Blockly.WidgetDiv.DIV.style.direction = rtl ? 'rtl' : 'ltr'; Blockly.WidgetDiv.DIV.style.display = 'block'; }; diff --git a/tests/playground.html b/tests/playground.html index 96a09272b..224ad61b4 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -87,8 +87,8 @@ function start() { {enabled: true, controls: true, wheel: true, - maxScale: 2, - minScale: .1, + maxScale: 4, + minScale: .25, scaleSpeed: 1.1 }, }); From ac9de0d91548662dc1919ea6e306517fabc292d2 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 2 Oct 2015 15:38:39 -0700 Subject: [PATCH 63/98] Deprecate empty list block. --- blockly_compressed.js | 3 ++- blockly_uncompressed.js | 2 +- blocks/lists.js | 4 ++++ demos/code/index.html | 4 +++- tests/playground.html | 4 +++- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 11d40ad69..315067cde 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -1246,7 +1246,8 @@ Blockly.Css.CONTENT=[".blocklySvg {"," background-color: #fff;"," outline: non "}",".blocklyWidgetDiv .goog-menuitem-disabled .goog-menuitem-icon {"," opacity: 0.3;"," -moz-opacity: 0.3;"," filter: alpha(opacity=30);","}",".blocklyWidgetDiv .goog-menuitem-highlight,",".blocklyWidgetDiv .goog-menuitem-hover {"," background-color: #d6e9f8;"," border-color: #d6e9f8;"," border-style: dotted;"," border-width: 1px 0;"," padding-bottom: 3px;"," padding-top: 3px;","}",".blocklyWidgetDiv .goog-menuitem-checkbox,",".blocklyWidgetDiv .goog-menuitem-icon {"," background-repeat: no-repeat;", " height: 16px;"," left: 6px;"," position: absolute;"," right: auto;"," vertical-align: middle;"," width: 16px;","}",".blocklyWidgetDiv .goog-menuitem-rtl .goog-menuitem-checkbox,",".blocklyWidgetDiv .goog-menuitem-rtl .goog-menuitem-icon {"," left: auto;"," right: 6px;","}",".blocklyWidgetDiv .goog-option-selected .goog-menuitem-checkbox,",".blocklyWidgetDiv .goog-option-selected .goog-menuitem-icon {"," background: url(//ssl.gstatic.com/editor/editortoolbar.png) no-repeat -512px 0;","}", ".blocklyWidgetDiv .goog-menuitem-accel {"," color: #999;"," direction: ltr;"," left: auto;"," padding: 0 6px;"," position: absolute;"," right: 0;"," text-align: right;","}",".blocklyWidgetDiv .goog-menuitem-rtl .goog-menuitem-accel {"," left: 0;"," right: auto;"," text-align: left;","}",".blocklyWidgetDiv .goog-menuitem-mnemonic-hint {"," text-decoration: underline;","}",".blocklyWidgetDiv .goog-menuitem-mnemonic-separator {"," color: #999;"," font-size: 12px;"," padding-left: 4px;", -"}",".blocklyWidgetDiv .goog-menuseparator {"," border-top: 1px solid #ccc;"," margin: 4px 0;"," padding: 0;","}",""];Blockly.WidgetDiv={};Blockly.WidgetDiv.DIV=null;Blockly.WidgetDiv.owner_=null;Blockly.WidgetDiv.dispose_=null;Blockly.WidgetDiv.createDom=function(){Blockly.WidgetDiv.DIV||(Blockly.WidgetDiv.DIV=goog.dom.createDom("div","blocklyWidgetDiv"),document.body.appendChild(Blockly.WidgetDiv.DIV))};Blockly.WidgetDiv.show=function(a,b,c){Blockly.WidgetDiv.hide();Blockly.WidgetDiv.owner_=a;Blockly.WidgetDiv.dispose_=c;Blockly.WidgetDiv.DIV.style.direction=b?"rtl":"ltr";Blockly.WidgetDiv.DIV.style.display="block"}; +"}",".blocklyWidgetDiv .goog-menuseparator {"," border-top: 1px solid #ccc;"," margin: 4px 0;"," padding: 0;","}",""];Blockly.WidgetDiv={};Blockly.WidgetDiv.DIV=null;Blockly.WidgetDiv.owner_=null;Blockly.WidgetDiv.dispose_=null;Blockly.WidgetDiv.createDom=function(){Blockly.WidgetDiv.DIV||(Blockly.WidgetDiv.DIV=goog.dom.createDom("div","blocklyWidgetDiv"),document.body.appendChild(Blockly.WidgetDiv.DIV))}; +Blockly.WidgetDiv.show=function(a,b,c){Blockly.WidgetDiv.hide();Blockly.WidgetDiv.owner_=a;Blockly.WidgetDiv.dispose_=c;a=goog.style.getViewportPageOffset(document);Blockly.WidgetDiv.DIV.style.top=a.y+"px";Blockly.WidgetDiv.DIV.style.direction=b?"rtl":"ltr";Blockly.WidgetDiv.DIV.style.display="block"}; Blockly.WidgetDiv.hide=function(){Blockly.WidgetDiv.owner_&&(Blockly.WidgetDiv.DIV.style.display="none",Blockly.WidgetDiv.DIV.style.left="",Blockly.WidgetDiv.DIV.style.top="",Blockly.WidgetDiv.DIV.style.height="",Blockly.WidgetDiv.dispose_&&Blockly.WidgetDiv.dispose_(),Blockly.WidgetDiv.owner_=null,Blockly.WidgetDiv.dispose_=null,goog.dom.removeChildren(Blockly.WidgetDiv.DIV))};Blockly.WidgetDiv.isVisible=function(){return!!Blockly.WidgetDiv.owner_}; Blockly.WidgetDiv.hideIfOwner=function(a){Blockly.WidgetDiv.owner_==a&&Blockly.WidgetDiv.hide()};Blockly.WidgetDiv.position=function(a,b,c,d,e){bc.width+d.x&&(a=c.width+d.x):a + * + * * @this Blockly.Block */ init: function() { diff --git a/demos/code/index.html b/demos/code/index.html index 2a42aa617..6c8e47a43 100644 --- a/demos/code/index.html +++ b/demos/code/index.html @@ -192,7 +192,9 @@ - + + + diff --git a/tests/playground.html b/tests/playground.html index 224ad61b4..f638d4829 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -343,7 +343,9 @@ h1 { - + + + From c413fa167880ee858e48b759535443828351889a Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Sat, 3 Oct 2015 07:45:16 -0700 Subject: [PATCH 64/98] Fix JS and PHP list/text blocks. The length and is_empty blocks can take either text or lists. --- generators/dart/lists.js | 4 ++-- generators/dart/text.js | 4 ++-- generators/javascript/lists.js | 4 ++-- generators/javascript/text.js | 6 +++--- generators/php/lists.js | 17 +++++++++++++---- generators/php/text.js | 15 ++++++++++++--- generators/python/lists.js | 4 ++-- generators/python/text.js | 4 ++-- javascript_compressed.js | 2 +- php_compressed.js | 6 ++++-- 10 files changed, 43 insertions(+), 23 deletions(-) diff --git a/generators/dart/lists.js b/generators/dart/lists.js index 7e61875d2..57ac4dda1 100644 --- a/generators/dart/lists.js +++ b/generators/dart/lists.js @@ -58,14 +58,14 @@ Blockly.Dart['lists_repeat'] = function(block) { }; Blockly.Dart['lists_length'] = function(block) { - // List length. + // String or array length. var argument0 = Blockly.Dart.valueToCode(block, 'VALUE', Blockly.Dart.ORDER_UNARY_POSTFIX) || '[]'; return [argument0 + '.length', Blockly.Dart.ORDER_UNARY_POSTFIX]; }; Blockly.Dart['lists_isEmpty'] = function(block) { - // Is the list empty? + // Is the string null or array empty? var argument0 = Blockly.Dart.valueToCode(block, 'VALUE', Blockly.Dart.ORDER_UNARY_POSTFIX) || '[]'; return [argument0 + '.isEmpty', Blockly.Dart.ORDER_UNARY_POSTFIX]; diff --git a/generators/dart/text.js b/generators/dart/text.js index 11f70a04a..6a06c8241 100644 --- a/generators/dart/text.js +++ b/generators/dart/text.js @@ -68,14 +68,14 @@ Blockly.Dart['text_append'] = function(block) { }; Blockly.Dart['text_length'] = function(block) { - // String length. + // String or array length. var argument0 = Blockly.Dart.valueToCode(block, 'VALUE', Blockly.Dart.ORDER_UNARY_POSTFIX) || '\'\''; return [argument0 + '.length', Blockly.Dart.ORDER_UNARY_POSTFIX]; }; Blockly.Dart['text_isEmpty'] = function(block) { - // Is the string null? + // Is the string null or array empty? var argument0 = Blockly.Dart.valueToCode(block, 'VALUE', Blockly.Dart.ORDER_UNARY_POSTFIX) || '\'\''; return [argument0 + '.isEmpty', Blockly.Dart.ORDER_UNARY_POSTFIX]; diff --git a/generators/javascript/lists.js b/generators/javascript/lists.js index 564a88816..a309a28ea 100644 --- a/generators/javascript/lists.js +++ b/generators/javascript/lists.js @@ -66,14 +66,14 @@ Blockly.JavaScript['lists_repeat'] = function(block) { }; Blockly.JavaScript['lists_length'] = function(block) { - // List length. + // String or array length. var argument0 = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_FUNCTION_CALL) || '[]'; return [argument0 + '.length', Blockly.JavaScript.ORDER_MEMBER]; }; Blockly.JavaScript['lists_isEmpty'] = function(block) { - // Is the list empty? + // Is the string null or array empty? var argument0 = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_MEMBER) || '[]'; return ['!' + argument0 + '.length', Blockly.JavaScript.ORDER_LOGICAL_NOT]; diff --git a/generators/javascript/text.js b/generators/javascript/text.js index 3adb8718d..481aed48a 100644 --- a/generators/javascript/text.js +++ b/generators/javascript/text.js @@ -73,17 +73,17 @@ Blockly.JavaScript['text_append'] = function(block) { }; Blockly.JavaScript['text_length'] = function(block) { - // String length. + // String or array length. var argument0 = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_FUNCTION_CALL) || '\'\''; return [argument0 + '.length', Blockly.JavaScript.ORDER_MEMBER]; }; Blockly.JavaScript['text_isEmpty'] = function(block) { - // Is the string null? + // Is the string null or array empty? var argument0 = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_MEMBER) || '\'\''; - return ['!' + argument0, Blockly.JavaScript.ORDER_LOGICAL_NOT]; + return ['!' + argument0 + '.length', Blockly.JavaScript.ORDER_LOGICAL_NOT]; }; Blockly.JavaScript['text_indexOf'] = function(block) { diff --git a/generators/php/lists.js b/generators/php/lists.js index 02e965e76..1173da554 100644 --- a/generators/php/lists.js +++ b/generators/php/lists.js @@ -66,14 +66,23 @@ Blockly.PHP['lists_repeat'] = function(block) { }; Blockly.PHP['lists_length'] = function(block) { - // List length. + // String or array length. + var functionName = Blockly.PHP.provideFunction_( + 'length', + [ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + '($value) {', + ' if (is_string($value)) {', + ' return strlen($value);', + ' } else {', + ' return count($value);', + ' }', + '}']); var argument0 = Blockly.PHP.valueToCode(block, 'VALUE', - Blockly.PHP.ORDER_FUNCTION_CALL) || 'array()'; - return ['count(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL]; + Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\''; + return [functionName + '(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL]; }; Blockly.PHP['lists_isEmpty'] = function(block) { - // Is the list empty? + // Is the string null or array empty? var argument0 = Blockly.PHP.valueToCode(block, 'VALUE', Blockly.PHP.ORDER_FUNCTION_CALL) || 'array()'; return ['empty(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL]; diff --git a/generators/php/text.js b/generators/php/text.js index 300672cd6..561b4997c 100644 --- a/generators/php/text.js +++ b/generators/php/text.js @@ -73,14 +73,23 @@ Blockly.PHP['text_append'] = function(block) { }; Blockly.PHP['text_length'] = function(block) { - // String length. + // String or array length. + var functionName = Blockly.PHP.provideFunction_( + 'length', + [ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + '($value) {', + ' if (is_string($value)) {', + ' return strlen($value);', + ' } else {', + ' return count($value);', + ' }', + '}']); var argument0 = Blockly.PHP.valueToCode(block, 'VALUE', Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\''; - return ['strlen(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL]; + return [functionName + '(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL]; }; Blockly.PHP['text_isEmpty'] = function(block) { - // Is the string null? + // Is the string null or array empty? var argument0 = Blockly.PHP.valueToCode(block, 'VALUE', Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\''; return ['empty(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL]; diff --git a/generators/python/lists.js b/generators/python/lists.js index 092801849..05ed4d23e 100644 --- a/generators/python/lists.js +++ b/generators/python/lists.js @@ -56,14 +56,14 @@ Blockly.Python['lists_repeat'] = function(block) { }; Blockly.Python['lists_length'] = function(block) { - // List length. + // String or array length. var argument0 = Blockly.Python.valueToCode(block, 'VALUE', Blockly.Python.ORDER_NONE) || '[]'; return ['len(' + argument0 + ')', Blockly.Python.ORDER_FUNCTION_CALL]; }; Blockly.Python['lists_isEmpty'] = function(block) { - // Is the list empty? + // Is the string null or array empty? var argument0 = Blockly.Python.valueToCode(block, 'VALUE', Blockly.Python.ORDER_NONE) || '[]'; var code = 'not len(' + argument0 + ')'; diff --git a/generators/python/text.js b/generators/python/text.js index a418eda11..7d3797b54 100644 --- a/generators/python/text.js +++ b/generators/python/text.js @@ -77,14 +77,14 @@ Blockly.Python['text_append'] = function(block) { }; Blockly.Python['text_length'] = function(block) { - // String length. + // Is the string null or array empty? var argument0 = Blockly.Python.valueToCode(block, 'VALUE', Blockly.Python.ORDER_NONE) || '\'\''; return ['len(' + argument0 + ')', Blockly.Python.ORDER_FUNCTION_CALL]; }; Blockly.Python['text_isEmpty'] = function(block) { - // Is the string null? + // Is the string null or array empty? var argument0 = Blockly.Python.valueToCode(block, 'VALUE', Blockly.Python.ORDER_NONE) || '\'\''; var code = 'not len(' + argument0 + ')'; diff --git a/javascript_compressed.js b/javascript_compressed.js index 35094c1e1..d1b51ae87 100644 --- a/javascript_compressed.js +++ b/javascript_compressed.js @@ -68,7 +68,7 @@ Blockly.JavaScript.procedures_callnoreturn=function(a){for(var b=Blockly.JavaScr Blockly.JavaScript.procedures_ifreturn=function(a){var b="if ("+(Blockly.JavaScript.valueToCode(a,"CONDITION",Blockly.JavaScript.ORDER_NONE)||"false")+") {\n";a.hasReturnValue_?(a=Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_NONE)||"null",b+=" return "+a+";\n"):b+=" return;\n";return b+"}\n"};Blockly.JavaScript.texts={};Blockly.JavaScript.text=function(a){return[Blockly.JavaScript.quote_(a.getFieldValue("TEXT")),Blockly.JavaScript.ORDER_ATOMIC]}; Blockly.JavaScript.text_join=function(a){var b;if(0==a.itemCount_)return["''",Blockly.JavaScript.ORDER_ATOMIC];if(1==a.itemCount_)return b=Blockly.JavaScript.valueToCode(a,"ADD0",Blockly.JavaScript.ORDER_NONE)||"''",["String("+b+")",Blockly.JavaScript.ORDER_FUNCTION_CALL];if(2==a.itemCount_)return b=Blockly.JavaScript.valueToCode(a,"ADD0",Blockly.JavaScript.ORDER_NONE)||"''",a=Blockly.JavaScript.valueToCode(a,"ADD1",Blockly.JavaScript.ORDER_NONE)||"''",["String("+b+") + String("+a+")",Blockly.JavaScript.ORDER_ADDITION]; b=Array(a.itemCount_);for(var c=0;c Date: Sat, 3 Oct 2015 22:56:10 +0200 Subject: [PATCH 65/98] Typo: evironment -> environment. --- demos/code/code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/code/code.js b/demos/code/code.js index cb2a529fa..846c8ce6f 100644 --- a/demos/code/code.js +++ b/demos/code/code.js @@ -387,7 +387,7 @@ Code.init = function() { zoom: {enabled: true} }); - // Add to reserved word list: Local variables in execution evironment (runJS) + // Add to reserved word list: Local variables in execution environment (runJS) // and the infinite loop detection function. Blockly.JavaScript.addReservedWords('code,timeouts,checkTimeout'); From 90e3ccb2b773331aa81463298c2ccb314604ab8c Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Sun, 4 Oct 2015 07:15:18 -0700 Subject: [PATCH 66/98] Add Blockly.BlockSvg.START_HAT option. --- blockly_compressed.js | 23 ++++++++++++----------- core/block_svg.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 315067cde..71da84a84 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -1086,13 +1086,13 @@ Blockly.BlockSvg.prototype.onMouseMove_=function(a){var b=this,c=this.workspace; c.recordDeleteAreas());if(2==Blockly.dragMode_){var g=d.x-b.dragStartXY_.x,d=d.y-b.dragStartXY_.y;f.translate_="translate("+e.x+","+e.y+")";f.setAttribute("transform",f.translate_+f.skew_);for(e=0;e Date: Sun, 4 Oct 2015 17:41:59 -0700 Subject: [PATCH 67/98] Simplify Block factory init. --- demos/blockfactory/factory.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/demos/blockfactory/factory.js b/demos/blockfactory/factory.js index f6a9a5e4d..649a8956c 100644 --- a/demos/blockfactory/factory.js +++ b/demos/blockfactory/factory.js @@ -771,11 +771,8 @@ function init() { BlocklyStorage.retrieveXml(window.location.hash.substring(1), mainWorkspace); } else { - var rootBlock = Blockly.Block.obtain(mainWorkspace, 'factory_base'); - rootBlock.initSvg(); - rootBlock.render(); - rootBlock.setMovable(false); - rootBlock.setDeletable(false); + var xml = ''; + Blockly.Xml.domToWorkspace(mainWorkspace, Blockly.Xml.textToDom(xml)); } mainWorkspace.addChangeListener(updateLanguage); From 18bac530d8b30490bf6cf2d27c28a75464ec30dd Mon Sep 17 00:00:00 2001 From: Ken Cheung Date: Mon, 5 Oct 2015 21:26:16 +0800 Subject: [PATCH 68/98] Refactor duplicated callback function for collapse and expand options --- core/workspace_svg.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/core/workspace_svg.js b/core/workspace_svg.js index e6c62b10a..e4f640948 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -677,19 +677,28 @@ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) { } } - // Option to collapse top blocks. - var collapseOption = {enabled: hasExpandedBlocks}; - collapseOption.text = Blockly.Msg.COLLAPSE_ALL; - collapseOption.callback = function() { + /* + * Option to collapse or expand top blocks + * @param {bool} shouldCollapse whether a block should collapse + * @private + */ + function toggleOption(shouldCollapse) { var ms = 0; for (var i = 0; i < topBlocks.length; i++) { var block = topBlocks[i]; while (block) { - setTimeout(block.setCollapsed.bind(block, true), ms); + setTimeout(block.setCollapsed.bind(block, shouldCollapse), ms); block = block.getNextBlock(); ms += COLLAPSE_DELAY; } } + } + + // Option to collapse top blocks. + var collapseOption = {enabled: hasExpandedBlocks}; + collapseOption.text = Blockly.Msg.COLLAPSE_ALL; + collapseOption.callback = function() { + toggleOption(true); }; menuOptions.push(collapseOption); @@ -697,15 +706,7 @@ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) { var expandOption = {enabled: hasCollapsedBlocks}; expandOption.text = Blockly.Msg.EXPAND_ALL; expandOption.callback = function() { - var ms = 0; - for (var i = 0; i < topBlocks.length; i++) { - var block = topBlocks[i]; - while (block) { - setTimeout(block.setCollapsed.bind(block, false), ms); - block = block.getNextBlock(); - ms += COLLAPSE_DELAY; - } - } + toggleOption(false); }; menuOptions.push(expandOption); } From 1140a6ccf21411292f7184bddae5af13e78ea9ed Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Mon, 5 Oct 2015 16:08:44 -0700 Subject: [PATCH 69/98] Simplify XML parser. --- core/xml.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/xml.js b/core/xml.js index d00decfa0..d7cc991b5 100644 --- a/core/xml.js +++ b/core/xml.js @@ -330,12 +330,14 @@ Blockly.Xml.domToBlockHeadless_ = } var input; - // Find the first 'real' grandchild node (that isn't whitespace). - var firstRealGrandchild = null; + // Find any enclosed blocks. + var childBlockNode = null; for (var j = 0, grandchildNode; grandchildNode = xmlChild.childNodes[j]; j++) { - if (grandchildNode.nodeType != 3 || !grandchildNode.data.match(/^\s*$/)) { - firstRealGrandchild = grandchildNode; + if (grandchildNode.nodeType == 1) { + if (grandchildNode.nodeName.toLowerCase() == 'block') { + childBlockNode = grandchildNode; + } } } @@ -395,10 +397,9 @@ Blockly.Xml.domToBlockHeadless_ = prototypeName); break; } - if (firstRealGrandchild && - firstRealGrandchild.nodeName.toLowerCase() == 'block') { + if (childBlockNode) { blockChild = Blockly.Xml.domToBlockHeadless_(workspace, - firstRealGrandchild, opt_reuseBlock); + childBlockNode, opt_reuseBlock); if (blockChild.outputConnection) { input.connection.connect(blockChild.outputConnection); } else if (blockChild.previousConnection) { @@ -409,8 +410,7 @@ Blockly.Xml.domToBlockHeadless_ = } break; case 'next': - if (firstRealGrandchild && - firstRealGrandchild.nodeName.toLowerCase() == 'block') { + if (childBlockNode) { if (!block.nextConnection) { throw 'Next statement does not exist.'; } else if (block.nextConnection.targetConnection) { @@ -418,7 +418,7 @@ Blockly.Xml.domToBlockHeadless_ = throw 'Next statement is already connected.'; } blockChild = Blockly.Xml.domToBlockHeadless_(workspace, - firstRealGrandchild, opt_reuseBlock); + childBlockNode, opt_reuseBlock); if (!blockChild.previousConnection) { throw 'Next block does not have previous statement.'; } From 799835943a7a79d0cd1488377173cdbd673eacb0 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 6 Oct 2015 18:09:27 -0700 Subject: [PATCH 70/98] Shadow Blocks --- blockly_compressed.js | 54 ++++++------ core/block.js | 21 ++++- core/block_svg.js | 18 ++-- core/connection.js | 95 +++++++++++++++------ core/xml.js | 36 ++++++-- tests/playground.html | 194 ++++++++++++++++++++++++++++++------------ 6 files changed, 303 insertions(+), 115 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 71da84a84..889051b3d 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -879,23 +879,24 @@ this.foreignObject_.appendChild(a);Blockly.bindEvent_(this.textarea_,"mouseup",t Blockly.Comment.prototype.resizeBubble_=function(){var a=this.bubble_.getBubbleSize(),b=2*Blockly.Bubble.BORDER_WIDTH;this.foreignObject_.setAttribute("width",a.width-b);this.foreignObject_.setAttribute("height",a.height-b);this.textarea_.style.width=a.width-b-4+"px";this.textarea_.style.height=a.height-b-4+"px"}; Blockly.Comment.prototype.setVisible=function(a){if(a!=this.isVisible())if(!this.block_.isEditable()&&!this.textarea_||goog.userAgent.IE)Blockly.Warning.prototype.setVisible.call(this,a);else{var b=this.getText(),c=this.getBubbleSize();a?(this.bubble_=new Blockly.Bubble(this.block_.workspace,this.createEditor_(),this.block_.svgPath_,this.iconX_,this.iconY_,this.width_,this.height_),this.bubble_.registerResizeEvent(this,this.resizeBubble_),this.updateColour(),this.text_=null):(this.bubble_.dispose(), this.foreignObject_=this.textarea_=this.bubble_=null);this.setText(b);this.setBubbleSize(c.width,c.height)}};Blockly.Comment.prototype.textareaFocus_=function(a){this.bubble_.promote_();this.textarea_.focus()};Blockly.Comment.prototype.getBubbleSize=function(){return this.isVisible()?this.bubble_.getBubbleSize():{width:this.width_,height:this.height_}};Blockly.Comment.prototype.setBubbleSize=function(a,b){this.textarea_?this.bubble_.setBubbleSize(a,b):(this.width_=a,this.height_=b)}; -Blockly.Comment.prototype.getText=function(){return this.textarea_?this.textarea_.value:this.text_};Blockly.Comment.prototype.setText=function(a){this.textarea_?this.textarea_.value=a:this.text_=a};Blockly.Comment.prototype.dispose=function(){this.block_.comment=null;Blockly.Icon.prototype.dispose.call(this)};Blockly.Connection=function(a,b){this.sourceBlock_=a;this.type=b;this.db_=a.workspace.connectionDBList[b];this.dbOpposite_=a.workspace.connectionDBList[Blockly.OPPOSITE_TYPE[b]];this.hidden_=!this.db_};Blockly.Connection.prototype.targetConnection=null;Blockly.Connection.prototype.check_=null;Blockly.Connection.prototype.x_=0;Blockly.Connection.prototype.y_=0;Blockly.Connection.prototype.inDB_=!1; +Blockly.Comment.prototype.getText=function(){return this.textarea_?this.textarea_.value:this.text_};Blockly.Comment.prototype.setText=function(a){this.textarea_?this.textarea_.value=a:this.text_=a};Blockly.Comment.prototype.dispose=function(){this.block_.comment=null;Blockly.Icon.prototype.dispose.call(this)};Blockly.Connection=function(a,b){this.sourceBlock_=a;this.type=b;this.db_=a.workspace.connectionDBList[b];this.dbOpposite_=a.workspace.connectionDBList[Blockly.OPPOSITE_TYPE[b]];this.hidden_=!this.db_};Blockly.Connection.prototype.targetConnection=null;Blockly.Connection.prototype.check_=null;Blockly.Connection.prototype.shadowDom_=null;Blockly.Connection.prototype.x_=0;Blockly.Connection.prototype.y_=0;Blockly.Connection.prototype.inDB_=!1; Blockly.Connection.prototype.dispose=function(){if(this.targetConnection)throw"Disconnect connection before disposing of it.";this.inDB_&&this.db_.removeConnection_(this);Blockly.highlightedConnection_==this&&(Blockly.highlightedConnection_=null);Blockly.localConnection_==this&&(Blockly.localConnection_=null);this.dbOpposite_=this.db_=null};Blockly.Connection.prototype.isSuperior=function(){return this.type==Blockly.INPUT_VALUE||this.type==Blockly.NEXT_STATEMENT}; Blockly.Connection.prototype.connect=function(a){if(this.sourceBlock_==a.sourceBlock_)throw"Attempted to connect a block to itself.";if(this.sourceBlock_.workspace!==a.sourceBlock_.workspace)throw"Blocks are on different workspaces.";if(Blockly.OPPOSITE_TYPE[this.type]!=a.type)throw"Attempt to connect incompatible types.";if(this.type==Blockly.INPUT_VALUE||this.type==Blockly.OUTPUT_VALUE){if(this.targetConnection)throw"Source connection already connected (value).";if(a.targetConnection){var b=a.targetBlock(); -b.setParent(null);if(!b.outputConnection)throw"Orphan block does not have an output connection.";for(var c=this.sourceBlock_;c=Blockly.Connection.singleConnection_(c,b);)if(c.targetBlock())c=c.targetBlock();else{c.connect(b.outputConnection);b=null;break}b&&setTimeout(function(){b.outputConnection.bumpAwayFrom_(a)},Blockly.BUMP_DELAY)}}else{if(this.targetConnection)throw"Source connection already connected (block).";if(a.targetConnection){if(this.type!=Blockly.PREVIOUS_STATEMENT)throw"Can only do a mid-stack connection with the top of a block."; -b=a.targetBlock();b.setParent(null);if(!b.previousConnection)throw"Orphan block does not have a previous connection.";for(c=this.sourceBlock_;c.nextConnection;)if(c.nextConnection.targetConnection)c=c.getNextBlock();else{b.previousConnection.checkType_(c.nextConnection)&&(c.nextConnection.connect(b.previousConnection),b=null);break}b&&setTimeout(function(){b.previousConnection.bumpAwayFrom_(a)},Blockly.BUMP_DELAY)}}var d;this.isSuperior()?(c=this.sourceBlock_,d=a.sourceBlock_):(c=a.sourceBlock_,d= -this.sourceBlock_);this.targetConnection=a;a.targetConnection=this;d.setParent(c);c.rendered&&c.updateDisabled();d.rendered&&d.updateDisabled();c.rendered&&d.rendered&&(this.type==Blockly.NEXT_STATEMENT||this.type==Blockly.PREVIOUS_STATEMENT?d.render():c.render())};Blockly.Connection.singleConnection_=function(a,b){for(var c=!1,d=0;d"!=d.slice(-2)&&(b+=" ")}a=a.join("\n");a=a.replace(/(<(\w+)\b[^>]*>[^\n]*)\n *<\/\2>/g,"$1");return a.replace(/^\n/,"")}; Blockly.Xml.textToDom=function(a){a=(new DOMParser).parseFromString(a,"text/xml");if(!a||!a.firstChild||"xml"!=a.firstChild.nodeName.toLowerCase()||a.firstChild!==a.lastChild)throw"Blockly.Xml.textToDom did not obtain a valid XML tree.";return a.firstChild}; Blockly.Xml.domToWorkspace=function(a,b){var c;a.RTL&&(c=a.getWidth());Blockly.Field.startCache();for(var d=b.childNodes.length,e=0;ethis.workspace.scale)){var a=Blockly.getSvgXY_(this.svgGroup_,this.workspace);this.outputConnection?(a.x+=(this.RTL?3:-3)*this.workspace.scale,a.y+=13*this.workspace.scale):this.previousConnection&&(a.x+=(this.RTL?-23:23)*this.workspace.scale,a.y+=3*this.workspace.scale);a=Blockly.createSvgElement("circle",{cx:a.x,cy:a.y,r:0,fill:"none",stroke:"#888","stroke-width":10},this.workspace.options.svg);Blockly.BlockSvg.connectionUiStep_(a, new Date,this.workspace.scale)}};Blockly.BlockSvg.connectionUiStep_=function(a,b,c){var d=(new Date-b)/150;1this.workspace.scale)){var a=this.getHeightWidth().height,a=Math.atan(10/a)/Math.PI*180;this.RTL||(a*=-1);Blockly.BlockSvg.disconnectUiStep_(this.svgGroup_,a,new Date)}}; Blockly.BlockSvg.disconnectUiStep_=function(a,b,c){var d=(new Date-c)/200;1 level. It's all whitespace anyway. continue; } var input; - // Find any enclosed blocks. + // Find any enclosed blocks or shadows in this tag. var childBlockNode = null; + var childShadowNode = null; + var shadowActive = false; for (var j = 0, grandchildNode; grandchildNode = xmlChild.childNodes[j]; j++) { if (grandchildNode.nodeType == 1) { if (grandchildNode.nodeName.toLowerCase() == 'block') { childBlockNode = grandchildNode; + } else if (grandchildNode.nodeName.toLowerCase() == 'shadow') { + childShadowNode = grandchildNode; } } } + // Use the shadow block if there is no child block. + if (!childBlockNode && childShadowNode) { + childBlockNode = childShadowNode; + shadowActive = true; + } var name = xmlChild.getAttribute('name'); switch (xmlChild.nodeName.toLowerCase()) { @@ -397,6 +414,9 @@ Blockly.Xml.domToBlockHeadless_ = prototypeName); break; } + if (childShadowNode) { + input.connection.setShadowDom(childShadowNode); + } if (childBlockNode) { blockChild = Blockly.Xml.domToBlockHeadless_(workspace, childBlockNode, opt_reuseBlock); @@ -410,6 +430,9 @@ Blockly.Xml.domToBlockHeadless_ = } break; case 'next': + if (childShadowNode && block.nextConnection) { + block.nextConnection.setShadowDom(childShadowNode); + } if (childBlockNode) { if (!block.nextConnection) { throw 'Next statement does not exist.'; @@ -455,6 +478,9 @@ Blockly.Xml.domToBlockHeadless_ = if (collapsed) { block.setCollapsed(collapsed == 'true'); } + if (xmlBlock.nodeName.toLowerCase() == 'shadow') { + block.setShadow(true); + } // Give the block a chance to clean up any initial inputs. if (block.validate) { block.validate(); diff --git a/tests/playground.html b/tests/playground.html index f638d4829..849725b3e 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -233,27 +233,27 @@ h1 { - + 10 - + - + 1 - + - + 10 - + - + 1 - + @@ -261,43 +261,94 @@ h1 { - - - - - - - - + + + 1 - + + + + + 1 + - - - - - - + + + + 9 + + + + + + + 45 + + + + + + + + 0 + + + + + + 1 - + + + + + + + 3.1 + + + + + + + + 64 + + + + + 10 + + + + + + + 50 + + + + + 1 + - + 100 - + - + 1 - + - + 100 - + @@ -307,17 +358,34 @@ h1 { - + + + + + + + abc + + + + + + + + - - text + + + abc + + @@ -333,12 +401,32 @@ h1 { - - - + + + + abc + + + + + + + abc + + + + + + + abc + + + - + + abc + @@ -349,9 +437,9 @@ h1 { - + 5 - + @@ -386,9 +474,9 @@ h1 { - + , - + @@ -397,36 +485,36 @@ h1 { - + 100 - + - + 50 - + - + 0 - + - + #ff0000 - + - + #3333ff - + - + 0.5 - + From 701ae603b751730944c60c1cae94a3e1616d6423 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 9 Oct 2015 13:53:14 -0700 Subject: [PATCH 71/98] Fix headless connections. --- blockly_compressed.js | 9 +++++---- core/connection.js | 32 ++++++++++++++++++++++++++++---- core/workspace_svg.js | 6 +++--- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 889051b3d..50d3a3ec8 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -879,8 +879,9 @@ this.foreignObject_.appendChild(a);Blockly.bindEvent_(this.textarea_,"mouseup",t Blockly.Comment.prototype.resizeBubble_=function(){var a=this.bubble_.getBubbleSize(),b=2*Blockly.Bubble.BORDER_WIDTH;this.foreignObject_.setAttribute("width",a.width-b);this.foreignObject_.setAttribute("height",a.height-b);this.textarea_.style.width=a.width-b-4+"px";this.textarea_.style.height=a.height-b-4+"px"}; Blockly.Comment.prototype.setVisible=function(a){if(a!=this.isVisible())if(!this.block_.isEditable()&&!this.textarea_||goog.userAgent.IE)Blockly.Warning.prototype.setVisible.call(this,a);else{var b=this.getText(),c=this.getBubbleSize();a?(this.bubble_=new Blockly.Bubble(this.block_.workspace,this.createEditor_(),this.block_.svgPath_,this.iconX_,this.iconY_,this.width_,this.height_),this.bubble_.registerResizeEvent(this,this.resizeBubble_),this.updateColour(),this.text_=null):(this.bubble_.dispose(), this.foreignObject_=this.textarea_=this.bubble_=null);this.setText(b);this.setBubbleSize(c.width,c.height)}};Blockly.Comment.prototype.textareaFocus_=function(a){this.bubble_.promote_();this.textarea_.focus()};Blockly.Comment.prototype.getBubbleSize=function(){return this.isVisible()?this.bubble_.getBubbleSize():{width:this.width_,height:this.height_}};Blockly.Comment.prototype.setBubbleSize=function(a,b){this.textarea_?this.bubble_.setBubbleSize(a,b):(this.width_=a,this.height_=b)}; -Blockly.Comment.prototype.getText=function(){return this.textarea_?this.textarea_.value:this.text_};Blockly.Comment.prototype.setText=function(a){this.textarea_?this.textarea_.value=a:this.text_=a};Blockly.Comment.prototype.dispose=function(){this.block_.comment=null;Blockly.Icon.prototype.dispose.call(this)};Blockly.Connection=function(a,b){this.sourceBlock_=a;this.type=b;this.db_=a.workspace.connectionDBList[b];this.dbOpposite_=a.workspace.connectionDBList[Blockly.OPPOSITE_TYPE[b]];this.hidden_=!this.db_};Blockly.Connection.prototype.targetConnection=null;Blockly.Connection.prototype.check_=null;Blockly.Connection.prototype.shadowDom_=null;Blockly.Connection.prototype.x_=0;Blockly.Connection.prototype.y_=0;Blockly.Connection.prototype.inDB_=!1; -Blockly.Connection.prototype.dispose=function(){if(this.targetConnection)throw"Disconnect connection before disposing of it.";this.inDB_&&this.db_.removeConnection_(this);Blockly.highlightedConnection_==this&&(Blockly.highlightedConnection_=null);Blockly.localConnection_==this&&(Blockly.localConnection_=null);this.dbOpposite_=this.db_=null};Blockly.Connection.prototype.isSuperior=function(){return this.type==Blockly.INPUT_VALUE||this.type==Blockly.NEXT_STATEMENT}; +Blockly.Comment.prototype.getText=function(){return this.textarea_?this.textarea_.value:this.text_};Blockly.Comment.prototype.setText=function(a){this.textarea_?this.textarea_.value=a:this.text_=a};Blockly.Comment.prototype.dispose=function(){this.block_.comment=null;Blockly.Icon.prototype.dispose.call(this)};Blockly.Connection=function(a,b){this.sourceBlock_=a;this.type=b;a.workspace.connectionDBList&&(this.db_=a.workspace.connectionDBList[b],this.dbOpposite_=a.workspace.connectionDBList[Blockly.OPPOSITE_TYPE[b]],this.hidden_=!this.db_)};Blockly.Connection.prototype.targetConnection=null;Blockly.Connection.prototype.check_=null;Blockly.Connection.prototype.shadowDom_=null;Blockly.Connection.prototype.x_=0;Blockly.Connection.prototype.y_=0;Blockly.Connection.prototype.inDB_=!1; +Blockly.Connection.prototype.db_=null;Blockly.Connection.prototype.dbOpposite_=null;Blockly.Connection.prototype.hidden_=null;Blockly.Connection.prototype.dispose=function(){if(this.targetConnection)throw"Disconnect connection before disposing of it.";this.inDB_&&this.db_.removeConnection_(this);Blockly.highlightedConnection_==this&&(Blockly.highlightedConnection_=null);Blockly.localConnection_==this&&(Blockly.localConnection_=null);this.dbOpposite_=this.db_=null}; +Blockly.Connection.prototype.isSuperior=function(){return this.type==Blockly.INPUT_VALUE||this.type==Blockly.NEXT_STATEMENT}; Blockly.Connection.prototype.connect=function(a){if(this.sourceBlock_==a.sourceBlock_)throw"Attempted to connect a block to itself.";if(this.sourceBlock_.workspace!==a.sourceBlock_.workspace)throw"Blocks are on different workspaces.";if(Blockly.OPPOSITE_TYPE[this.type]!=a.type)throw"Attempt to connect incompatible types.";if(this.type==Blockly.INPUT_VALUE||this.type==Blockly.OUTPUT_VALUE){if(this.targetConnection)throw"Source connection already connected (value).";if(a.targetConnection){var b=a.targetBlock(); b.setParent(null);if(b.isShadow())a.setShadowDom(Blockly.Xml.blockToDom_(b)),b.dispose();else{if(!b.outputConnection)throw"Orphan block does not have an output connection.";for(var c=this.sourceBlock_,d;d=Blockly.Connection.singleConnection_(c,b);)if(c=d.targetBlock(),!c||c.isShadow()){b.outputConnection.connect(d);b=null;break}b&&setTimeout(function(){b.outputConnection.bumpAwayFrom_(a)},Blockly.BUMP_DELAY)}}}else{if(this.targetConnection)throw"Source connection already connected (block).";if(a.targetConnection){if(this.type!= Blockly.PREVIOUS_STATEMENT)throw"Can only do a mid-stack connection with the top of a block.";b=a.targetBlock();b.setParent(null);if(!b.previousConnection)throw"Orphan block does not have a previous connection.";for(c=this.sourceBlock_;c.nextConnection;)if(c.nextConnection.targetConnection)c=c.getNextBlock();else{b.previousConnection.checkType_(c.nextConnection)&&(c.nextConnection.connect(b.previousConnection),b=null);break}b&&setTimeout(function(){b.previousConnection.bumpAwayFrom_(a)},Blockly.BUMP_DELAY)}}this.isSuperior()? @@ -999,8 +1000,8 @@ Blockly.WorkspaceSvg.prototype.onMouseDown_=function(a){this.markFocused();Block a.clientY,this.startDragMetrics=this.getMetrics(),this.startScrollX=this.scrollX,this.startScrollY=this.scrollY,"mouseup"in Blockly.bindEvent_.TOUCH_MAP&&(Blockly.onTouchUpWrapper_=Blockly.bindEvent_(document,"mouseup",null,Blockly.onMouseUp_)),Blockly.onMouseMoveWrapper_=Blockly.bindEvent_(document,"mousemove",null,Blockly.onMouseMove_)),a.stopPropagation())}; Blockly.WorkspaceSvg.prototype.startDrag=function(a,b,c){a=Blockly.mouseToSvg(a,this.options.svg);a.x/=this.scale;a.y/=this.scale;this.dragDeltaX_=b-a.x;this.dragDeltaY_=c-a.y};Blockly.WorkspaceSvg.prototype.moveDrag=function(a){a=Blockly.mouseToSvg(a,this.options.svg);a.x/=this.scale;a.y/=this.scale;return new goog.math.Coordinate(this.dragDeltaX_+a.x,this.dragDeltaY_+a.y)}; Blockly.WorkspaceSvg.prototype.onMouseWheel_=function(a){Blockly.terminateDrag_();var b=0