diff --git a/blockly_compressed.js b/blockly_compressed.js index 64a399a94..3969fbf68 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -851,7 +851,7 @@ goog.cssom.getAllCss_=function(a,b){for(var c=[],d=goog.cssom.getAllCssStyleShee // Copyright 2013 Google Inc. Apache License 2.0 var Blockly={Blocks:{}};Blockly.Blocks.uidCounter_=0;Blockly.Blocks.genUid=function(){var a=(++Blockly.Blocks.uidCounter_).toString();return Blockly.Realtime.isEnabled()?Blockly.Realtime.genUid(a):a}; // Copyright 2012 Google Inc. Apache License 2.0 -Blockly.Workspace=function(a){this.topBlocks_=[];this.options=a||{};this.RTL=!!this.options.RTL};Blockly.Workspace.prototype.rendered=!1;Blockly.Workspace.prototype.dispose=function(){this.clear()};Blockly.Workspace.SCAN_ANGLE=3;Blockly.Workspace.prototype.addTopBlock=function(a){this.topBlocks_.push(a);this.fireChangeEvent()}; +Blockly.Workspace=function(a){this.options=a||{};this.RTL=!!this.options.RTL;this.topBlocks_=[]};Blockly.Workspace.prototype.rendered=!1;Blockly.Workspace.prototype.dispose=function(){this.clear()};Blockly.Workspace.SCAN_ANGLE=3;Blockly.Workspace.prototype.addTopBlock=function(a){this.topBlocks_.push(a);this.fireChangeEvent()}; Blockly.Workspace.prototype.removeTopBlock=function(a){for(var b=!1,c,d=0;c=this.topBlocks_[d];d++)if(c==a){this.topBlocks_.splice(d,1);b=!0;break}if(!b)throw"Block not present in workspace's list of top-most blocks.";this.fireChangeEvent()}; Blockly.Workspace.prototype.getTopBlocks=function(a){var b=[].concat(this.topBlocks_);if(a&&1c.viewWidth&&(a=this.anchorX_-c.viewLeft-c.viewWidth):this.anchorX_+ac.viewWidth&&(a=this.anchorX_-c.viewLeft-c.viewWidth):this.anchorX_+ae&&(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)}; @@ -876,13 +876,13 @@ Blockly.Bubble.prototype.dispose=function(){Blockly.Bubble.unbindDragEvents_();g 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){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)}}; -Blockly.Icon.prototype.renderIcon=function(a){if(this.collapseHidden&&this.block_.isCollapsed())return this.iconGroup_.setAttribute("display","none"),a;this.iconGroup_.setAttribute("display","block");var b=this.SIZE;this.block_.RTL&&(a-=b);this.iconGroup_.setAttribute("transform","translate("+a+", 5)");this.computeIconLocation();return a=this.block_.RTL?a-Blockly.BlockSvg.SEP_SPACE_X:a+(b+Blockly.BlockSvg.SEP_SPACE_X)}; +Blockly.Icon.prototype.renderIcon=function(a){if(this.collapseHidden&&this.block_.isCollapsed())return this.iconGroup_.setAttribute("display","none"),a;this.iconGroup_.setAttribute("display","block");var b=this.SIZE;this.block_.RTL&&(a-=b);this.iconGroup_.setAttribute("transform","translate("+a+",5)");this.computeIconLocation();return a=this.block_.RTL?a-Blockly.BlockSvg.SEP_SPACE_X:a+(b+Blockly.BlockSvg.SEP_SPACE_X)}; Blockly.Icon.prototype.setIconLocation=function(a,b){this.iconX_=a;this.iconY_=b;this.isVisible()&&this.bubble_.setAnchorLocation(a,b)};Blockly.Icon.prototype.computeIconLocation=function(){var a=this.block_.getRelativeToSurfaceXY(),b=Blockly.getRelativeXY_(this.iconGroup_),c=a.x+b.x+this.SIZE/2,a=a.y+b.y+this.SIZE/2;c===this.iconX_&&a===this.iconY_||this.setIconLocation(c,a)};Blockly.Icon.prototype.getIconLocation=function(){return{x:this.iconX_,y:this.iconY_}}; // Copyright 2011 Google Inc. Apache License 2.0 Blockly.Comment=function(a){Blockly.Comment.superClass_.constructor.call(this,a);this.createIcon()};goog.inherits(Blockly.Comment,Blockly.Icon);Blockly.Comment.prototype.png_="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAANyAAADcgBffIlqAAAAAd0SU1FB98DGgAnBf0Xj5sAAAIBSURBVDjLjZO9SxxRFMXPrFkWl2UFYSOIRtF210YtAiH/gGATRNZFgo19IBaB9Ipgk3SiEoKQgI19JIVgGaOIgpWJEAV1kZk3b1ad0V+KRYIzk5ALh1ecc88978tRSgHPg0Bjvq/BbFalMNR5oaBv+bzWHMfZjOudWPOg6+pDva6elRXlt7fVcnYmPX4sDQ3pdmpKQXu7frS16aXjON8T06OIMWOwtRp3jgNSEpkMTE5y5/v4UcSLePxnroutVNKb4xgYANfFAk/vDbLG8Gtk5P8M7jE6CsZwDDwSMLm5iYmLlpbg4ABOTmBjA4aHk0ZbWxigposLvlarScH5OSwvw9oaABwdJTW1GtTrfJHnUe/uTgqKxeZaKEAUgTEQP/CeHvA8LhRFhLlc+r6zWVhfbyaZn0/yuRxEEaGCAK9USjdZWGgarK5CS0uS7+gAa3EzjYaOy2WlludJi4vSzIx0e5vky2Xp6ko/M4WCPleruk4zsVa6vJSur9OHTEzoqljUJwEdQYDf25uMe3jY3E5fX5Lr7wdr8YGSJCkIeL23h9/a+lA4Pg7T039u6h75POzv4wcBrx5Ec11Wd3bwOzv//VK7umB3F991+Zj2/R1reWstdnaWm3L5YXOlAnNz3FiLbTR4Azj6WwFPjOG953EahoT1On4YEnoep8bwDuiO9/wG1sM4kG8A4fUAAAAASUVORK5CYII="; Blockly.Comment.prototype.text_="";Blockly.Comment.prototype.width_=160;Blockly.Comment.prototype.height_=80; Blockly.Comment.prototype.createEditor_=function(){this.foreignObject_=Blockly.createSvgElement("foreignObject",{x:Blockly.Bubble.BORDER_WIDTH,y:Blockly.Bubble.BORDER_WIDTH},null);var a=document.createElementNS(Blockly.HTML_NS,"body");a.setAttribute("xmlns",Blockly.HTML_NS);a.className="blocklyMinimalBody";this.textarea_=document.createElementNS(Blockly.HTML_NS,"textarea");this.textarea_.className="blocklyCommentTextarea";this.textarea_.setAttribute("dir",this.block_.RTL?"RTL":"LTR");a.appendChild(this.textarea_); -this.foreignObject_.appendChild(a);Blockly.bindEvent_(this.textarea_,"mouseup",this,this.textareaFocus_);return this.foreignObject_};Blockly.Comment.prototype.updateEditable=function(){this.isVisible()&&(this.setVisible(!1),this.setVisible(!0));Blockly.Icon.prototype.updateEditable.call(this)}; +this.foreignObject_.appendChild(a);Blockly.bindEvent_(this.textarea_,"mouseup",this,this.textareaFocus_);Blockly.bindEvent_(this.textarea_,"wheel",this,function(a){a.stopPropagation()});return this.foreignObject_};Blockly.Comment.prototype.updateEditable=function(){this.isVisible()&&(this.setVisible(!1),this.setVisible(!0));Blockly.Icon.prototype.updateEditable.call(this)}; 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)}; @@ -897,8 +897,8 @@ Blockly.Connection.prototype.targetBlock=function(){return this.targetConnection 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.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)}}; +{"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;bthis.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_)}; Blockly.Tooltip.onMouseOver_=function(a){for(a=a.target;!goog.isString(a.tooltip)&&!goog.isFunction(a.tooltip);)a=a.tooltip;Blockly.Tooltip.element_!=a&&(Blockly.Tooltip.hide(),Blockly.Tooltip.poisonedElement_=null,Blockly.Tooltip.element_=a);clearTimeout(Blockly.Tooltip.mouseOutPid_)};Blockly.Tooltip.onMouseOut_=function(a){Blockly.Tooltip.mouseOutPid_=setTimeout(function(){Blockly.Tooltip.element_=null;Blockly.Tooltip.poisonedElement_=null;Blockly.Tooltip.hide()},1);clearTimeout(Blockly.Tooltip.showPid_)}; -Blockly.Tooltip.onMouseMove_=function(a){if(Blockly.Tooltip.element_&&Blockly.Tooltip.element_.tooltip&&0==Blockly.dragMode_&&!Blockly.WidgetDiv.isVisible())if(Blockly.Tooltip.visible){var b=Blockly.Tooltip.lastY_-a.pageY;Math.sqrt(Math.pow(Blockly.Tooltip.lastX_-a.pageX,2)+Math.pow(b,2))>Blockly.Tooltip.RADIUS_OK&&Blockly.Tooltip.hide()}else Blockly.Tooltip.poisonedElement_!=Blockly.Tooltip.element_&&(clearTimeout(Blockly.Tooltip.showPid_),Blockly.Tooltip.lastX_=a.pageX,Blockly.Tooltip.lastY_=a.pageY, -Blockly.Tooltip.showPid_=setTimeout(Blockly.Tooltip.show_,Blockly.Tooltip.HOVER_MS))};Blockly.Tooltip.hide=function(){Blockly.Tooltip.visible&&(Blockly.Tooltip.visible=!1,Blockly.Tooltip.DIV&&(Blockly.Tooltip.DIV.style.display="none"));clearTimeout(Blockly.Tooltip.showPid_)}; +Blockly.Tooltip.onMouseMove_=function(a){if(Blockly.Tooltip.element_&&Blockly.Tooltip.element_.tooltip&&0==Blockly.dragMode_&&!Blockly.WidgetDiv.isVisible())if(Blockly.Tooltip.visible){var b=Blockly.Tooltip.lastX_-a.pageX;a=Blockly.Tooltip.lastY_-a.pageY;Math.sqrt(b*b+a*a)>Blockly.Tooltip.RADIUS_OK&&Blockly.Tooltip.hide()}else Blockly.Tooltip.poisonedElement_!=Blockly.Tooltip.element_&&(clearTimeout(Blockly.Tooltip.showPid_),Blockly.Tooltip.lastX_=a.pageX,Blockly.Tooltip.lastY_=a.pageY,Blockly.Tooltip.showPid_= +setTimeout(Blockly.Tooltip.show_,Blockly.Tooltip.HOVER_MS))};Blockly.Tooltip.hide=function(){Blockly.Tooltip.visible&&(Blockly.Tooltip.visible=!1,Blockly.Tooltip.DIV&&(Blockly.Tooltip.DIV.style.display="none"));clearTimeout(Blockly.Tooltip.showPid_)}; Blockly.Tooltip.show_=function(){Blockly.Tooltip.poisonedElement_=Blockly.Tooltip.element_;if(Blockly.Tooltip.DIV){goog.dom.removeChildren(Blockly.Tooltip.DIV);var a=Blockly.Tooltip.element_.tooltip;goog.isFunction(a)&&(a=a());for(var a=Blockly.Tooltip.wrap_(a,Blockly.Tooltip.LIMIT),a=a.split("\n"),b=0;bb.height+window.scrollY&&(d-=Blockly.Tooltip.DIV.offsetHeight+2*Blockly.Tooltip.OFFSET_Y);a?c=Math.max(Blockly.Tooltip.MARGINS-window.scrollX,c):c+Blockly.Tooltip.DIV.offsetWidth>b.width+window.scrollX-2*Blockly.Tooltip.MARGINS&& (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"}}; @@ -941,26 +941,33 @@ Blockly.Scrollbar=function(a,b,c){this.workspace_=a;this.pair_=c||!1;this.horizo Blockly.bindEvent_(this.svgBackground_,"mousedown",this,this.onMouseDownBar_);this.onMouseDownKnobWrapper_=Blockly.bindEvent_(this.svgKnob_,"mousedown",this,this.onMouseDownKnob_)};Blockly.Scrollbar.scrollbarThickness=15;goog.events.BrowserFeature.TOUCH_ENABLED&&(Blockly.Scrollbar.scrollbarThickness=25); Blockly.Scrollbar.prototype.dispose=function(){this.onMouseUpKnob_();this.onResizeWrapper_&&(Blockly.unbindEvent_(this.onResizeWrapper_),this.onResizeWrapper_=null);Blockly.unbindEvent_(this.onMouseDownBarWrapper_);this.onMouseDownBarWrapper_=null;Blockly.unbindEvent_(this.onMouseDownKnobWrapper_);this.onMouseDownKnobWrapper_=null;goog.dom.removeNode(this.svgGroup_);this.workspace_=this.svgKnob_=this.svgBackground_=this.svgGroup_=null}; Blockly.Scrollbar.prototype.resize=function(a){if(!a&&(a=this.workspace_.getMetrics(),!a))return;if(this.horizontal_){var b=a.viewWidth-1;this.pair_?b-=Blockly.Scrollbar.scrollbarThickness:this.setVisible(b=c+d&&(e+=f);this.svgKnob_.setAttribute(this.horizontal_?"x":"y",this.constrainKnob_(e)); +Blockly.Scrollbar.prototype.onMouseDownBar_=function(a){this.onMouseUpKnob_();if(!Blockly.isRightButton(a)){var b=Blockly.mouseToSvg(a,this.workspace_.options.svg),b=this.horizontal_?b.x:b.y,c=Blockly.getSvgXY_(this.svgKnob_,this.workspace_),c=this.horizontal_?c.x:c.y,d=parseFloat(this.svgKnob_.getAttribute(this.horizontal_?"width":"height")),e=parseFloat(this.svgKnob_.getAttribute(this.horizontal_?"x":"y")),f=.95*d;b<=c?e-=f:b>=c+d&&(e+=f);this.svgKnob_.setAttribute(this.horizontal_?"x":"y",this.constrainKnob_(e)); this.onScroll_()}a.stopPropagation()};Blockly.Scrollbar.prototype.onMouseDownKnob_=function(a){this.onMouseUpKnob_();Blockly.isRightButton(a)||(this.startDragKnob=parseFloat(this.svgKnob_.getAttribute(this.horizontal_?"x":"y")),this.startDragMouse=this.horizontal_?a.clientX:a.clientY,Blockly.Scrollbar.onMouseUpWrapper_=Blockly.bindEvent_(document,"mouseup",this,this.onMouseUpKnob_),Blockly.Scrollbar.onMouseMoveWrapper_=Blockly.bindEvent_(document,"mousemove",this,this.onMouseMoveKnob_));a.stopPropagation()}; Blockly.Scrollbar.prototype.onMouseMoveKnob_=function(a){this.svgKnob_.setAttribute(this.horizontal_?"x":"y",this.constrainKnob_(this.startDragKnob+((this.horizontal_?a.clientX:a.clientY)-this.startDragMouse)));this.onScroll_()}; 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.SPRITE_URL_="media/sprites.png";Blockly.Trashcan.prototype.LID_URL_="media/trashlid.png";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.Trashcan.prototype.left_=0;Blockly.Trashcan.prototype.top_=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_=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.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.Trashcan.prototype.getRect=function(){var a=Blockly.getSvgXY_(this.svgGroup_);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)};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.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.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_); +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.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)}; @@ -976,29 +983,35 @@ d.setMovable("true"==a);(a=b.getAttribute("editable"))&&d.setEditable("true"==a) 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)};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.trashcan=null;Blockly.WorkspaceSvg.prototype.scrollbar=null; -Blockly.WorkspaceSvg.prototype.createDom=function(a){this.svgGroup_=Blockly.createSvgElement("g",{"class":"blocklyWorkspace"},null);a&&(this.svgBackground_=Blockly.createSvgElement("rect",{height:"100%",width:"100%","class":a},this.svgGroup_),"blocklyMainBackground"==a&&(this.svgBackground_.style.fill="url(#"+this.options.gridPattern.id+")"));this.svgBlockCanvas_=Blockly.createSvgElement("g",{"class":"blocklyBlockCanvas"},this.svgGroup_);this.svgBubbleCanvas_=Blockly.createSvgElement("g",{"class":"blocklyBubbleCanvas"}, -this.svgGroup_);this.options.hasTrashcan&&this.addTrashcan_();Blockly.bindEvent_(this.svgGroup_,"mousedown",this,this.onMouseDown_);var b=this;Blockly.bindEvent_(this.svgGroup_,"touchstart",null,function(a){Blockly.longStart_(a,b)});this.options.hasCategories?this.toolbox_=new Blockly.Toolbox(this):this.options.languageTree&&this.addFlyout_();return this.svgGroup_}; -Blockly.WorkspaceSvg.prototype.dispose=function(){this.rendered=!1;Blockly.WorkspaceSvg.superClass_.dispose.call(this);this.svgGroup_&&(goog.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.svgBubbleCanvas_=this.svgBlockCanvas_=null;this.toolbox_&&(this.toolbox_.dispose(),this.toolbox_=null);this.flyout_&&(this.flyout_.dispose(),this.flyout_=null);this.trashcan&&(this.trashcan.dispose(),this.trashcan=null);this.options.parentWorkspace||goog.dom.removeNode(this.options.svg)}; -Blockly.WorkspaceSvg.prototype.addTrashcan_=function(){this.trashcan=new Blockly.Trashcan(this);var a=this.trashcan.createDom();this.svgGroup_.insertBefore(a,this.svgBlockCanvas_);this.trashcan.init()};Blockly.WorkspaceSvg.prototype.addFlyout_=function(){this.flyout_=new Blockly.Flyout({parentWorkspace:this,RTL:this.RTL});this.flyout_.autoClose=!1;var a=this.flyout_.createDom();this.svgGroup_.insertBefore(a,this.svgBlockCanvas_)}; -Blockly.WorkspaceSvg.prototype.resize=function(){this.toolbox_&&this.toolbox_.position();this.flyout_&&this.flyout_.position();this.trashcan&&this.trashcan.position();this.scrollbar&&this.scrollbar.resize()};Blockly.WorkspaceSvg.prototype.getCanvas=function(){return this.svgBlockCanvas_};Blockly.WorkspaceSvg.prototype.getBubbleCanvas=function(){return this.svgBubbleCanvas_}; -Blockly.WorkspaceSvg.prototype.translate=function(a,b){var c="translate("+a+","+b+")";this.svgBlockCanvas_.setAttribute("transform",c);this.svgBubbleCanvas_.setAttribute("transform",c)};Blockly.WorkspaceSvg.prototype.addTopBlock=function(a){Blockly.WorkspaceSvg.superClass_.addTopBlock.call(this,a);Blockly.Realtime.isEnabled()&&!this.options.parentWorkspace&&Blockly.Realtime.addTopBlock(a)}; -Blockly.WorkspaceSvg.prototype.removeTopBlock=function(a){Blockly.WorkspaceSvg.superClass_.removeTopBlock.call(this,a);Blockly.Realtime.isEnabled()&&!this.options.parentWorkspace&&Blockly.Realtime.removeTopBlock(a)};Blockly.WorkspaceSvg.prototype.getWidth=function(){return this.getMetrics().viewWidth}; +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; +Blockly.WorkspaceSvg.prototype.createDom=function(a){this.svgGroup_=Blockly.createSvgElement("g",{"class":"blocklyWorkspace"},null);a&&(this.svgBackground_=Blockly.createSvgElement("rect",{height:"100%",width:"100%","class":a},this.svgGroup_),"blocklyMainBackground"==a&&(this.svgBackground_.style.fill="url(#"+this.options.gridPattern.id+")"));this.svgBlockCanvas_=Blockly.createSvgElement("g",{"class":"blocklyBlockCanvas"},this.svgGroup_,this);this.svgBubbleCanvas_=Blockly.createSvgElement("g",{"class":"blocklyBubbleCanvas"}, +this.svgGroup_,this);this.options.hasTrashcan&&this.addTrashcan_();this.options.zoomOptions&&this.options.zoomOptions.controls&&this.addZoomControls_();Blockly.bindEvent_(this.svgGroup_,"mousedown",this,this.onMouseDown_);var b=this;Blockly.bindEvent_(this.svgGroup_,"touchstart",null,function(a){Blockly.longStart_(a,b)});this.options.zoomOptions&&this.options.zoomOptions.wheel&&Blockly.bindEvent_(this.svgGroup_,"wheel",this,this.onMouseWheel_);this.options.hasCategories?this.toolbox_=new Blockly.Toolbox(this): +this.options.languageTree&&this.addFlyout_();this.updateGridPattern_();return this.svgGroup_}; +Blockly.WorkspaceSvg.prototype.dispose=function(){this.rendered=!1;Blockly.WorkspaceSvg.superClass_.dispose.call(this);this.svgGroup_&&(goog.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.svgBubbleCanvas_=this.svgBlockCanvas_=null;this.toolbox_&&(this.toolbox_.dispose(),this.toolbox_=null);this.flyout_&&(this.flyout_.dispose(),this.flyout_=null);this.trashcan&&(this.trashcan.dispose(),this.trashcan=null);this.zoomControls&&(this.zoomControls.dispose(),this.zoomControls=null);this.options.parentWorkspace|| +goog.dom.removeNode(this.options.svg)};Blockly.WorkspaceSvg.prototype.addTrashcan_=function(){this.trashcan=new Blockly.Trashcan(this);var a=this.trashcan.createDom();this.svgGroup_.insertBefore(a,this.svgBlockCanvas_);this.trashcan.init()};Blockly.WorkspaceSvg.prototype.addZoomControls_=function(){this.zoomControls=new Blockly.ZoomControls(this);var a=this.zoomControls.createDom();this.svgGroup_.appendChild(a);this.zoomControls.init()}; +Blockly.WorkspaceSvg.prototype.addFlyout_=function(){this.flyout_=new Blockly.Flyout({parentWorkspace:this,RTL:this.RTL});this.flyout_.autoClose=!1;var a=this.flyout_.createDom();this.svgGroup_.insertBefore(a,this.svgBlockCanvas_)};Blockly.WorkspaceSvg.prototype.resize=function(){this.toolbox_&&this.toolbox_.position();this.flyout_&&this.flyout_.position();this.trashcan&&this.trashcan.position();this.zoomControls&&this.zoomControls.position();this.scrollbar&&this.scrollbar.resize()}; +Blockly.WorkspaceSvg.prototype.getCanvas=function(){return this.svgBlockCanvas_};Blockly.WorkspaceSvg.prototype.getBubbleCanvas=function(){return this.svgBubbleCanvas_};Blockly.WorkspaceSvg.prototype.translate=function(a,b){var c="translate("+a+","+b+")scale("+this.scale+")";this.svgBlockCanvas_.setAttribute("transform",c);this.svgBubbleCanvas_.setAttribute("transform",c)}; +Blockly.WorkspaceSvg.prototype.addTopBlock=function(a){Blockly.WorkspaceSvg.superClass_.addTopBlock.call(this,a);Blockly.Realtime.isEnabled()&&!this.options.parentWorkspace&&Blockly.Realtime.addTopBlock(a)};Blockly.WorkspaceSvg.prototype.removeTopBlock=function(a){Blockly.WorkspaceSvg.superClass_.removeTopBlock.call(this,a);Blockly.Realtime.isEnabled()&&!this.options.parentWorkspace&&Blockly.Realtime.removeTopBlock(a)};Blockly.WorkspaceSvg.prototype.getWidth=function(){return this.getMetrics().viewWidth}; Blockly.WorkspaceSvg.prototype.setVisible=function(a){this.options.svg.style.display=a?"block":"none";this.toolbox_&&(this.toolbox_.HtmlDiv.style.display=a?"block":"none");a?(this.render(),this.toolbox_&&this.toolbox_.position()):Blockly.hideChaff(!0)};Blockly.WorkspaceSvg.prototype.render=function(){for(var a=this.getAllBlocks(),b=0,c;c=a[b];b++)c.getChildren().length||c.render()}; Blockly.WorkspaceSvg.prototype.traceOn=function(a){this.traceOn_=a;this.traceWrapper_&&(Blockly.unbindEvent_(this.traceWrapper_),this.traceWrapper_=null);a&&(this.traceWrapper_=Blockly.bindEvent_(this.svgBlockCanvas_,"blocklySelectChange",this,function(){this.traceOn_=!1}))}; Blockly.WorkspaceSvg.prototype.highlightBlock=function(a){this.traceOn_&&0!=Blockly.dragMode_&&this.traceOn(!1);if(this.traceOn_){var b=null;if(a&&(b=this.getBlockById(a),!b))return;this.traceOn(!1);b?b.select():Blockly.selected&&Blockly.selected.unselect();var c=this;setTimeout(function(){c.traceOn(!0)},1)}};Blockly.WorkspaceSvg.prototype.fireChangeEvent=function(){this.rendered&&this.svgBlockCanvas_&&Blockly.fireUiEvent(this.svgBlockCanvas_,"blocklyWorkspaceChange")}; Blockly.WorkspaceSvg.prototype.paste=function(a){if(this.rendered&&!(a.getElementsByTagName("block").length>=this.remainingCapacity())){Blockly.terminateDrag_();var b=Blockly.Xml.domToBlock(this,a),c=parseInt(a.getAttribute("x"),10);a=parseInt(a.getAttribute("y"),10);if(!isNaN(c)&&!isNaN(a)){this.RTL&&(c=-c);do{for(var d=!1,e=this.getAllBlocks(),f=0,g;g=e[f];f++)if(g=g.getRelativeToSurfaceXY(),1>=Math.abs(c-g.x)&&1>=Math.abs(a-g.y)){d=!0;break}if(!d)for(e=b.getConnections_(!1),f=0;g=e[f];f++)if(g.closest(Blockly.SNAP_RADIUS, c,a).connection){d=!0;break}d&&(c=this.RTL?c-Blockly.SNAP_RADIUS:c+Blockly.SNAP_RADIUS,a+=2*Blockly.SNAP_RADIUS)}while(d);b.moveBy(c,a)}b.select()}};Blockly.WorkspaceSvg.prototype.recordDeleteAreas=function(){this.deleteAreaTrash_=this.trashcan?this.trashcan.getRect():null;this.deleteAreaToolbox_=this.flyout_?this.flyout_.getRect():this.toolbox_?this.toolbox_.getRect():null}; -Blockly.WorkspaceSvg.prototype.isDeleteArea=function(a){a=Blockly.mouseToSvg(a,this.options.svg);a=new goog.math.Coordinate(a.x,a.y);if(this.deleteAreaTrash_){if(this.deleteAreaTrash_.contains(a))return this.trashcan.setOpen_(!0),Blockly.Css.setCursor(Blockly.Css.Cursor.DELETE),!0;this.trashcan.setOpen_(!1)}if(this.deleteAreaToolbox_&&this.deleteAreaToolbox_.contains(a))return Blockly.Css.setCursor(Blockly.Css.Cursor.DELETE),!0;Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);return!1}; +Blockly.WorkspaceSvg.prototype.isDeleteArea=function(a){a=Blockly.mouseToSvg(a,Blockly.mainWorkspace.options.svg);a=new goog.math.Coordinate(a.x,a.y);if(this.deleteAreaTrash_){if(this.deleteAreaTrash_.contains(a))return this.trashcan.setOpen_(!0),Blockly.Css.setCursor(Blockly.Css.Cursor.DELETE),!0;this.trashcan.setOpen_(!1)}if(this.deleteAreaToolbox_&&this.deleteAreaToolbox_.contains(a))return Blockly.Css.setCursor(Blockly.Css.Cursor.DELETE),!0;Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);return!1}; Blockly.WorkspaceSvg.prototype.onMouseDown_=function(a){this.markFocused();Blockly.isTargetInput_(a)||(Blockly.svgResize(this),Blockly.terminateDrag_(),Blockly.hideChaff(),a.target&&a.target.nodeName&&("svg"==a.target.nodeName.toLowerCase()||a.target==this.svgBackground_)&&Blockly.selected&&!this.options.readOnly&&Blockly.selected.unselect(),Blockly.isRightButton(a)?this.showContextMenu_(a):this.scrollbar&&(Blockly.removeAllRanges(),this.isScrolling=!0,this.startDragMouseX=a.clientX,this.startDragMouseY= 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.showContextMenu_=function(a){if(!this.options.readOnly){var b=[];if(this.options.collapse){for(var c=!1,d=!1,e=this.getTopBlocks(!1),f=0;fthis.options.zoomOptions.maxScale?c=this.options.zoomOptions.maxScale/this.scale:d=b.height&&(k-=g.height);c?g.width>=a.clientX&&(e+=g.width):a.clientX+g.width>=b.width&&(e-=g.width);Blockly.WidgetDiv.position(e,k,b,f,c);d.setAllowAutoFocus(!0);setTimeout(function(){h.focus()},1);Blockly.ContextMenu.currentBlock=null}else Blockly.ContextMenu.hide()}; -Blockly.ContextMenu.hide=function(){Blockly.WidgetDiv.hideIfOwner(Blockly.ContextMenu);Blockly.ContextMenu.currentBlock=null};Blockly.ContextMenu.callbackFactory=function(a,b){return function(){var c=Blockly.Xml.domToBlock(a.workspace,b),d=a.getRelativeToSurfaceXY();d.x=a.RTL?d.x-Blockly.SNAP_RADIUS:d.x+Blockly.SNAP_RADIUS;d.y+=2*Blockly.SNAP_RADIUS;c.moveBy(d.x,d.y);c.select()}};Blockly.BlockSvg=function(){this.svgGroup_=Blockly.createSvgElement("g",{},null);this.svgPathDark_=Blockly.createSvgElement("path",{"class":"blocklyPathDark",transform:"translate(1, 1)"},this.svgGroup_);this.svgPath_=Blockly.createSvgElement("path",{"class":"blocklyPath"},this.svgGroup_);this.svgPathLight_=Blockly.createSvgElement("path",{"class":"blocklyPathLight"},this.svgGroup_);this.svgPath_.tooltip=this;Blockly.Tooltip.bindMouseEvents(this.svgPath_)};goog.inherits(Blockly.BlockSvg,Blockly.Block); -Blockly.BlockSvg.prototype.height=0;Blockly.BlockSvg.prototype.width=0;Blockly.BlockSvg.INLINE=-1; +Blockly.ContextMenu.hide=function(){Blockly.WidgetDiv.hideIfOwner(Blockly.ContextMenu);Blockly.ContextMenu.currentBlock=null};Blockly.ContextMenu.callbackFactory=function(a,b){return function(){var c=Blockly.Xml.domToBlock(a.workspace,b),d=a.getRelativeToSurfaceXY();d.x=a.RTL?d.x-Blockly.SNAP_RADIUS:d.x+Blockly.SNAP_RADIUS;d.y+=2*Blockly.SNAP_RADIUS;c.moveBy(d.x,d.y);c.select()}};Blockly.BlockSvg=function(){this.svgGroup_=Blockly.createSvgElement("g",{},null);this.svgPathDark_=Blockly.createSvgElement("path",{"class":"blocklyPathDark",transform:"translate(1,1)"},this.svgGroup_);this.svgPath_=Blockly.createSvgElement("path",{"class":"blocklyPath"},this.svgGroup_);this.svgPathLight_=Blockly.createSvgElement("path",{"class":"blocklyPathLight"},this.svgGroup_);this.svgPath_.tooltip=this;Blockly.Tooltip.bindMouseEvents(this.svgPath_)};goog.inherits(Blockly.BlockSvg,Blockly.Block); +Blockly.BlockSvg.prototype.height=0;Blockly.BlockSvg.prototype.width=0;Blockly.BlockSvg.prototype.dragStartXY_=null;Blockly.BlockSvg.INLINE=-1; Blockly.BlockSvg.prototype.initSvg=function(){goog.asserts.assert(this.workspace.rendered,"Workspace is headless.");for(var a=0,b;b=this.inputList[a];a++)b.init();this.mutator&&this.mutator.createIcon();this.updateColour();this.updateMovable();if(!this.workspace.options.readOnly&&!this.eventsInit_){Blockly.bindEvent_(this.getSvgRoot(),"mousedown",this,this.onMouseDown_);var c=this;Blockly.bindEvent_(this.getSvgRoot(),"touchstart",null,function(a){Blockly.longStart_(a,c)})}goog.isFunction(this.onchange)&& !this.eventsInit_&&(this.onchangeWrapper_=Blockly.bindEvent_(this.workspace.getCanvas(),"blocklyWorkspaceChange",this,this.onchange));this.eventsInit_=!0;this.getSvgRoot().parentNode||this.workspace.getCanvas().appendChild(this.getSvgRoot())};Blockly.BlockSvg.prototype.select=function(){Blockly.selected&&Blockly.selected.unselect();Blockly.selected=this;this.addSelect();Blockly.fireUiEvent(this.workspace.getCanvas(),"blocklySelectChange")}; Blockly.BlockSvg.prototype.unselect=function(){Blockly.selected=null;this.removeSelect();Blockly.fireUiEvent(this.workspace.getCanvas(),"blocklySelectChange")};Blockly.BlockSvg.prototype.mutator=null;Blockly.BlockSvg.prototype.comment=null;Blockly.BlockSvg.prototype.warning=null;Blockly.BlockSvg.prototype.getIcons=function(){var a=[];this.mutator&&a.push(this.mutator);this.comment&&a.push(this.comment);this.warning&&a.push(this.warning);return a};Blockly.BlockSvg.onMouseUpWrapper_=null; Blockly.BlockSvg.onMouseMoveWrapper_=null; -Blockly.BlockSvg.terminateDrag_=function(){Blockly.BlockSvg.onMouseUpWrapper_&&(Blockly.unbindEvent_(Blockly.BlockSvg.onMouseUpWrapper_),Blockly.BlockSvg.onMouseUpWrapper_=null);Blockly.BlockSvg.onMouseMoveWrapper_&&(Blockly.unbindEvent_(Blockly.BlockSvg.onMouseMoveWrapper_),Blockly.BlockSvg.onMouseMoveWrapper_=null);var a=Blockly.selected;if(2==Blockly.dragMode_&&a){var b=a.getRelativeToSurfaceXY();a.moveConnections_(b.x-a.startDragX,b.y-a.startDragY);delete a.draggedBubbles_;a.setDragging_(!1); -a.render();a.workspace&&a.workspace.options.gridOptions&&a.workspace.options.gridOptions.snap&&goog.Timer.callOnce(a.snapToGrid_,Blockly.BUMP_DELAY/2,a);goog.Timer.callOnce(a.bumpNeighbours_,Blockly.BUMP_DELAY,a);Blockly.fireUiEvent(window,"resize");a.workspace.fireChangeEvent()}Blockly.dragMode_=0;Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN)}; -Blockly.BlockSvg.prototype.setParent=function(a){var b=this.getSvgRoot();if(this.parentBlock_&&b){var c=this.getRelativeToSurfaceXY();this.workspace.getCanvas().appendChild(b);b.setAttribute("transform","translate("+c.x+", "+c.y+")")}Blockly.BlockSvg.superClass_.setParent.call(this,a);a&&(c=this.getRelativeToSurfaceXY(),a.getSvgRoot().appendChild(b),a=this.getRelativeToSurfaceXY(),this.moveConnections_(a.x-c.x,a.y-c.y))}; -Blockly.BlockSvg.prototype.getRelativeToSurfaceXY=function(){var a=0,b=0,c=this.getSvgRoot();if(c){do var d=Blockly.getRelativeXY_(c),a=a+d.x,b=b+d.y,c=c.parentNode;while(c&&c!=this.workspace.getCanvas())}return new goog.math.Coordinate(a,b)};Blockly.BlockSvg.prototype.moveBy=function(a,b){var c=this.getRelativeToSurfaceXY();this.getSvgRoot().setAttribute("transform","translate("+(c.x+a)+", "+(c.y+b)+")");this.moveConnections_(a,b);Blockly.Realtime.blockChanged(this)}; +Blockly.BlockSvg.terminateDrag_=function(){Blockly.BlockSvg.onMouseUpWrapper_&&(Blockly.unbindEvent_(Blockly.BlockSvg.onMouseUpWrapper_),Blockly.BlockSvg.onMouseUpWrapper_=null);Blockly.BlockSvg.onMouseMoveWrapper_&&(Blockly.unbindEvent_(Blockly.BlockSvg.onMouseMoveWrapper_),Blockly.BlockSvg.onMouseMoveWrapper_=null);var a=Blockly.selected;if(2==Blockly.dragMode_&&a){var b=a.getRelativeToSurfaceXY(),b=goog.math.Coordinate.difference(b,a.dragStartXY_);a.moveConnections_(b.x,b.y);delete a.draggedBubbles_; +a.setDragging_(!1);a.render();a.workspace&&a.workspace.options.gridOptions&&a.workspace.options.gridOptions.snap&&goog.Timer.callOnce(a.snapToGrid_,Blockly.BUMP_DELAY/2,a);goog.Timer.callOnce(a.bumpNeighbours_,Blockly.BUMP_DELAY,a);Blockly.fireUiEvent(window,"resize");a.workspace.fireChangeEvent()}Blockly.dragMode_=0;Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN)}; +Blockly.BlockSvg.prototype.setParent=function(a){var b=this.getSvgRoot();if(this.parentBlock_&&b){var c=this.getRelativeToSurfaceXY();this.workspace.getCanvas().appendChild(b);b.setAttribute("transform","translate("+c.x+","+c.y+")")}Blockly.BlockSvg.superClass_.setParent.call(this,a);a&&(c=this.getRelativeToSurfaceXY(),a.getSvgRoot().appendChild(b),a=this.getRelativeToSurfaceXY(),this.moveConnections_(a.x-c.x,a.y-c.y))}; +Blockly.BlockSvg.prototype.getRelativeToSurfaceXY=function(){var a=0,b=0,c=this.getSvgRoot();if(c){do var d=Blockly.getRelativeXY_(c),a=a+d.x,b=b+d.y,c=c.parentNode;while(c&&c!=this.workspace.getCanvas())}return new goog.math.Coordinate(a,b)};Blockly.BlockSvg.prototype.moveBy=function(a,b){var c=this.getRelativeToSurfaceXY();this.getSvgRoot().setAttribute("transform","translate("+(c.x+a)+","+(c.y+b)+")");this.moveConnections_(a,b);Blockly.Realtime.blockChanged(this)}; Blockly.BlockSvg.prototype.snapToGrid_=function(){if(this.workspace&&0==Blockly.dragMode_&&!this.getParent()&&!this.isInFlyout){var a=this.workspace.options.gridOptions.spacing,b=a/2,c=this.getRelativeToSurfaceXY(),d=Math.round((c.x-b)/a)*a+b-c.x,a=Math.round((c.y-b)/a)*a+b-c.y,d=Math.round(d),a=Math.round(a);0==d&&0==a||this.moveBy(d,a)}}; Blockly.BlockSvg.prototype.getHeightWidth=function(){var a=this.height,b=this.width,c=this.getNextBlock();c?(c=c.getHeightWidth(),a+=c.height-4,b=Math.max(b,c.width)):this.nextConnection||this.outputConnection||(a+=2);return{height:a,width:b}}; Blockly.BlockSvg.prototype.setCollapsed=function(a){if(this.collapsed_!=a){for(var b=[],c=0,d;d=this.inputList[c];c++)b.push.apply(b,d.setVisible(!a));if(a){d=this.getIcons();for(c=0;cthis.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= @@ -1073,9 +1086,9 @@ function(){b.setCommentText(null)}):(d.text=Blockly.Msg.ADD_COMMENT,d.callback=f {enabled:!0},d.text=Blockly.Msg.EXPAND_BLOCK,d.callback=function(){b.setCollapsed(!1)}):(d={enabled:!0},d.text=Blockly.Msg.COLLAPSE_BLOCK,d.callback=function(){b.setCollapsed(!0)}),c.push(d));this.workspace.options.disable&&(d={text:this.disabled?Blockly.Msg.ENABLE_BLOCK:Blockly.Msg.DISABLE_BLOCK,enabled:!this.getInheritedDisabled(),callback:function(){b.setDisabled(!b.disabled)}},c.push(d));var d=this.getDescendants().length,f=this.getNextBlock();f&&(d-=f.getDescendants().length);d={text:1==d?Blockly.Msg.DELETE_BLOCK: Blockly.Msg.DELETE_X_BLOCKS.replace("%1",String(d)),enabled:!0,callback:function(){b.dispose(!0,!0)}};c.push(d)}d={enabled:!(goog.isFunction(this.helpUrl)?!this.helpUrl():!this.helpUrl)};d.text=Blockly.Msg.HELP;d.callback=function(){b.showHelp_()};c.push(d);this.customContextMenu&&!b.isInFlyout&&this.customContextMenu(c);Blockly.ContextMenu.show(a,c,this.RTL);Blockly.ContextMenu.currentBlock=this}}; Blockly.BlockSvg.prototype.moveConnections_=function(a,b){if(this.rendered){for(var c=this.getConnections_(!1),d=0;d=a.clientX&&0==a.clientY&&0==a.button)){Blockly.removeAllRanges();var c=a.clientX-b.startDragMouseX,d=a.clientY-b.startDragMouseY;1==Blockly.dragMode_&&Math.sqrt(Math.pow(c,2)+Math.pow(d,2))>Blockly.DRAG_RADIUS&&(Blockly.dragMode_=2,Blockly.longStop_(),b.setParent(null),b.setDragging_(!0),b.workspace.recordDeleteAreas());if(2==Blockly.dragMode_){var e=b.startDragX+c,f=b.startDragY+ -d;b.getSvgRoot().setAttribute("transform","translate("+e+", "+f+")");for(e=0;e=a.clientX&&0==a.clientY&&0==a.button)){Blockly.removeAllRanges();var d=b.getRelativeToSurfaceXY(),e=c.moveDrag(a);1==Blockly.dragMode_&&goog.math.Coordinate.distance(d,e)*c.scale>Blockly.DRAG_RADIUS&&(Blockly.dragMode_=2,Blockly.longStop_(),b.setParent(null),b.setDragging_(!0),c.recordDeleteAreas());if(2==Blockly.dragMode_){var f=d.x-b.dragStartXY_.x,d=d.y-b.dragStartXY_.y; +b.getSvgRoot().setAttribute("transform","translate("+e.x+","+e.y+")");for(e=0;ec;c+=15)Blockly.createSvgElement("line",{x1:Blockly.FieldAngle.HALF+Blockly.FieldAngle.RADIUS,y1:Blockly.FieldAngle.HALF,x2:Blockly.FieldAngle.HALF+Blockly.FieldAngle.RADIUS- -(0==c%45?10:5),y2:Blockly.FieldAngle.HALF,"class":"blocklyAngleMarks",transform:"rotate("+c+", "+Blockly.FieldAngle.HALF+", "+Blockly.FieldAngle.HALF+")"},a);a.style.marginLeft=15-Blockly.FieldAngle.RADIUS+"px";this.clickWrapper_=Blockly.bindEvent_(a,"click",this,Blockly.WidgetDiv.hide);this.moveWrapper1_=Blockly.bindEvent_(b,"mousemove",this,this.onMouseMove);this.moveWrapper2_=Blockly.bindEvent_(this.gauge_,"mousemove",this,this.onMouseMove);this.updateGraph_()}}; +(0==c%45?10:5),y2:Blockly.FieldAngle.HALF,"class":"blocklyAngleMarks",transform:"rotate("+c+","+Blockly.FieldAngle.HALF+","+Blockly.FieldAngle.HALF+")"},a);a.style.marginLeft=15-Blockly.FieldAngle.RADIUS+"px";this.clickWrapper_=Blockly.bindEvent_(a,"click",this,Blockly.WidgetDiv.hide);this.moveWrapper1_=Blockly.bindEvent_(b,"mousemove",this,this.onMouseMove);this.moveWrapper2_=Blockly.bindEvent_(this.gauge_,"mousemove",this,this.onMouseMove);this.updateGraph_()}}; Blockly.FieldAngle.prototype.onMouseMove=function(a){var b=this.gauge_.ownerSVGElement.getBoundingClientRect(),c=a.clientX-b.left-Blockly.FieldAngle.HALF;a=a.clientY-b.top-Blockly.FieldAngle.HALF;b=Math.atan(-a/c);isNaN(b)||(b=goog.math.toDegrees(b),0>c?b+=180:0Math.PI?1:0)+" 0 "+b+","+c+" z");this.line_.setAttribute("x2",b);this.line_.setAttribute("y2",c)}}};Blockly.FieldAngle.angleValidator=function(a){a=Blockly.FieldTextInput.numberValidator(a);null!==a&&(a%=360,0>a&&(a+=360),a=String(a));return a};Blockly.FieldCheckbox=function(a,b){Blockly.FieldCheckbox.superClass_.constructor.call(this,"");this.setChangeHandler(b);this.setValue(a)};goog.inherits(Blockly.FieldCheckbox,Blockly.Field);Blockly.FieldCheckbox.prototype.CURSOR="default"; +Blockly.FieldAngle.prototype.updateGraph_=function(){if(this.gauge_){var a=goog.math.toRadians(Number(this.getText()));if(isNaN(a))this.gauge_.setAttribute("d","M "+Blockly.FieldAngle.HALF+","+Blockly.FieldAngle.HALF),this.line_.setAttribute("x2",Blockly.FieldAngle.HALF),this.line_.setAttribute("y2",Blockly.FieldAngle.HALF);else{var b=Blockly.FieldAngle.HALF+Math.cos(a)*Blockly.FieldAngle.RADIUS,c=Blockly.FieldAngle.HALF+Math.sin(a)*-Blockly.FieldAngle.RADIUS;this.gauge_.setAttribute("d","M "+Blockly.FieldAngle.HALF+ +","+Blockly.FieldAngle.HALF+" h "+Blockly.FieldAngle.RADIUS+" A "+Blockly.FieldAngle.RADIUS+","+Blockly.FieldAngle.RADIUS+" 0 "+(a>Math.PI?1:0)+" 0 "+b+","+c+" z");this.line_.setAttribute("x2",b);this.line_.setAttribute("y2",c)}}};Blockly.FieldAngle.angleValidator=function(a){a=Blockly.FieldTextInput.numberValidator(a);null!==a&&(a%=360,0>a&&(a+=360),a=String(a));return a};Blockly.FieldCheckbox=function(a,b){Blockly.FieldCheckbox.superClass_.constructor.call(this,"");this.setChangeHandler(b);this.setValue(a)};goog.inherits(Blockly.FieldCheckbox,Blockly.Field);Blockly.FieldCheckbox.prototype.CURSOR="default"; Blockly.FieldCheckbox.prototype.init=function(a){this.sourceBlock_||(Blockly.FieldCheckbox.superClass_.init.call(this,a),this.checkElement_=Blockly.createSvgElement("text",{"class":"blocklyText",x:-3},this.fieldGroup_),a=document.createTextNode("\u2713"),this.checkElement_.appendChild(a),this.checkElement_.style.display=this.state_?"block":"none")};Blockly.FieldCheckbox.prototype.getValue=function(){return String(this.state_).toUpperCase()}; Blockly.FieldCheckbox.prototype.setValue=function(a){a="TRUE"==a;this.state_!==a&&(this.state_=a,this.checkElement_&&(this.checkElement_.style.display=a?"block":"none"),this.sourceBlock_&&this.sourceBlock_.rendered&&this.sourceBlock_.workspace.fireChangeEvent())};Blockly.FieldCheckbox.prototype.showEditor_=function(){var a=!this.state_;if(this.sourceBlock_&&this.changeHandler_){var b=this.changeHandler_(a);void 0!==b&&(a=b)}null!==a&&this.setValue(String(a).toUpperCase())};Blockly.FieldColour=function(a,b){Blockly.FieldColour.superClass_.constructor.call(this,"\u00a0\u00a0\u00a0");this.setChangeHandler(b);this.setValue(a);this.colours_=null;this.columns_=0};goog.inherits(Blockly.FieldColour,Blockly.Field);Blockly.FieldColour.prototype.init=function(a){Blockly.FieldColour.superClass_.init.call(this,a);this.borderRect_.style.fillOpacity=1;this.setValue(this.getValue())};Blockly.FieldColour.prototype.CURSOR="default"; Blockly.FieldColour.prototype.dispose=function(){Blockly.WidgetDiv.hideIfOwner(this);Blockly.FieldColour.superClass_.dispose.call(this)};Blockly.FieldColour.prototype.getValue=function(){return this.colour_};Blockly.FieldColour.prototype.setValue=function(a){this.colour_=a;this.borderRect_&&(this.borderRect_.style.fill=a);this.sourceBlock_&&this.sourceBlock_.rendered&&(Blockly.Realtime.blockChanged(this.sourceBlock_),this.sourceBlock_.workspace.fireChangeEvent())}; Blockly.FieldColour.prototype.getText=function(){var a=this.colour_,b=a.match(/^#(.)\1(.)\2(.)\3$/);b&&(a="#"+b[1]+b[2]+b[3]);return a};Blockly.FieldColour.COLOURS=goog.ui.ColorPicker.SIMPLE_GRID_COLORS;Blockly.FieldColour.COLUMNS=7;Blockly.FieldColour.prototype.setColours=function(a){this.colours_=a;return this};Blockly.FieldColour.prototype.setColumns=function(a){this.columns_=a;return this}; -Blockly.FieldColour.prototype.showEditor_=function(){Blockly.WidgetDiv.show(this,this.sourceBlock_.RTL,Blockly.FieldColour.widgetDispose_);var a=new goog.ui.ColorPicker;a.setSize(this.columns_||Blockly.FieldColour.COLUMNS);a.setColors(this.colours_||Blockly.FieldColour.COLOURS);var b=goog.dom.getViewportSize(),c=goog.style.getViewportPageOffset(document),d=this.getAbsoluteXY_(),e=this.borderRect_.getBBox();a.render(Blockly.WidgetDiv.DIV);a.setSelectedColor(this.getValue());var f=goog.style.getSize(a.getElement()); +Blockly.FieldColour.prototype.showEditor_=function(){Blockly.WidgetDiv.show(this,this.sourceBlock_.RTL,Blockly.FieldColour.widgetDispose_);var a=new goog.ui.ColorPicker;a.setSize(this.columns_||Blockly.FieldColour.COLUMNS);a.setColors(this.colours_||Blockly.FieldColour.COLOURS);var b=goog.dom.getViewportSize(),c=goog.style.getViewportPageOffset(document),d=this.getAbsoluteXY_(),e=this.getScaledBBox_();a.render(Blockly.WidgetDiv.DIV);a.setSelectedColor(this.getValue());var f=goog.style.getSize(a.getElement()); d.y=d.y+f.height+e.height>=b.height+c.y?d.y-(f.height-1):d.y+(e.height-1);this.sourceBlock_.RTL?(d.x+=e.width,d.x-=f.width,d.xb.width+c.x-f.width&&(d.x=b.width+c.x-f.width);Blockly.WidgetDiv.position(d.x,d.y,b,c,this.sourceBlock_.RTL);var g=this;Blockly.FieldColour.changeEventKey_=goog.events.listen(a,goog.ui.ColorPicker.EventType.CHANGE,function(a){a=a.target.getSelectedColor()||"#000000";Blockly.WidgetDiv.hide();if(g.sourceBlock_&&g.changeHandler_){var b=g.changeHandler_(a); void 0!==b&&(a=b)}null!==a&&g.setValue(a)})};Blockly.FieldColour.widgetDispose_=function(){Blockly.FieldColour.changeEventKey_&&goog.events.unlistenByKey(Blockly.FieldColour.changeEventKey_)};Blockly.FieldDropdown=function(a,b){this.menuGenerator_=a;this.setChangeHandler(b);this.trimOptions_();var c=this.getOptions_()[0];this.value_=c[1];Blockly.FieldDropdown.superClass_.constructor.call(this,c[0])};goog.inherits(Blockly.FieldDropdown,Blockly.Field);Blockly.FieldDropdown.CHECKMARK_OVERHANG=25;Blockly.FieldDropdown.ARROW_CHAR=goog.userAgent.ANDROID?"\u25bc":"\u25be";Blockly.FieldDropdown.prototype.CURSOR="default"; Blockly.FieldDropdown.prototype.init=function(a){this.sourceBlock_||(this.arrow_=Blockly.createSvgElement("tspan",{},null),this.arrow_.appendChild(document.createTextNode(a.RTL?Blockly.FieldDropdown.ARROW_CHAR+" ":" "+Blockly.FieldDropdown.ARROW_CHAR)),Blockly.FieldDropdown.superClass_.init.call(this,a),a=this.text_,this.text_=null,this.setText(a))}; -Blockly.FieldDropdown.prototype.showEditor_=function(){Blockly.WidgetDiv.show(this,this.sourceBlock_.RTL,null);for(var a=this,b=new goog.ui.Menu,c=this.getOptions_(),d=0;d=c.height+d.y?e.y-h.height:e.y+f.height;this.sourceBlock_.RTL?(e.x+=f.width,e.x+=Blockly.FieldDropdown.CHECKMARK_OVERHANG,e.xc.width+d.x-h.width&&(e.x=c.width+d.x-h.width));Blockly.WidgetDiv.position(e.x,e.y,c,d,this.sourceBlock_.RTL);b.setAllowAutoFocus(!0);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;c=c.height+d.y?e.y-h.height:e.y+f.height;this.sourceBlock_.RTL?(e.x+=f.width,e.x+=Blockly.FieldDropdown.CHECKMARK_OVERHANG,e.xc.width+d.x-h.width&&(e.x=c.width+d.x-h.width));Blockly.WidgetDiv.position(e.x,e.y,c,d,this.sourceBlock_.RTL);b.setAllowAutoFocus(!0); +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;c=a.clientX&&0==a.clientY&&0==a.button)a.stopPropagation();else{Blockly.removeAllRanges();var b=a.clientY-Blockly.Flyout.startDownEvent_.clientY;Math.sqrt(Math.pow(a.clientX-Blockly.Flyout.startDownEvent_.clientX,2)+Math.pow(b,2))>Blockly.DRAG_RADIUS&&Blockly.Flyout.startFlyout_.createBlockFunc_(Blockly.Flyout.startBlock_)(Blockly.Flyout.startDownEvent_)}}; -Blockly.Flyout.prototype.createBlockFunc_=function(a){var b=this;return function(c){if(!Blockly.isRightButton(c)&&!a.disabled){var d=Blockly.Xml.blockToDom_(a),d=Blockly.Xml.domToBlock(b.targetWorkspace_,d),e=a.getSvgRoot();if(!e)throw"originBlock is not rendered.";var e=Blockly.getSvgXY_(e),f=d.getSvgRoot();if(!f)throw"block is not rendered.";f=Blockly.getSvgXY_(f);d.moveBy(e.x-f.x,e.y-f.y);b.autoClose?b.hide():b.filterForCapacity_();d.onMouseDown_(c)}}}; -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.getSvgXY_(this.svgGroup_).x;this.RTL||(a-=1E7);return new goog.math.Rect(a,-1E7,1E7+this.width_,this.height_+2E7)}; +Blockly.Flyout.prototype.onMouseMoveBlock_=function(a){if("mousemove"==a.type&&1>=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.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"}; Blockly.Toolbox.prototype.init=function(){var a=this.workspace_;this.HtmlDiv=goog.dom.createDom("div","blocklyToolboxDiv");this.HtmlDiv.setAttribute("dir",this.workspace_.RTL?"RTL":"LTR");document.body.appendChild(this.HtmlDiv);Blockly.bindEvent_(this.HtmlDiv,"mousedown",this,function(a){Blockly.isRightButton(a)||a.target==this.HtmlDiv?Blockly.hideChaff(!1):Blockly.hideChaff(!0)});this.flyout_=new Blockly.Flyout({parentWorkspace:a,RTL:a.RTL,svg:a.options.svg});goog.dom.insertSiblingAfter(this.flyout_.createDom(), @@ -1247,38 +1263,40 @@ Blockly.Toolbox.TreeNode=function(a,b,c,d){goog.ui.tree.TreeNode.call(this,b,c,d Blockly.Toolbox.TreeNode.prototype.onMouseDown=function(a){this.hasChildren()&&this.isUserCollapsible_?(this.toggle(),this.select()):this.isSelected()?this.getTree().setSelectedItem(null):this.select();this.updateRow()};Blockly.Toolbox.TreeNode.prototype.onDoubleClick_=function(a){};Blockly.Toolbox.TreeSeparator=function(){Blockly.Toolbox.TreeNode.call(this,null,"",Blockly.Toolbox.TreeSeparator.CONFIG_)};goog.inherits(Blockly.Toolbox.TreeSeparator,Blockly.Toolbox.TreeNode); Blockly.Toolbox.TreeSeparator.CONFIG_={cssTreeRow:"blocklyTreeSeparator"};Blockly.Css={};Blockly.Css.Cursor={OPEN:"handopen",CLOSED:"handclosed",DELETE:"handdelete"};Blockly.Css.currentCursor_="";Blockly.Css.styleSheet_=null;Blockly.Css.mediaPath_=""; 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(/[\\\/]$/,"");c=c.replace(/<<>>/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.OPEN?"":b;document.body.parentNode.style.cursor=a==Blockly.Css.Cursor.OPEN?"":b}}; +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.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 {", " pointer-events: none;","}",".blocklyNonEditableText>rect,",".blocklyEditableText>rect {"," fill: #fff;"," fill-opacity: .6;","}",".blocklyNonEditableText>text,",".blocklyEditableText>text {"," fill: #000;","}",".blocklyEditableText:hover>rect {"," stroke: #fff;"," stroke-width: 2;","}",".blocklyBubbleText {"," fill: #000;","}",".blocklySvg text {"," user-select: none;"," -moz-user-select: none;"," -webkit-user-select: none;"," cursor: inherit;","}",".blocklyHidden {"," display: none;", -"}",".blocklyFieldDropdown:not(.blocklyHidden) {"," display: block;","}",".blocklyIconGroup {"," cursor: default;","}",".blocklyIconGroup:not(:hover),",".blocklyIconGroupReadonly {"," opacity: .6;","}",".blocklyMinimalBody {"," margin: 0;"," padding: 0;","}",".blocklyCommentTextarea {"," background-color: #ffc;"," border: 0;"," margin: 0;"," padding: 2px;"," resize: none;","}",".blocklyHtmlInput {"," border: none;"," font-family: sans-serif;"," font-size: 11pt;"," outline: none;"," width: 100%", -"}",".blocklyMainBackground {"," stroke-width: 1;"," stroke: #c6c6c6;","}",".blocklyMutatorBackground {"," fill: #fff;"," stroke: #ddd;"," stroke-width: 1;","}",".blocklyFlyoutBackground {"," fill: #ddd;"," fill-opacity: .8;","}",".blocklyScrollbarBackground {"," opacity: 0;","}",".blocklyScrollbarKnob {"," fill: #ccc;","}",".blocklyScrollbarBackground:hover+.blocklyScrollbarKnob,",".blocklyScrollbarKnob:hover {"," fill: #bbb;","}",".blocklyFlyout .blocklyScrollbarKnob {"," fill: #bbb;", -"}",".blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarKnob,",".blocklyFlyout .blocklyScrollbarKnob:hover {"," fill: #aaa;","}",".blocklyInvalidInput {"," background: #faa;","}",".blocklyAngleCircle {"," stroke: #444;"," stroke-width: 1;"," fill: #ddd;"," fill-opacity: .8;","}",".blocklyAngleMarks {"," stroke: #444;"," stroke-width: 1;","}",".blocklyAngleGauge {"," fill: #f88;"," fill-opacity: .8; ","}",".blocklyAngleLine {"," stroke: #f00;"," stroke-width: 2;"," stroke-linecap: round;", -"}",".blocklyContextMenu {"," border-radius: 4px;","}",".blocklyDropdownMenu {"," padding: 0 !important;","}",".blocklyWidgetDiv .goog-option-selected .goog-menuitem-checkbox,",".blocklyWidgetDiv .goog-option-selected .goog-menuitem-icon {"," background: url(<<>>/sprites.png) no-repeat -48px -16px !important;","}",".blocklyToolboxDiv {"," background-color: #ddd;"," overflow-x: visible;"," overflow-y: auto;"," position: absolute;","}",".blocklyTreeRoot {"," padding: 4px 0;","}",".blocklyTreeRoot:focus {", -" outline: none;","}",".blocklyTreeRow {"," line-height: 22px;"," height: 22px;"," padding-right: 1em;"," white-space: nowrap;","}",'.blocklyToolboxDiv[dir="RTL"] .blocklyTreeRow {'," padding-right: 0;"," padding-left: 1em !important;","}",".blocklyTreeRow:hover {"," background-color: #e4e4e4;","}",".blocklyTreeSeparator {"," border-bottom: solid #e5e5e5 1px;"," height: 0px;"," margin: 5px 0;","}",".blocklyTreeIcon {"," background-image: url(<<>>/sprites.png);"," height: 16px;", -" vertical-align: middle;"," width: 16px;","}",".blocklyTreeIconClosedLtr {"," background-position: -32px -1px;","}",".blocklyTreeIconClosedRtl {"," background-position: 0px -1px;","}",".blocklyTreeIconOpen {"," background-position: -16px -1px;","}",".blocklyTreeSelected>.blocklyTreeIconClosedLtr {"," background-position: -32px -17px;","}",".blocklyTreeSelected>.blocklyTreeIconClosedRtl {"," background-position: 0px -17px;","}",".blocklyTreeSelected>.blocklyTreeIconOpen {"," background-position: -16px -17px;", -"}",".blocklyTreeIconNone,",".blocklyTreeSelected>.blocklyTreeIconNone {"," background-position: -48px -1px;","}",".blocklyTreeLabel {"," cursor: default;"," font-family: sans-serif;"," font-size: 16px;"," padding: 0 3px;"," vertical-align: middle;","}",".blocklyTreeSelected {"," background-color: #57e !important;","}",".blocklyTreeSelected .blocklyTreeLabel {"," color: #fff;","}",".blocklyWidgetDiv .goog-palette {"," outline: none;"," cursor: default;","}",".blocklyWidgetDiv .goog-palette-table {", -" border: 1px solid #666;"," border-collapse: collapse;","}",".blocklyWidgetDiv .goog-palette-cell {"," height: 13px;"," width: 15px;"," margin: 0;"," border: 0;"," text-align: center;"," vertical-align: middle;"," border-right: 1px solid #666;"," font-size: 1px;","}",".blocklyWidgetDiv .goog-palette-colorswatch {"," position: relative;"," height: 13px;"," width: 15px;"," border: 1px solid #666;","}",".blocklyWidgetDiv .goog-palette-cell-hover .goog-palette-colorswatch {"," border: 1px solid #FFF;", -"}",".blocklyWidgetDiv .goog-palette-cell-selected .goog-palette-colorswatch {"," border: 1px solid #000;"," color: #fff;","}",".blocklyWidgetDiv .goog-menu {"," background: #fff;"," border-color: #ccc #666 #666 #ccc;"," border-style: solid;"," border-width: 1px;"," cursor: default;"," font: normal 13px Arial, sans-serif;"," margin: 0;"," outline: none;"," padding: 4px 0;"," position: absolute;"," overflow-y: auto;"," overflow-x: hidden;"," max-height: 100%;"," z-index: 20000;","}", -".blocklyWidgetDiv .goog-menuitem {"," color: #000;"," font: normal 13px Arial, sans-serif;"," list-style: none;"," margin: 0;"," padding: 4px 7em 4px 28px;"," white-space: nowrap;","}",".blocklyWidgetDiv .goog-menuitem.goog-menuitem-rtl {"," padding-left: 7em;"," padding-right: 28px;","}",".blocklyWidgetDiv .goog-menu-nocheckbox .goog-menuitem,",".blocklyWidgetDiv .goog-menu-noicon .goog-menuitem {"," padding-left: 12px;","}",".blocklyWidgetDiv .goog-menu-noaccel .goog-menuitem {"," padding-right: 20px;", -"}",".blocklyWidgetDiv .goog-menuitem-content {"," color: #000;"," font: normal 13px Arial, sans-serif;","}",".blocklyWidgetDiv .goog-menuitem-disabled .goog-menuitem-accel,",".blocklyWidgetDiv .goog-menuitem-disabled .goog-menuitem-content {"," color: #ccc !important;","}",".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"}; +"}",".blocklyFieldDropdown:not(.blocklyHidden) {"," display: block;","}",".blocklyIconGroup {"," cursor: default;","}",".blocklyIconGroup:not(:hover),",".blocklyIconGroupReadonly {"," opacity: .6;","}",".blocklyMinimalBody {"," margin: 0;"," padding: 0;","}",".blocklyCommentTextarea {"," background-color: #ffc;"," border: 0;"," margin: 0;"," padding: 2px;"," resize: none;","}",".blocklyHtmlInput {"," border: none;"," border-radius: 4px;"," font-family: sans-serif;"," height: 100%;", +" margin: 0;"," outline: none;"," padding: 0 1px;"," width: 100%","}",".blocklyMainBackground {"," stroke-width: 1;"," stroke: #c6c6c6;","}",".blocklyMutatorBackground {"," fill: #fff;"," stroke: #ddd;"," stroke-width: 1;","}",".blocklyFlyoutBackground {"," fill: #ddd;"," fill-opacity: .8;","}",".blocklyScrollbarBackground {"," opacity: 0;","}",".blocklyScrollbarKnob {"," fill: #ccc;","}",".blocklyScrollbarBackground:hover+.blocklyScrollbarKnob,",".blocklyScrollbarKnob:hover {"," fill: #bbb;", +"}",".blocklyZoom>image {"," opacity: .4;","}",".blocklyZoom>image:hover {"," opacity: .6;","}",".blocklyZoom>image:active {"," opacity: .8;","}",".blocklyFlyout .blocklyScrollbarKnob {"," fill: #bbb;","}",".blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarKnob,",".blocklyFlyout .blocklyScrollbarKnob:hover {"," fill: #aaa;","}",".blocklyInvalidInput {"," background: #faa;","}",".blocklyAngleCircle {"," stroke: #444;"," stroke-width: 1;"," fill: #ddd;"," fill-opacity: .8;", +"}",".blocklyAngleMarks {"," stroke: #444;"," stroke-width: 1;","}",".blocklyAngleGauge {"," fill: #f88;"," fill-opacity: .8; ","}",".blocklyAngleLine {"," stroke: #f00;"," stroke-width: 2;"," stroke-linecap: round;","}",".blocklyContextMenu {"," border-radius: 4px;","}",".blocklyDropdownMenu {"," padding: 0 !important;","}",".blocklyWidgetDiv .goog-option-selected .goog-menuitem-checkbox,",".blocklyWidgetDiv .goog-option-selected .goog-menuitem-icon {"," background: url(<<>>/sprites.png) no-repeat -48px -16px !important;", +"}",".blocklyToolboxDiv {"," background-color: #ddd;"," overflow-x: visible;"," overflow-y: auto;"," position: absolute;","}",".blocklyTreeRoot {"," padding: 4px 0;","}",".blocklyTreeRoot:focus {"," outline: none;","}",".blocklyTreeRow {"," line-height: 22px;"," height: 22px;"," padding-right: 1em;"," white-space: nowrap;","}",'.blocklyToolboxDiv[dir="RTL"] .blocklyTreeRow {'," padding-right: 0;"," padding-left: 1em !important;","}",".blocklyTreeRow:hover {"," background-color: #e4e4e4;", +"}",".blocklyTreeSeparator {"," border-bottom: solid #e5e5e5 1px;"," height: 0px;"," margin: 5px 0;","}",".blocklyTreeIcon {"," background-image: url(<<>>/sprites.png);"," height: 16px;"," vertical-align: middle;"," width: 16px;","}",".blocklyTreeIconClosedLtr {"," background-position: -32px -1px;","}",".blocklyTreeIconClosedRtl {"," background-position: 0px -1px;","}",".blocklyTreeIconOpen {"," background-position: -16px -1px;","}",".blocklyTreeSelected>.blocklyTreeIconClosedLtr {", +" background-position: -32px -17px;","}",".blocklyTreeSelected>.blocklyTreeIconClosedRtl {"," background-position: 0px -17px;","}",".blocklyTreeSelected>.blocklyTreeIconOpen {"," background-position: -16px -17px;","}",".blocklyTreeIconNone,",".blocklyTreeSelected>.blocklyTreeIconNone {"," background-position: -48px -1px;","}",".blocklyTreeLabel {"," cursor: default;"," font-family: sans-serif;"," font-size: 16px;"," padding: 0 3px;"," vertical-align: middle;","}",".blocklyTreeSelected {", +" background-color: #57e !important;","}",".blocklyTreeSelected .blocklyTreeLabel {"," color: #fff;","}",".blocklyWidgetDiv .goog-palette {"," outline: none;"," cursor: default;","}",".blocklyWidgetDiv .goog-palette-table {"," border: 1px solid #666;"," border-collapse: collapse;","}",".blocklyWidgetDiv .goog-palette-cell {"," height: 13px;"," width: 15px;"," margin: 0;"," border: 0;"," text-align: center;"," vertical-align: middle;"," border-right: 1px solid #666;"," font-size: 1px;", +"}",".blocklyWidgetDiv .goog-palette-colorswatch {"," position: relative;"," height: 13px;"," width: 15px;"," border: 1px solid #666;","}",".blocklyWidgetDiv .goog-palette-cell-hover .goog-palette-colorswatch {"," border: 1px solid #FFF;","}",".blocklyWidgetDiv .goog-palette-cell-selected .goog-palette-colorswatch {"," border: 1px solid #000;"," color: #fff;","}",".blocklyWidgetDiv .goog-menu {"," background: #fff;"," border-color: #ccc #666 #666 #ccc;"," border-style: solid;"," border-width: 1px;", +" cursor: default;"," font: normal 13px Arial, sans-serif;"," margin: 0;"," outline: none;"," padding: 4px 0;"," position: absolute;"," overflow-y: auto;"," overflow-x: hidden;"," max-height: 100%;"," z-index: 20000;","}",".blocklyWidgetDiv .goog-menuitem {"," color: #000;"," font: normal 13px Arial, sans-serif;"," list-style: none;"," margin: 0;"," padding: 4px 7em 4px 28px;"," white-space: nowrap;","}",".blocklyWidgetDiv .goog-menuitem.goog-menuitem-rtl {"," padding-left: 7em;", +" padding-right: 28px;","}",".blocklyWidgetDiv .goog-menu-nocheckbox .goog-menuitem,",".blocklyWidgetDiv .goog-menu-noicon .goog-menuitem {"," padding-left: 12px;","}",".blocklyWidgetDiv .goog-menu-noaccel .goog-menuitem {"," padding-right: 20px;","}",".blocklyWidgetDiv .goog-menuitem-content {"," color: #000;"," font: normal 13px Arial, sans-serif;","}",".blocklyWidgetDiv .goog-menuitem-disabled .goog-menuitem-accel,",".blocklyWidgetDiv .goog-menuitem-disabled .goog-menuitem-content {"," color: #ccc !important;", +"}",".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"}; Blockly.WidgetDiv.hide=function(){Blockly.WidgetDiv.owner_&&(Blockly.WidgetDiv.DIV.style.display="none",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):aa.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_, -!1),goog.userAgent.IPAD&&Blockly.bindEvent_(window,"orientationchange",document,function(){Blockly.fireUiEvent(window,"resize")}),Blockly.documentEventsBound_=!0);if(b.languageTree)if(a.toolbox_)a.toolbox_.init(a);else if(a.flyout_){a.flyout_.init(a);a.flyout_.show(b.languageTree.childNodes);a.scrollX=a.flyout_.width_;b.RTL&&(a.scrollX*=-1);var c="translate("+a.scrollX+", 0)";a.getCanvas().setAttribute("transform",c);a.getBubbleCanvas().setAttribute("transform",c)}b.hasScrollbars&&(a.scrollbar=new Blockly.ScrollbarPair(a), +!1),goog.userAgent.IPAD&&Blockly.bindEvent_(window,"orientationchange",document,function(){Blockly.fireUiEvent(window,"resize")}),Blockly.documentEventsBound_=!0);if(b.languageTree)if(a.toolbox_)a.toolbox_.init(a);else if(a.flyout_){a.flyout_.init(a);a.flyout_.show(b.languageTree.childNodes);a.scrollX=a.flyout_.width_;b.RTL&&(a.scrollX*=-1);var c="translate("+a.scrollX+",0)";a.getCanvas().setAttribute("transform",c);a.getBubbleCanvas().setAttribute("transform",c)}b.hasScrollbars&&(a.scrollbar=new Blockly.ScrollbarPair(a), a.scrollbar.resize());if(b.hasSounds){a.loadAudio_([b.pathToMedia+"click.mp3",b.pathToMedia+"click.wav",b.pathToMedia+"click.ogg"],"click");a.loadAudio_([b.pathToMedia+"delete.mp3",b.pathToMedia+"delete.ogg",b.pathToMedia+"delete.wav"],"delete");var d=[],b=function(){for(;d.length;)Blockly.unbindEvent_(d.pop());a.preloadAudio_()};d.push(Blockly.bindEvent_(document,"mousemove",null,b));d.push(Blockly.bindEvent_(document,"touchstart",null,b))}}; Blockly.updateToolbox=function(a){console.warn("Deprecated call to Blockly.updateToolbox, use workspace.updateToolbox instead.");Blockly.getMainWorkspace().updateToolbox(a)};Blockly.utils={};Blockly.addClass_=function(a,b){var c=a.getAttribute("class")||"";-1==(" "+c+" ").indexOf(" "+b+" ")&&(c&&(c+=" "),a.setAttribute("class",c+b))};Blockly.removeClass_=function(a,b){var c=a.getAttribute("class");if(-1!=(" "+c+" ").indexOf(" "+b+" ")){for(var c=c.split(/\s+/),d=0;d=g?(c=2,e=g,(g=d.join(""))&&b.push(g),d.length=0):(d.push("%",g),c=0):2==c&&("0"<=g&&"9">=g?e+=g:(b.push(parseInt(e,10)),f--,c=0))}(g=d.join(""))&&b.push(g);return b};Blockly.SVG_NS="http://www.w3.org/2000/svg";Blockly.HTML_NS="http://www.w3.org/1999/xhtml";Blockly.HSV_SATURATION=.45;Blockly.HSV_VALUE=.65;Blockly.SPRITE={width:64,height:92,url:"sprites.png"};Blockly.makeColour=function(a){return goog.color.hsvToHex(a,Blockly.HSV_SATURATION,255*Blockly.HSV_VALUE)};Blockly.INPUT_VALUE=1;Blockly.OUTPUT_VALUE=2;Blockly.NEXT_STATEMENT=3;Blockly.PREVIOUS_STATEMENT=4;Blockly.DUMMY_INPUT=5;Blockly.ALIGN_LEFT=-1;Blockly.ALIGN_CENTRE=0;Blockly.ALIGN_RIGHT=1; +Blockly.tokenizeInterpolation=function(a){var b=[];a=a.split("");a.push("");for(var c=0,d=[],e=null,f=0;f=g?(c=2,e=g,(g=d.join(""))&&b.push(g),d.length=0):(d.push("%",g),c=0):2==c&&("0"<=g&&"9">=g?e+=g:(b.push(parseInt(e,10)),f--,c=0))}(g=d.join(""))&&b.push(g);return b};Blockly.SVG_NS="http://www.w3.org/2000/svg";Blockly.HTML_NS="http://www.w3.org/1999/xhtml";Blockly.HSV_SATURATION=.45;Blockly.HSV_VALUE=.65;Blockly.SPRITE={width:96,height:124,url:"sprites.png"};Blockly.makeColour=function(a){return goog.color.hsvToHex(a,Blockly.HSV_SATURATION,255*Blockly.HSV_VALUE)};Blockly.INPUT_VALUE=1;Blockly.OUTPUT_VALUE=2;Blockly.NEXT_STATEMENT=3;Blockly.PREVIOUS_STATEMENT=4;Blockly.DUMMY_INPUT=5;Blockly.ALIGN_LEFT=-1;Blockly.ALIGN_CENTRE=0;Blockly.ALIGN_RIGHT=1; Blockly.OPPOSITE_TYPE=[];Blockly.OPPOSITE_TYPE[Blockly.INPUT_VALUE]=Blockly.OUTPUT_VALUE;Blockly.OPPOSITE_TYPE[Blockly.OUTPUT_VALUE]=Blockly.INPUT_VALUE;Blockly.OPPOSITE_TYPE[Blockly.NEXT_STATEMENT]=Blockly.PREVIOUS_STATEMENT;Blockly.OPPOSITE_TYPE[Blockly.PREVIOUS_STATEMENT]=Blockly.NEXT_STATEMENT;Blockly.selected=null;Blockly.highlightedConnection_=null;Blockly.localConnection_=null;Blockly.DRAG_RADIUS=5;Blockly.SNAP_RADIUS=20;Blockly.BUMP_DELAY=250;Blockly.COLLAPSE_CHARS=30;Blockly.LONGPRESS=750; 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(Math.pow(c,2)+Math.pow(d,2))>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){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}if(this.scrollbar)var f=this.RTL?0:Blockly.Scrollbar.scrollbarThickness,g=Math.min(d.x-b/2,d.x+d.width-b-(this.RTL?Blockly.Scrollbar.scrollbarThickness:0)+5),b=Math.max(d.x+d.width+b/2,d.x+b+f-5),f=Math.min(d.y-c/2, -d.y+d.height-c+5),c=Math.max(d.y+d.height+c/2,d.y+c+Blockly.Scrollbar.scrollbarThickness-5);else g=d.x,b=g+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-g,viewTop:-this.scrollY,viewLeft:-this.scrollX,contentTop:f,contentLeft:g,absoluteTop:0,absoluteLeft:d}}; +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,g=d.height,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}}; Blockly.setMainWorkspaceMetrics_=function(a){if(!this.scrollbar)throw"Attempt to set main workspace scroll without scrollbars.";var b=this.getMetrics();goog.isNumber(a.x)&&(this.scrollX=-b.contentWidth*a.x-b.contentLeft);goog.isNumber(a.y)&&(this.scrollY=-b.contentHeight*a.y-b.contentTop);a=this.scrollX+b.absoluteLeft;b=this.scrollY+b.absoluteTop;this.translate(a,b);this.options.gridPattern&&(this.options.gridPattern.setAttribute("x",a),this.options.gridPattern.setAttribute("y",b))}; Blockly.doCommand=function(a){Blockly.Realtime.isEnabled?Blockly.Realtime.doCommand(a):a()};Blockly.addChangeListener=function(a){console.warn("Deprecated call to Blockly.addChangeListener, use workspace.addChangeListener instead.");return Blockly.getMainWorkspace().addChangeListener(a)};Blockly.getMainWorkspace=function(){return Blockly.mainWorkspace};goog.global.Blockly||(goog.global.Blockly={});goog.global.Blockly.getMainWorkspace=Blockly.getMainWorkspace; -goog.global.Blockly.addChangeListener=Blockly.addChangeListener;goog.global.Blockly.removeChangeListener=Blockly.removeChangeListener; \ No newline at end of file +goog.global.Blockly.addChangeListener=Blockly.addChangeListener; \ No newline at end of file diff --git a/blockly_uncompressed.js b/blockly_uncompressed.js index 0774fe2cd..3af843337 100644 --- a/blockly_uncompressed.js +++ b/blockly_uncompressed.js @@ -40,7 +40,7 @@ goog.addDependency("../../../" + dir + "/core/field_checkbox.js", ['Blockly.Fiel goog.addDependency("../../../" + dir + "/core/field_colour.js", ['Blockly.FieldColour'], ['Blockly.Field', 'goog.dom', 'goog.events', 'goog.style', 'goog.ui.ColorPicker']); goog.addDependency("../../../" + dir + "/core/field_date.js", ['Blockly.FieldDate'], ['Blockly.Field', 'goog.date', 'goog.dom', 'goog.events', 'goog.i18n.DateTimeSymbols', 'goog.i18n.DateTimeSymbols_he', 'goog.style', 'goog.ui.DatePicker']); goog.addDependency("../../../" + dir + "/core/field_dropdown.js", ['Blockly.FieldDropdown'], ['Blockly.Field', 'goog.dom', 'goog.events', 'goog.style', 'goog.ui.Menu', 'goog.ui.MenuItem', 'goog.userAgent']); -goog.addDependency("../../../" + dir + "/core/field_image.js", ['Blockly.FieldImage'], ['Blockly.Field', 'goog.dom', 'goog.userAgent']); +goog.addDependency("../../../" + dir + "/core/field_image.js", ['Blockly.FieldImage'], ['Blockly.Field', 'goog.dom', 'goog.math.Size', 'goog.userAgent']); goog.addDependency("../../../" + dir + "/core/field_label.js", ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.Tooltip', 'goog.dom', 'goog.math.Size']); goog.addDependency("../../../" + dir + "/core/field_textinput.js", ['Blockly.FieldTextInput'], ['Blockly.Field', 'Blockly.Msg', 'goog.asserts', 'goog.dom', 'goog.userAgent']); goog.addDependency("../../../" + dir + "/core/field_variable.js", ['Blockly.FieldVariable'], ['Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.Variables', 'goog.string']); @@ -59,13 +59,14 @@ goog.addDependency("../../../" + dir + "/core/scrollbar.js", ['Blockly.Scrollbar goog.addDependency("../../../" + dir + "/core/toolbox.js", ['Blockly.Toolbox'], ['Blockly.Flyout', 'goog.dom', 'goog.events', 'goog.events.BrowserFeature', 'goog.html.SafeHtml', 'goog.math.Rect', 'goog.style', 'goog.ui.tree.TreeControl', 'goog.ui.tree.TreeNode']); goog.addDependency("../../../" + dir + "/core/tooltip.js", ['Blockly.Tooltip'], ['goog.dom']); goog.addDependency("../../../" + dir + "/core/trashcan.js", ['Blockly.Trashcan'], ['goog.Timer', 'goog.dom', 'goog.math', 'goog.math.Rect']); -goog.addDependency("../../../" + dir + "/core/utils.js", ['Blockly.utils'], ['goog.events.BrowserFeature', 'goog.userAgent']); +goog.addDependency("../../../" + dir + "/core/utils.js", ['Blockly.utils'], ['goog.events.BrowserFeature', 'goog.userAgent', 'goog.dom']); goog.addDependency("../../../" + dir + "/core/variables.js", ['Blockly.Variables'], ['Blockly.Workspace', 'goog.string']); goog.addDependency("../../../" + dir + "/core/warning.js", ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Icon']); goog.addDependency("../../../" + dir + "/core/widgetdiv.js", ['Blockly.WidgetDiv'], ['Blockly.Css', 'goog.dom']); goog.addDependency("../../../" + dir + "/core/workspace.js", ['Blockly.Workspace'], ['goog.math']); -goog.addDependency("../../../" + dir + "/core/workspace_svg.js", ['Blockly.WorkspaceSvg'], ['Blockly.ScrollbarPair', 'Blockly.Trashcan', 'Blockly.Workspace', 'Blockly.Xml', 'goog.dom', 'goog.math.Coordinate', 'goog.userAgent']); +goog.addDependency("../../../" + dir + "/core/workspace_svg.js", ['Blockly.WorkspaceSvg'], ['Blockly.ScrollbarPair', 'Blockly.Trashcan', 'Blockly.ZoomControls', 'Blockly.Workspace', 'Blockly.Xml', 'goog.dom', 'goog.math.Coordinate', 'goog.userAgent']); goog.addDependency("../../../" + dir + "/core/xml.js", ['Blockly.Xml'], ['goog.dom']); +goog.addDependency("../../../" + dir + "/core/zoom_controls.js", ['Blockly.ZoomControls'], ['goog.dom']); goog.addDependency("../../alltests.js", [], []); goog.addDependency("base.js", [], []); goog.addDependency("base_module_test.js", [], []); @@ -1584,6 +1585,7 @@ goog.require('Blockly.WidgetDiv'); goog.require('Blockly.Workspace'); goog.require('Blockly.WorkspaceSvg'); goog.require('Blockly.Xml'); +goog.require('Blockly.ZoomControls'); goog.require('Blockly.inject'); goog.require('Blockly.utils'); goog.require('rtclient'); diff --git a/core/block_svg.js b/core/block_svg.js index 5b406a2c6..e4524776e 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -43,7 +43,7 @@ Blockly.BlockSvg = function() { // Create core elements for the block. this.svgGroup_ = Blockly.createSvgElement('g', {}, null); this.svgPathDark_ = Blockly.createSvgElement('path', - {'class': 'blocklyPathDark', 'transform': 'translate(1, 1)'}, + {'class': 'blocklyPathDark', 'transform': 'translate(1,1)'}, this.svgGroup_); this.svgPath_ = Blockly.createSvgElement('path', {'class': 'blocklyPath'}, this.svgGroup_); @@ -63,6 +63,13 @@ Blockly.BlockSvg.prototype.height = 0; */ Blockly.BlockSvg.prototype.width = 0; +/** + * Original location of block being dragged. + * @type {goog.math.Coordinate} + * @private + */ +Blockly.BlockSvg.prototype.dragStartXY_ = null; + /** * Constant for identifying rows that are to be rendered inline. * Don't collide with Blockly.INPUT_VALUE and friends. @@ -194,9 +201,8 @@ Blockly.BlockSvg.terminateDrag_ = function() { if (selected) { // Update the connection locations. var xy = selected.getRelativeToSurfaceXY(); - var dx = xy.x - selected.startDragX; - var dy = xy.y - selected.startDragY; - selected.moveConnections_(dx, dy); + var dxy = goog.math.Coordinate.difference(xy, selected.dragStartXY_); + selected.moveConnections_(dxy.x, dxy.y); delete selected.draggedBubbles_; selected.setDragging_(false); selected.render(); @@ -227,8 +233,7 @@ Blockly.BlockSvg.prototype.setParent = function(newParent) { // Move this block up the DOM. Keep track of x/y translations. var xy = this.getRelativeToSurfaceXY(); this.workspace.getCanvas().appendChild(svgRoot); - svgRoot.setAttribute('transform', - 'translate(' + xy.x + ', ' + xy.y + ')'); + svgRoot.setAttribute('transform', 'translate(' + xy.x + ',' + xy.y + ')'); } Blockly.BlockSvg.superClass_.setParent.call(this, newParent); @@ -271,7 +276,7 @@ Blockly.BlockSvg.prototype.getRelativeToSurfaceXY = function() { Blockly.BlockSvg.prototype.moveBy = function(dx, dy) { var xy = this.getRelativeToSurfaceXY(); this.getSvgRoot().setAttribute('transform', - 'translate(' + (xy.x + dx) + ', ' + (xy.y + dy) + ')'); + 'translate(' + (xy.x + dx) + ',' + (xy.y + dy) + ')'); this.moveConnections_(dx, dy); Blockly.Realtime.blockChanged(this); }; @@ -397,13 +402,10 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) { // Left-click (or middle click) Blockly.removeAllRanges(); Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED); - // Look up the current translation and record it. - var xy = this.getRelativeToSurfaceXY(); - this.startDragX = xy.x; - this.startDragY = xy.y; - // Record the current mouse position. - this.startDragMouseX = e.clientX; - this.startDragMouseY = e.clientY; + + this.dragStartXY_ = this.getRelativeToSurfaceXY(); + this.workspace.startDrag(e, this.dragStartXY_.x, this.dragStartXY_.y); + Blockly.dragMode_ = 1; Blockly.BlockSvg.onMouseUpWrapper_ = Blockly.bindEvent_(document, 'mouseup', this, this.onMouseUp_); @@ -671,6 +673,7 @@ Blockly.BlockSvg.prototype.setDragging_ = function(adding) { */ Blockly.BlockSvg.prototype.onMouseMove_ = function(e) { var this_ = this; + var workspace_ = this.workspace; Blockly.doCommand(function() { if (e.type == 'mousemove' && e.clientX <= 1 && e.clientY == 0 && e.button == 0) { @@ -683,11 +686,13 @@ Blockly.BlockSvg.prototype.onMouseMove_ = function(e) { return; } Blockly.removeAllRanges(); - var dx = e.clientX - this_.startDragMouseX; - var dy = e.clientY - this_.startDragMouseY; + + var oldXY = this_.getRelativeToSurfaceXY(); + var newXY = workspace_.moveDrag(e); + if (Blockly.dragMode_ == 1) { // Still dragging within the sticky DRAG_RADIUS. - var dr = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); + var dr = goog.math.Coordinate.distance(oldXY, newXY) * workspace_.scale; if (dr > Blockly.DRAG_RADIUS) { // Switch to unrestricted dragging. Blockly.dragMode_ = 2; @@ -695,15 +700,15 @@ Blockly.BlockSvg.prototype.onMouseMove_ = function(e) { // Push this block to the very top of the stack. this_.setParent(null); this_.setDragging_(true); - this_.workspace.recordDeleteAreas(); + workspace_.recordDeleteAreas(); } } if (Blockly.dragMode_ == 2) { // Unrestricted dragging. - var x = this_.startDragX + dx; - var y = this_.startDragY + dy; + var dx = oldXY.x - this_.dragStartXY_.x; + var dy = oldXY.y - this_.dragStartXY_.y; this_.getSvgRoot().setAttribute('transform', - 'translate(' + x + ', ' + y + ')'); + 'translate(' + newXY.x + ',' + newXY.y + ')'); // Drag all the nested bubbles. for (var i = 0; i < this_.draggedBubbles_.length; i++) { var commentData = this_.draggedBubbles_[i]; @@ -744,7 +749,7 @@ Blockly.BlockSvg.prototype.onMouseMove_ = function(e) { // Provide visual indication of whether the block will be deleted if // dropped here. if (this_.isDeletable()) { - this_.workspace.isDeleteArea(e); + workspace_.isDeleteArea(e); } } // This event has been handled. No need to bubble up to the document. @@ -1035,7 +1040,8 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate, Blockly.BlockSvg.prototype.disposeUiEffect = function() { this.workspace.playAudio('delete'); - var xy = Blockly.getSvgXY_(/** @type {!Element} */ (this.svgGroup_)); + var xy = Blockly.getSvgXY_(/** @type {!Element} */ (this.svgGroup_), + this.workspace); // Deeply clone the current block. var clone = this.svgGroup_.cloneNode(true); clone.translateX_ = xy.x; @@ -1045,31 +1051,34 @@ Blockly.BlockSvg.prototype.disposeUiEffect = function() { this.workspace.options.svg.appendChild(clone); clone.bBox_ = clone.getBBox(); // Start the animation. - clone.startDate_ = new Date(); - Blockly.BlockSvg.disposeUiStep_(clone, this.RTL); + Blockly.BlockSvg.disposeUiStep_(clone, this.RTL, new Date(), + this.workspace.scale); }; /** * Animate a cloned block and eventually dispose of it. + * This is a class method, not an instace method since the original block has + * been destroyed and is no longer accessible. * @param {!Element} clone SVG element to animate and dispose of. * @param {boolean} rtl True if RTL, false if LTR. + * @param {!Date} start Date of animation's start. + * @param {number} workspaceScale Scale of workspace. * @private */ -Blockly.BlockSvg.disposeUiStep_ = function(clone, rtl) { - var ms = (new Date()) - clone.startDate_; +Blockly.BlockSvg.disposeUiStep_ = function(clone, rtl, start, workspaceScale) { + var ms = (new Date()) - start; var percent = ms / 150; if (percent > 1) { goog.dom.removeNode(clone); } else { var x = clone.translateX_ + - (rtl ? -1 : 1) * clone.bBox_.width / 2 * percent; - var y = clone.translateY_ + clone.bBox_.height * percent; - var translate = x + ', ' + y; - var scale = 1 - percent; - clone.setAttribute('transform', 'translate(' + translate + ')' + + (rtl ? -1 : 1) * clone.bBox_.width * workspaceScale / 2 * percent; + var y = clone.translateY_ + clone.bBox_.height * workspaceScale * percent; + var scale = (1 - percent) * workspaceScale; + clone.setAttribute('transform', 'translate(' + x + ',' + y + ')' + ' scale(' + scale + ')'); var closure = function() { - Blockly.BlockSvg.disposeUiStep_(clone, rtl); + Blockly.BlockSvg.disposeUiStep_(clone, rtl, start, workspaceScale); }; setTimeout(closure, 10); } @@ -1082,39 +1091,41 @@ Blockly.BlockSvg.prototype.connectionUiEffect = function() { this.workspace.playAudio('click'); // Determine the absolute coordinates of the inferior block. - var xy = Blockly.getSvgXY_(/** @type {!Element} */ (this.svgGroup_)); - // Offset the coordinates based on the two connection types. + var xy = Blockly.getSvgXY_(/** @type {!Element} */ (this.svgGroup_), + this.workspace); + // Offset the coordinates based on the two connection types, fix scale. if (this.outputConnection) { - xy.x += this.RTL ? 3 : -3; - xy.y += 13; + xy.x += (this.RTL ? 3 : -3) * this.workspace.scale; + xy.y += 13 * this.workspace.scale; } else if (this.previousConnection) { - xy.x += this.RTL ? -23 : 23; - xy.y += 3; + xy.x += (this.RTL ? -23 : 23) * this.workspace.scale; + xy.y += 3 * this.workspace.scale; } var ripple = Blockly.createSvgElement('circle', {'cx': xy.x, 'cy': xy.y, 'r': 0, 'fill': 'none', 'stroke': '#888', 'stroke-width': 10}, this.workspace.options.svg); // Start the animation. - ripple.startDate_ = new Date(); - Blockly.BlockSvg.connectionUiStep_(ripple); + Blockly.BlockSvg.connectionUiStep_(ripple, new Date(), this.workspace.scale); }; /** * Expand a ripple around a connection. * @param {!Element} ripple Element to animate. + * @param {!Date} start Date of animation's start. + * @param {number} workspaceScale Scale of workspace. * @private */ -Blockly.BlockSvg.connectionUiStep_ = function(ripple) { - var ms = (new Date()) - ripple.startDate_; +Blockly.BlockSvg.connectionUiStep_ = function(ripple, start, workspaceScale) { + var ms = (new Date()) - start; var percent = ms / 150; if (percent > 1) { goog.dom.removeNode(ripple); } else { - ripple.setAttribute('r', percent * 25); + ripple.setAttribute('r', percent * 25 * workspaceScale); ripple.style.opacity = 1 - percent; var closure = function() { - Blockly.BlockSvg.connectionUiStep_(ripple); + Blockly.BlockSvg.connectionUiStep_(ripple, start, workspaceScale); }; setTimeout(closure, 10); } @@ -1419,13 +1430,13 @@ Blockly.BlockSvg.prototype.renderFields_ = if (this.RTL) { cursorX -= field.renderSep + field.renderWidth; root.setAttribute('transform', - 'translate(' + cursorX + ', ' + cursorY + ')'); + 'translate(' + cursorX + ',' + cursorY + ')'); if (field.renderWidth) { cursorX -= Blockly.BlockSvg.SEP_SPACE_X; } } else { root.setAttribute('transform', - 'translate(' + (cursorX + field.renderSep) + ', ' + cursorY + ')'); + 'translate(' + (cursorX + field.renderSep) + ',' + cursorY + ')'); if (field.renderWidth) { cursorX += field.renderSep + field.renderWidth + Blockly.BlockSvg.SEP_SPACE_X; diff --git a/core/blockly.js b/core/blockly.js index fa8a9926c..883bba13f 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -79,8 +79,8 @@ Blockly.HSV_VALUE = 0.65; * Sprited icons and images. */ Blockly.SPRITE = { - width: 64, - height: 92, + width: 96, + height: 124, url: 'sprites.png' }; @@ -311,10 +311,9 @@ Blockly.onMouseMove_ = function(e) { // Move the scrollbars and the page will scroll automatically. workspace.scrollbar.set(-x - metrics.contentLeft, - -y - metrics.contentTop); + -y - metrics.contentTop); // Cancel the long-press if the drag has moved too far. - var dr = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); - if (dr > Blockly.DRAG_RADIUS) { + if (Math.sqrt(dx * dx + dy * dy) > Blockly.DRAG_RADIUS) { Blockly.longStop_(); } e.stopPropagation(); @@ -490,23 +489,22 @@ Blockly.getMainWorkspaceMetrics_ = function() { // Firefox has trouble with hidden elements (Bug 528969). return null; } + // Fix scale. + var contentWidth = blockBox.width; + var contentHeight = blockBox.height; + var contentX = blockBox.x * this.scale; + var contentY = blockBox.y * this.scale; if (this.scrollbar) { // Add a border around the content that is at least half a screenful wide. // Ensure border is wide enough that blocks can scroll over entire screen. - var MARGIN = 5; - var leftScroll = this.RTL ? - Blockly.Scrollbar.scrollbarThickness : 0; - var rightScroll = this.RTL ? - 0 : Blockly.Scrollbar.scrollbarThickness; - var leftEdge = Math.min(blockBox.x - viewWidth / 2, - blockBox.x + blockBox.width - viewWidth - leftScroll + MARGIN); - var rightEdge = Math.max(blockBox.x + blockBox.width + viewWidth / 2, - blockBox.x + viewWidth + rightScroll - MARGIN); - var topEdge = Math.min(blockBox.y - viewHeight / 2, - blockBox.y + blockBox.height - viewHeight + MARGIN); - var bottomEdge = Math.max(blockBox.y + blockBox.height + viewHeight / 2, - blockBox.y + viewHeight + Blockly.Scrollbar.scrollbarThickness - - MARGIN); + var leftEdge = Math.min(contentX - viewWidth / 2, + contentX + contentWidth - viewWidth); + var rightEdge = Math.max(contentX + contentWidth + viewWidth / 2, + contentX + viewWidth); + var topEdge = Math.min(contentY - viewHeight / 2, + contentY + contentHeight - viewHeight); + var bottomEdge = Math.max(contentY + contentHeight + viewHeight / 2, + contentY + viewHeight); } else { var leftEdge = blockBox.x; var rightEdge = leftEdge + blockBox.width; diff --git a/core/bubble.js b/core/bubble.js index d80c8b274..7ce540f54 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -267,13 +267,10 @@ Blockly.Bubble.prototype.bubbleMouseDown_ = function(e) { } // Left-click (or middle click) Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED); - // Record the starting offset between the current location and the mouse. - if (this.workspace_.RTL) { - this.dragDeltaX = this.relativeLeft_ + e.clientX; - } else { - this.dragDeltaX = this.relativeLeft_ - e.clientX; - } - this.dragDeltaY = this.relativeTop_ - e.clientY; + + this.workspace_.startDrag(e, + this.workspace_.RTL ? -this.relativeLeft_ : this.relativeLeft_, + this.relativeTop_); Blockly.Bubble.onMouseUpWrapper_ = Blockly.bindEvent_(document, 'mouseup', this, Blockly.Bubble.unbindDragEvents_); @@ -291,12 +288,9 @@ Blockly.Bubble.prototype.bubbleMouseDown_ = function(e) { */ Blockly.Bubble.prototype.bubbleMouseMove_ = function(e) { this.autoLayout_ = false; - if (this.workspace_.RTL) { - this.relativeLeft_ = this.dragDeltaX - e.clientX; - } else { - this.relativeLeft_ = this.dragDeltaX + e.clientX; - } - this.relativeTop_ = this.dragDeltaY + e.clientY; + var newXY = this.workspace_.moveDrag(e); + this.relativeLeft_ = this.workspace_.RTL ? -newXY.x : newXY.x; + this.relativeTop_ = newXY.y; this.positionBubble_(); this.renderArrow_(); }; @@ -316,13 +310,9 @@ Blockly.Bubble.prototype.resizeMouseDown_ = function(e) { } // Left-click (or middle click) Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED); - // Record the starting offset between the current location and the mouse. - if (this.workspace_.RTL) { - this.resizeDeltaWidth = this.width_ + e.clientX; - } else { - this.resizeDeltaWidth = this.width_ - e.clientX; - } - this.resizeDeltaHeight = this.height_ - e.clientY; + + this.workspace_.startDrag(e, + this.workspace_.RTL ? -this.width_ : this.width_, this.height_); Blockly.Bubble.onMouseUpWrapper_ = Blockly.bindEvent_(document, 'mouseup', this, Blockly.Bubble.unbindDragEvents_); @@ -340,16 +330,8 @@ Blockly.Bubble.prototype.resizeMouseDown_ = function(e) { */ Blockly.Bubble.prototype.resizeMouseMove_ = function(e) { this.autoLayout_ = false; - var w = this.resizeDeltaWidth; - var h = this.resizeDeltaHeight + e.clientY; - if (this.workspace_.RTL) { - // RTL drags the bottom-left corner. - w -= e.clientX; - } else { - // LTR drags the bottom-right corner. - w += e.clientX; - } - this.setBubbleSize(w, h); + var newXY = this.workspace_.moveDrag(e); + this.setBubbleSize(this.workspace_.RTL ? -newXY.x : newXY.x, newXY.y); if (this.workspace_.RTL) { // RTL requires the bubble to move its left edge. this.positionBubble_(); @@ -398,6 +380,8 @@ Blockly.Bubble.prototype.layoutBubble_ = function() { var relativeTop = -this.height_ - Blockly.BlockSvg.MIN_BLOCK_Y; // Prevent the bubble from being off-screen. var metrics = this.workspace_.getMetrics(); + metrics.viewWidth /= this.workspace_.scale; + metrics.viewLeft /= this.workspace_.scale; if (this.workspace_.RTL) { if (this.anchorX_ - metrics.viewLeft - relativeLeft - this.width_ < Blockly.Scrollbar.scrollbarThickness) { @@ -444,7 +428,7 @@ Blockly.Bubble.prototype.positionBubble_ = function() { } var top = this.relativeTop_ + this.anchorY_; this.bubbleGroup_.setAttribute('transform', - 'translate(' + left + ', ' + top + ')'); + 'translate(' + left + ',' + top + ')'); }; /** @@ -474,11 +458,10 @@ Blockly.Bubble.prototype.setBubbleSize = function(width, height) { // Mirror the resize group. var resizeSize = 2 * Blockly.Bubble.BORDER_WIDTH; this.resizeGroup_.setAttribute('transform', 'translate(' + - resizeSize + ', ' + - (height - doubleBorderWidth) + ') scale(-1 1)'); + resizeSize + ',' + (height - doubleBorderWidth) + ') scale(-1 1)'); } else { this.resizeGroup_.setAttribute('transform', 'translate(' + - (width - doubleBorderWidth) + ', ' + + (width - doubleBorderWidth) + ',' + (height - doubleBorderWidth) + ')'); } } diff --git a/core/comment.js b/core/comment.js index 4fc860e41..3f2c1f7d9 100644 --- a/core/comment.js +++ b/core/comment.js @@ -94,6 +94,10 @@ Blockly.Comment.prototype.createEditor_ = function() { body.appendChild(this.textarea_); this.foreignObject_.appendChild(body); Blockly.bindEvent_(this.textarea_, 'mouseup', this, this.textareaFocus_); + // Don't zoom with mousewheel. + Blockly.bindEvent_(this.textarea_, 'wheel', this, function(e) { + e.stopPropagation(); + }); return this.foreignObject_; }; diff --git a/core/css.js b/core/css.js index d1e7b8692..a025f75ef 100644 --- a/core/css.js +++ b/core/css.js @@ -118,10 +118,10 @@ Blockly.Css.setCursor = function(cursor) { // 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++) { - if (cursor == Blockly.Css.Cursor.OPEN) { - toolbox.style.cursor = ''; - } else { + if (cursor == Blockly.Css.Cursor.DELETE) { toolbox.style.cursor = url; + } else { + toolbox.style.cursor = ''; } } // Set cursor on the whole document, so that rapid movements @@ -294,9 +294,12 @@ Blockly.Css.CONTENT = [ '.blocklyHtmlInput {', ' border: none;', + ' border-radius: 4px;', ' font-family: sans-serif;', - ' font-size: 11pt;', + ' height: 100%;', + ' margin: 0;', ' outline: none;', + ' padding: 0 1px;', ' width: 100%', '}', @@ -329,6 +332,18 @@ Blockly.Css.CONTENT = [ ' fill: #bbb;', '}', + '.blocklyZoom>image {', + ' opacity: .4;', + '}', + + '.blocklyZoom>image:hover {', + ' opacity: .6;', + '}', + + '.blocklyZoom>image:active {', + ' opacity: .8;', + '}', + /* Darken flyout scrollbars due to being on a grey background. */ /* By contrast, workspace scrollbars are on a white background. */ '.blocklyFlyout .blocklyScrollbarKnob {', diff --git a/core/field.js b/core/field.js index a7dae1523..279d19539 100644 --- a/core/field.js +++ b/core/field.js @@ -98,7 +98,7 @@ Blockly.Field.prototype.init = function(block) { 'ry': 4, 'x': -Blockly.BlockSvg.SEP_SPACE_X / 2, 'y': -12, - 'height': 16}, this.fieldGroup_); + 'height': 16}, this.fieldGroup_, this.sourceBlock_.workspace); this.textElement_ = Blockly.createSvgElement('text', {'class': 'blocklyText'}, this.fieldGroup_); @@ -224,6 +224,18 @@ Blockly.Field.prototype.getSize = function() { return this.size_; }; +/** + * Returns the height and width of the field, + * accounting for the workspace scaling. + * @return {!Object} Height and width. + */ +Blockly.Field.prototype.getScaledBBox_ = function() { + var bBox = this.borderRect_.getBBox(); + bBox.width *= this.sourceBlock_.workspace.scale; + bBox.height *= this.sourceBlock_.workspace.scale; + return bBox; +}; + /** * Get the text from this field. * @return {string} Current text. diff --git a/core/field_colour.js b/core/field_colour.js index 18068f50e..ed738a3fa 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -170,7 +170,7 @@ Blockly.FieldColour.prototype.showEditor_ = function() { var windowSize = goog.dom.getViewportSize(); var scrollOffset = goog.style.getViewportPageOffset(document); var xy = this.getAbsoluteXY_(); - var borderBBox = this.borderRect_.getBBox(); + var borderBBox = this.getScaledBBox_(); var div = Blockly.WidgetDiv.DIV; picker.render(div); picker.setSelectedColor(this.getValue()); diff --git a/core/field_date.js b/core/field_date.js index cabd1262f..11f47d976 100644 --- a/core/field_date.js +++ b/core/field_date.js @@ -113,7 +113,7 @@ Blockly.FieldDate.prototype.showEditor_ = function() { var windowSize = goog.dom.getViewportSize(); var scrollOffset = goog.style.getViewportPageOffset(document); var xy = this.getAbsoluteXY_(); - var borderBBox = this.borderRect_.getBBox(); + var borderBBox = this.getScaledBBox_(); var div = Blockly.WidgetDiv.DIV; picker.render(div); picker.setDate(goog.date.fromIsoString(this.getValue())); diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 2e2a845a5..55cf53770 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -126,11 +126,13 @@ Blockly.FieldDropdown.prototype.showEditor_ = function() { } var menu = new goog.ui.Menu(); + menu.setRightToLeft(this.sourceBlock_.RTL); var options = this.getOptions_(); for (var x = 0; x < options.length; x++) { var text = options[x][0]; // Human-readable text. var value = options[x][1]; // Language-neutral value. var menuItem = new goog.ui.MenuItem(text); + menuItem.setRightToLeft(this.sourceBlock_.RTL); menuItem.setValue(value); menuItem.setCheckable(true); menu.addChild(menuItem, true); @@ -158,7 +160,7 @@ Blockly.FieldDropdown.prototype.showEditor_ = function() { var windowSize = goog.dom.getViewportSize(); var scrollOffset = goog.style.getViewportPageOffset(document); var xy = this.getAbsoluteXY_(); - var borderBBox = this.borderRect_.getBBox(); + var borderBBox = this.getScaledBBox_(); var div = Blockly.WidgetDiv.DIV; menu.render(div); var menuDom = menu.getElement(); diff --git a/core/field_image.js b/core/field_image.js index 6a4c70514..26fab813b 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -28,6 +28,7 @@ goog.provide('Blockly.FieldImage'); goog.require('Blockly.Field'); goog.require('goog.dom'); +goog.require('goog.math.Size'); goog.require('goog.userAgent'); @@ -45,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_ = {height: this.height_ + 10, width: this.width_}; + this.size_ = new goog.math.Size(this.height_ + 10, this.width_); this.text_ = opt_alt || ''; this.setValue(src); }; diff --git a/core/field_textinput.js b/core/field_textinput.js index 7fdc1d047..3fdbacd0f 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -49,6 +49,11 @@ Blockly.FieldTextInput = function(text, opt_changeHandler) { }; goog.inherits(Blockly.FieldTextInput, Blockly.Field); +/** + * Point size of text. Should match blocklyText's font-size in CSS. + */ +Blockly.FieldTextInput.FONTSIZE = 11; + /** * Mouse cursor style when over the hotspot that initiates the editor. */ @@ -126,6 +131,10 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(opt_quietInput) { // Create the input. var htmlInput = goog.dom.createDom('input', 'blocklyHtmlInput'); htmlInput.setAttribute('spellcheck', this.spellcheck_); + var fontSize = (Blockly.FieldTextInput.FONTSIZE * + this.sourceBlock_.workspace.scale) + 'pt'; + div.style.fontSize = fontSize; + htmlInput.style.fontSize = fontSize; /** @type {!HTMLInputElement} */ Blockly.FieldTextInput.htmlInput_ = htmlInput; div.appendChild(htmlInput); @@ -219,12 +228,15 @@ 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'; 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. if (this.sourceBlock_.RTL) { - var borderBBox = this.borderRect_.getBBox(); + var borderBBox = this.getScaledBBox_(); xy.x += borderBBox.width; xy.x -= div.offsetWidth; } @@ -266,8 +278,11 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() { Blockly.unbindEvent_(htmlInput.onKeyPressWrapper_); Blockly.unbindEvent_(htmlInput.onWorkspaceChangeWrapper_); Blockly.FieldTextInput.htmlInput_ = null; - // Delete the width property. - Blockly.WidgetDiv.DIV.style.width = 'auto'; + // Delete style properties. + var style = Blockly.WidgetDiv.DIV.style; + style.width = 'auto'; + style.height = 'auto'; + style.fontSize = ''; }; }; diff --git a/core/flyout.js b/core/flyout.js index 0073b259e..b764a2450 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -106,6 +106,12 @@ Blockly.Flyout.prototype.autoClose = true; */ Blockly.Flyout.prototype.CORNER_RADIUS = 8; +/** + * Top/bottom padding between scrollbar and edge of flyout background. + * @type {number} + * @const + */ +Blockly.Flyout.prototype.SCROLLBAR_PADDING = 2; /** * Creates the flyout's DOM. Only needs to be called once. @@ -128,12 +134,12 @@ Blockly.Flyout.prototype.createDom = function() { /** * Initializes the flyout. - * @param {!Blockly.Workspace} workspace The workspace in which to create new - * blocks. + * @param {!Blockly.Workspace} targetWorkspace The workspace in which to create + * new blocks. */ -Blockly.Flyout.prototype.init = function(workspace) { - this.targetWorkspace_ = workspace; - this.workspace_.targetWorkspace = workspace; +Blockly.Flyout.prototype.init = function(targetWorkspace) { + this.targetWorkspace_ = targetWorkspace; + this.workspace_.targetWorkspace = targetWorkspace; // Add scrollbar. this.scrollbar_ = new Blockly.Scrollbar(this.workspace_, false, false); @@ -141,9 +147,6 @@ Blockly.Flyout.prototype.init = function(workspace) { this.eventWrappers_.concat(Blockly.bindEvent_(this.svgGroup_, 'wheel', this, this.wheel_)); - // Safari needs mousewheel. - this.eventWrappers_.concat(Blockly.bindEvent_(this.svgGroup_, - 'mousewheel', this, this.wheel_)); this.eventWrappers_.concat( Blockly.bindEvent_(this.targetWorkspace_.getCanvas(), 'blocklyWorkspaceChange', this, this.filterForCapacity_)); @@ -191,7 +194,7 @@ Blockly.Flyout.prototype.getMetrics_ = function() { // Flyout is hidden. return null; } - var viewHeight = this.height_ - 2 * this.CORNER_RADIUS; + var viewHeight = this.height_ - 2 * this.SCROLLBAR_PADDING; var viewWidth = this.width_; try { var optionBox = this.workspace_.getCanvas().getBBox(); @@ -205,7 +208,7 @@ Blockly.Flyout.prototype.getMetrics_ = function() { contentHeight: optionBox.height + optionBox.y, viewTop: -this.workspace_.scrollY, contentTop: 0, - absoluteTop: this.CORNER_RADIUS, + absoluteTop: this.SCROLLBAR_PADDING, absoluteLeft: 0 }; }; @@ -290,8 +293,7 @@ Blockly.Flyout.prototype.scrollToTop = function() { * @private */ Blockly.Flyout.prototype.wheel_ = function(e) { - // Safari uses wheelDeltaY, everyone else uses deltaY. - var delta = e.deltaY || -e.wheelDeltaY; + var delta = e.deltaY; if (delta) { if (goog.userAgent.GECKO) { // Firefox's deltas are a tenth that of Chrome/Safari. @@ -304,6 +306,8 @@ Blockly.Flyout.prototype.wheel_ = function(e) { this.scrollbar_.set(y); // Don't scroll the page. e.preventDefault(); + // Don't propagate mousewheel event (zooming). + e.stopPropagation(); } }; @@ -582,8 +586,7 @@ Blockly.Flyout.prototype.onMouseMoveBlock_ = function(e) { var dx = e.clientX - Blockly.Flyout.startDownEvent_.clientX; var dy = e.clientY - Blockly.Flyout.startDownEvent_.clientY; // Still dragging within the sticky DRAG_RADIUS. - var dr = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); - if (dr > Blockly.DRAG_RADIUS) { + if (Math.sqrt(dx * dx + dy * dy) > Blockly.DRAG_RADIUS) { // Create the block. Blockly.Flyout.startFlyout_.createBlockFunc_(Blockly.Flyout.startBlock_)( Blockly.Flyout.startDownEvent_); @@ -598,6 +601,7 @@ Blockly.Flyout.prototype.onMouseMoveBlock_ = function(e) { */ Blockly.Flyout.prototype.createBlockFunc_ = function(originBlock) { var flyout = this; + var workspace = this.targetWorkspace_; return function(e) { if (Blockly.isRightButton(e)) { // Right-click. Don't create a block, let the context menu show. @@ -609,19 +613,41 @@ Blockly.Flyout.prototype.createBlockFunc_ = function(originBlock) { } // Create the new block by cloning the block in the flyout (via XML). var xml = Blockly.Xml.blockToDom_(originBlock); - var block = Blockly.Xml.domToBlock(flyout.targetWorkspace_, xml); + var block = Blockly.Xml.domToBlock(workspace, xml); // Place it in the same spot as the flyout copy. var svgRootOld = originBlock.getSvgRoot(); if (!svgRootOld) { throw 'originBlock is not rendered.'; } - var xyOld = Blockly.getSvgXY_(svgRootOld); + var xyOld = Blockly.getSvgXY_(svgRootOld, workspace); var svgRootNew = block.getSvgRoot(); if (!svgRootNew) { throw 'block is not rendered.'; } - var xyNew = Blockly.getSvgXY_(svgRootNew); - block.moveBy(xyOld.x - xyNew.x, xyOld.y - xyNew.y); + 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); + } if (flyout.autoClose) { flyout.hide(); } else { @@ -653,15 +679,18 @@ Blockly.Flyout.prototype.filterForCapacity_ = function() { */ Blockly.Flyout.prototype.getRect = function() { // BIG_NUM is offscreen padding so that blocks dragged beyond the shown flyout - // area are still deleted. Must be smaller than Infinity, but larger than - // the largest screen size. - var BIG_NUM = 10000000; - var x = Blockly.getSvgXY_(this.svgGroup_).x; + // area are still deleted. Must be larger than the largest screen size, + // but be smaller than half Number.MAX_SAFE_INTEGER (not available on IE). + var BIG_NUM = 1000000000; + var mainWorkspace = Blockly.mainWorkspace; + var x = Blockly.getSvgXY_(this.svgGroup_, mainWorkspace).x; if (!this.RTL) { x -= BIG_NUM; } - return new goog.math.Rect(x, -BIG_NUM, - BIG_NUM + this.width_, this.height_ + 2 * BIG_NUM); + // Fix scale if nested in zoomed workspace. + var scale = this.targetWorkspace_ == mainWorkspace ? 1 : mainWorkspace.scale; + return new goog.math.Rect(x, -BIG_NUM, + BIG_NUM + this.width_ * scale, BIG_NUM * 2); }; /** diff --git a/core/inject.js b/core/inject.js index dea3d6134..026e308f3 100644 --- a/core/inject.js +++ b/core/inject.js @@ -142,21 +142,14 @@ Blockly.parseOptions_ = function(options) { if (hasCss === undefined) { hasCss = true; } + // See grid documentation at: + // https://developers.google.com/blockly/installation/grid var grid = options['grid'] || {}; - if (!grid['spacing']) { - grid['spacing'] = 0; - } else { - grid['spacing'] = parseFloat(grid['spacing']); - } - if (!grid['colour']) { - grid['colour'] = '#888'; - } - if (!grid['length']) { - grid['length'] = 1; - } else { - grid['length'] = parseFloat(grid['length']); - } - grid['snap'] = grid['spacing'] > 0 && !!grid['snap']; + var gridOptions = {}; + gridOptions.spacing = parseFloat(grid['spacing']) || 0; + gridOptions.colour = grid['colour'] || '#888'; + gridOptions.length = parseFloat(grid['length']) || 1; + gridOptions.snap = gridOptions.spacing > 0 && !!grid['snap']; var pathToMedia = 'https://blockly-demo.appspot.com/static/media/'; if (options['media']) { pathToMedia = options['media']; @@ -164,6 +157,75 @@ Blockly.parseOptions_ = function(options) { // 'path' is a deprecated option which has been replaced by 'media'. pathToMedia = options['path'] + 'media/'; } + +/* TODO (fraser): Add documentation page: + * https://developers.google.com/blockly/installation/zoom + * + * enabled + * + * Set to `true` to allow zooming of the main workspace. Zooming is only + * possible if the workspace has scrollbars. If `false`, then the options + * below have no effect. Defaults to `false`. + * + * controls + * + * Set to `true` to show zoom-in and zoom-out buttons. Defaults to `true`. + * + * wheel + * + * Set to `true` to allow the mouse wheel to zoom. Defaults to `true`. + * + * maxScale + * + * Maximum multiplication factor for how far one can zoom in. Defaults to `3`. + * + * minScale + * + * Minimum multiplication factor for how far one can zoom out. Defaults to `0.3`. + * + * scaleSpeed + * + * For each zooming in-out step the scale is multiplied + * or divided respectively by the scale speed, this means that: + * `scale = scaleSpeed ^ steps`, note that in this formula + * steps of zoom-out are subtracted and zoom-in steps are added. + */ + // See zoom documentation at: + // https://developers.google.com/blockly/installation/zoom + var zoom = options['zoom'] || {}; + var zoomOptions = {}; + zoomOptions.enabled = hasScrollbars && !!zoom['enabled']; + if (zoomOptions.enabled) { + if (zoom['controls'] === undefined) { + zoomOptions.controls = true; + } else { + zoomOptions.controls = !!zoom['controls']; + } + if (zoom['wheel'] === undefined) { + zoomOptions.wheel = true; + } else { + zoomOptions.wheel = !!zoom['wheel']; + } + if (zoom['maxScale'] === undefined) { + zoomOptions.maxScale = 3; + } else { + zoomOptions.maxScale = parseFloat(zoom['maxScale']); + } + if (zoom['minScale'] === undefined) { + zoomOptions.minScale = 0.3; + } else { + zoomOptions.minScale = parseFloat(zoom['minScale']); + } + if (zoom['scaleSpeed'] === undefined) { + zoomOptions.scaleSpeed = 1.2; + } else { + zoomOptions.scaleSpeed = parseFloat(zoom['scaleSpeed']); + } + } else { + zoomOptions.controls = false; + zoomOptions.wheel = false; + } + var enableRealtime = !!options['realtime']; var realtimeOptions = enableRealtime ? options['realtimeOptions'] : undefined; @@ -181,7 +243,8 @@ Blockly.parseOptions_ = function(options) { hasSounds: hasSounds, hasCss: hasCss, languageTree: languageTree, - gridOptions: grid, + gridOptions: gridOptions, + zoomOptions: zoomOptions, enableRealtime: enableRealtime, realtimeOptions: realtimeOptions }; @@ -282,39 +345,24 @@ Blockly.createDom_ = function(container, options) { Blockly.createSvgElement('path', {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, disabledPattern); /* - - - + + + */ - // MSIE freaks if it sees a 0x0 pattern, so set empty patterns to 100x100. - var safeSpacing = options.gridOptions['spacing'] || 100; var gridPattern = Blockly.createSvgElement('pattern', {'id': 'blocklyGridPattern' + String(Math.random()).substring(2), - 'patternUnits': 'userSpaceOnUse', - 'width': safeSpacing, - 'height': safeSpacing}, defs); + 'patternUnits': 'userSpaceOnUse'}, defs); if (options.gridOptions['length'] > 0 && options.gridOptions['spacing'] > 0) { - var half = Math.floor(options.gridOptions['spacing'] / 2) + .5; - var start = half - options.gridOptions['length'] / 2; - var end = half + options.gridOptions['length'] / 2; Blockly.createSvgElement('line', - {'x1': start, - 'y1': half, - 'x2': end, - 'y2': half, - 'stroke': options.gridOptions['colour']}, + {'stroke': options.gridOptions['colour']}, gridPattern); if (options.gridOptions['length'] > 1) { Blockly.createSvgElement('line', - {'x1': half, - 'y1': start, - 'x2': half, - 'y2': end, - 'stroke': options.gridOptions['colour']}, + {'stroke': options.gridOptions['colour']}, gridPattern); } + // x1, y1, x1, x2 properties will be set later in updateGridPattern_. } options.gridPattern = gridPattern; options.svg = svg; @@ -446,7 +494,7 @@ Blockly.init_ = function(mainWorkspace) { if (options.RTL) { mainWorkspace.scrollX *= -1; } - var translation = 'translate(' + mainWorkspace.scrollX + ', 0)'; + var translation = 'translate(' + mainWorkspace.scrollX + ',0)'; mainWorkspace.getCanvas().setAttribute('transform', translation); mainWorkspace.getBubbleCanvas().setAttribute('transform', translation); } diff --git a/core/scrollbar.js b/core/scrollbar.js index 864c125e8..80adc623e 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -372,7 +372,7 @@ Blockly.Scrollbar.prototype.onMouseDownBar_ = function(e) { var mouseXY = Blockly.mouseToSvg(e, this.workspace_.options.svg); var mouseLocation = this.horizontal_ ? mouseXY.x : mouseXY.y; - var knobXY = Blockly.getSvgXY_(this.svgKnob_); + var knobXY = Blockly.getSvgXY_(this.svgKnob_, this.workspace_); var knobStart = this.horizontal_ ? knobXY.x : knobXY.y; var knobLength = parseFloat( this.svgKnob_.getAttribute(this.horizontal_ ? 'width' : 'height')); diff --git a/core/tooltip.js b/core/tooltip.js index d71a4cd76..4ac8049b9 100644 --- a/core/tooltip.js +++ b/core/tooltip.js @@ -196,8 +196,7 @@ Blockly.Tooltip.onMouseMove_ = function(e) { // shown and the current mouse position. Pythagorean theorem. var dx = Blockly.Tooltip.lastX_ - e.pageX; var dy = Blockly.Tooltip.lastY_ - e.pageY; - var dr = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); - if (dr > Blockly.Tooltip.RADIUS_OK) { + if (Math.sqrt(dx * dx + dy * dy) > Blockly.Tooltip.RADIUS_OK) { Blockly.Tooltip.hide(); } } else if (Blockly.Tooltip.poisonedElement_ != Blockly.Tooltip.element_) { diff --git a/core/trashcan.js b/core/trashcan.js index 3980c110a..35249e16b 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -230,7 +230,7 @@ Blockly.Trashcan.prototype.position = function() { * @return {goog.math.Rect} Rectangle in which to delete. */ Blockly.Trashcan.prototype.getRect = function() { - var trashXY = Blockly.getSvgXY_(this.svgGroup_); + var trashXY = Blockly.getSvgXY_(this.svgGroup_, this.workspace_); return new goog.math.Rect( trashXY.x - this.MARGIN_HOTSPOT_, trashXY.y - this.MARGIN_HOTSPOT_, diff --git a/core/utils.js b/core/utils.js index dd32d0fb8..149b365c6 100644 --- a/core/utils.js +++ b/core/utils.js @@ -30,6 +30,7 @@ goog.provide('Blockly.utils'); goog.require('goog.events.BrowserFeature'); goog.require('goog.userAgent'); +goog.require('goog.dom'); /** @@ -281,22 +282,37 @@ Blockly.getRelativeXY_ = function(element) { }; /** - * Return the absolute coordinates of the top-left corner of this element. - * The origin (0,0) is the top-left corner of the nearest SVG. + * Return the absolute coordinates of the top-left corner of this element, + * scales that after canvas SVG element, if it's a descendant. + * 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. * @private */ -Blockly.getSvgXY_ = function(element) { +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); do { // Loop through this block and every parent. var xy = Blockly.getRelativeXY_(element); - x += xy.x; - y += xy.y; + if (element == workspace.getCanvas() || + element == workspace.getBubbleCanvas()) { + canvasFlag = true; + } + // Before the SVG canvas scale the coordinates. + if (canvasFlag) { + x += xy.x; + y += xy.y; + } else { + x += xy.x * workspace.scale; + y += xy.y * workspace.scale; + } element = element.parentNode; - } while (element && element.nodeName.toLowerCase() != 'svg'); + } while (element && element != workspace.options.svg); return {x: x, y: y}; }; @@ -304,10 +320,12 @@ Blockly.getSvgXY_ = function(element) { * Helper method for creating SVG elements. * @param {string} name Element's tag name. * @param {!Object} attrs Dictionary of attribute names and values. - * @param {Element=} opt_parent Optional parent on which to append the element. + * @param {Element} parent Optional parent on which to append the element. + * @param {Blockly.Workspace=} opt_workspace Optional workspace for access to + * context (scale...). * @return {!SVGElement} Newly created SVG element. */ -Blockly.createSvgElement = function(name, attrs, opt_parent) { +Blockly.createSvgElement = function(name, attrs, parent, opt_workspace) { var e = /** @type {!SVGElement} */ ( document.createElementNS(Blockly.SVG_NS, name)); for (var key in attrs) { @@ -319,8 +337,8 @@ Blockly.createSvgElement = function(name, attrs, opt_parent) { if (document.body.runtimeStyle) { // Indicates presence of IE-only attr. e.runtimeStyle = e.currentStyle = e.style; } - if (opt_parent) { - opt_parent.appendChild(e); + if (parent) { + parent.appendChild(e); } return e; }; diff --git a/core/workspace.js b/core/workspace.js index b7fe0560e..bd62251c7 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -36,13 +36,12 @@ goog.require('goog.math'); * @constructor */ Blockly.Workspace = function(opt_options) { - /** - * @type {!Array.} - * @private - */ - this.topBlocks_ = []; + /** @type {!Object} */ this.options = opt_options || {}; + /** @type {boolean} */ this.RTL = !!this.options.RTL; + /** @type {!Array.} */ + this.topBlocks_ = []; }; /** diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 4b8d654af..bc9c9fdcd 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -30,6 +30,7 @@ goog.provide('Blockly.WorkspaceSvg'); // goog.require('Blockly.Block'); goog.require('Blockly.ScrollbarPair'); goog.require('Blockly.Trashcan'); +goog.require('Blockly.ZoomControls'); goog.require('Blockly.Workspace'); goog.require('Blockly.Xml'); @@ -90,6 +91,26 @@ Blockly.WorkspaceSvg.prototype.scrollX = 0; */ Blockly.WorkspaceSvg.prototype.scrollY = 0; +/** + * Horizontal distance from mouse to object being dragged. + * @type {number} + * @private + */ +Blockly.WorkspaceSvg.prototype.dragDeltaX_ = 0; + +/** + * Vertical distance from mouse to object being dragged. + * @type {number} + * @private + */ +Blockly.WorkspaceSvg.prototype.dragDeltaY_ = 0; + +/** + * Current scale. + * @type {number} + */ +Blockly.WorkspaceSvg.prototype.scale = 1; + /** * The workspace's trashcan (if any). * @type {Blockly.Trashcan} @@ -130,17 +151,23 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) { } } this.svgBlockCanvas_ = Blockly.createSvgElement('g', - {'class': 'blocklyBlockCanvas'}, this.svgGroup_); + {'class': 'blocklyBlockCanvas'}, this.svgGroup_, this); this.svgBubbleCanvas_ = Blockly.createSvgElement('g', - {'class': 'blocklyBubbleCanvas'}, this.svgGroup_); + {'class': 'blocklyBubbleCanvas'}, this.svgGroup_, this); if (this.options.hasTrashcan) { this.addTrashcan_(); } - + if (this.options.zoomOptions && this.options.zoomOptions.controls) { + this.addZoomControls_(); + } Blockly.bindEvent_(this.svgGroup_, 'mousedown', this, this.onMouseDown_); var thisWorkspace = this; Blockly.bindEvent_(this.svgGroup_, 'touchstart', null, - function(e) {Blockly.longStart_(e, thisWorkspace);}); + function(e) {Blockly.longStart_(e, thisWorkspace);}); + if (this.options.zoomOptions && this.options.zoomOptions.wheel) { + // Mouse-wheel. + Blockly.bindEvent_(this.svgGroup_, 'wheel', this, this.onMouseWheel_); + } // Determine if there needs to be a category tree, or a simple list of // blocks. This cannot be changed later, since the UI is very different. @@ -149,6 +176,7 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) { } else if (this.options.languageTree) { this.addFlyout_(); } + this.updateGridPattern_(); return this.svgGroup_; }; @@ -178,6 +206,10 @@ Blockly.WorkspaceSvg.prototype.dispose = function() { this.trashcan.dispose(); this.trashcan = null; } + if (this.zoomControls) { + this.zoomControls.dispose(); + this.zoomControls = null; + } if (!this.options.parentWorkspace) { // Top-most workspace. Dispose of the SVG too. goog.dom.removeNode(this.options.svg); @@ -195,6 +227,17 @@ Blockly.WorkspaceSvg.prototype.addTrashcan_ = function() { this.trashcan.init(); }; +/** + * Add zoom controls. + * @private + */ +Blockly.WorkspaceSvg.prototype.addZoomControls_ = function() { + this.zoomControls = new Blockly.ZoomControls(this); + var svgZoomControls = this.zoomControls.createDom(); + this.svgGroup_.appendChild(svgZoomControls); + this.zoomControls.init(); +}; + /** * Add a flyout. * @private @@ -223,6 +266,9 @@ Blockly.WorkspaceSvg.prototype.resize = function() { if (this.trashcan) { this.trashcan.position(); } + if (this.zoomControls) { + this.zoomControls.position(); + } if (this.scrollbar) { this.scrollbar.resize(); } @@ -250,7 +296,8 @@ Blockly.WorkspaceSvg.prototype.getBubbleCanvas = function() { * @param {number} y Vertical translation. */ Blockly.WorkspaceSvg.prototype.translate = function(x, y) { - var translation = 'translate(' + x + ',' + y + ')'; + var translation = 'translate(' + x + ',' + y + ')' + + 'scale(' + this.scale + ')'; this.svgBlockCanvas_.setAttribute('transform', translation); this.svgBubbleCanvas_.setAttribute('transform', translation); }; @@ -465,7 +512,7 @@ Blockly.WorkspaceSvg.prototype.recordDeleteAreas = function() { */ Blockly.WorkspaceSvg.prototype.isDeleteArea = function(e) { var isDelete = false; - var mouseXY = Blockly.mouseToSvg(e, this.options.svg); + var mouseXY = Blockly.mouseToSvg(e, Blockly.mainWorkspace.options.svg); var xy = new goog.math.Coordinate(mouseXY.x, mouseXY.y); if (this.deleteAreaTrash_) { if (this.deleteAreaTrash_.contains(xy)) { @@ -535,6 +582,52 @@ Blockly.WorkspaceSvg.prototype.onMouseDown_ = function(e) { e.stopPropagation(); }; +/** + * Start tracking a drag of an object on this workspace. + * @param {!Event} e Mouse down event. + * @param {number} x Starting horizontal location of object. + * @param {number} y Starting vertical location of object. + */ +Blockly.WorkspaceSvg.prototype.startDrag = function(e, x, y) { + // Record the starting offset between the bubble's location and the mouse. + var point = Blockly.mouseToSvg(e, this.options.svg); + // Fix scale of mouse event. + point.x /= this.scale; + point.y /= this.scale; + this.dragDeltaX_ = x - point.x; + this.dragDeltaY_ = y - point.y; +}; + +/** + * Track a drag of an object on this workspace. + * @param {!Event} e Mouse move event. + * @return {!goog.math.Coordinate} New location of object. + */ +Blockly.WorkspaceSvg.prototype.moveDrag = function(e) { + var point = Blockly.mouseToSvg(e, this.options.svg); + // Fix scale of mouse event. + point.x /= this.scale; + point.y /= this.scale; + var x = this.dragDeltaX_ + point.x; + var y = this.dragDeltaY_ + point.y; + return new goog.math.Coordinate(x, y); +}; + +/** + * Handle a mouse-wheel on SVG drawing surface. + * @param {!Event} e Mouse wheel event. + * @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; + var position = Blockly.mouseToSvg(e, this.options.svg); + this.zoom(position.x, position.y, delta); + e.preventDefault(); +}; + /** * Show the context menu for the workspace. * @param {!Event} e Mouse event. @@ -551,7 +644,7 @@ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) { if (this.options.collapse) { var hasCollapsedBlocks = false; var hasExpandedBlocks = false; - var topBlocks = this.getTopBlocks(false); + var topBlocks = this.getTopBlocks(true); for (var i = 0; i < topBlocks.length; i++) { var block = topBlocks[i]; while (block) { @@ -732,6 +825,102 @@ Blockly.WorkspaceSvg.prototype.markFocused = function() { Blockly.mainWorkspace = this; }; +/** + * Zooming the blocks centered in (x, y) coordinate with zooming in or out. + * @param {number} x X coordinate of center. + * @param {number} y Y coordinate of center. + * @param {number} type Type of zooming (-1 zooming out and 1 zooming in). + */ +Blockly.WorkspaceSvg.prototype.zoom = function(x, y, type) { + var speed = this.options.zoomOptions.scaleSpeed; + var metrics = this.getMetrics(); + var center = this.options.svg.createSVGPoint(); + center.x = x; + center.y = y; + center = center.matrixTransform(this.getCanvas().getCTM().inverse()); + x = center.x; + y = center.y; + var canvas = this.getCanvas(); + // Scale factor. + var scaleChange = (type == 1) ? speed : 1 / speed; + // Clamp scale within valid range. + var newScale = this.scale * scaleChange; + if (newScale > this.options.zoomOptions.maxScale) { + scaleChange = this.options.zoomOptions.maxScale / this.scale; + } else if (newScale < this.options.zoomOptions.minScale) { + scaleChange = this.options.zoomOptions.minScale / this.scale; + } + var matrix = canvas.getCTM() + .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(); + } +}; + +/** + * Zooming the blocks centered in the center of view with zooming in or out. + * @param {number} type Type of zooming (-1 zooming out and 1 zooming in). + */ +Blockly.WorkspaceSvg.prototype.zoomCenter = function(type) { + var metrics = this.getMetrics(); + var x = metrics.viewWidth / 2; + var y = metrics.viewHeight / 2; + this.zoom(x, y, type); +}; + +/** + * Reset zooming and dragging. + */ +Blockly.WorkspaceSvg.prototype.zoomReset = function() { + this.scale = 1; + this.updateGridPattern_(); + var metrics = this.getMetrics(); + this.scrollbar.set((metrics.contentWidth - metrics.viewWidth) / 2, + (metrics.contentHeight - metrics.viewHeight) / 2); +}; + +/** + * Updates the grid pattern. + * @private + */ +Blockly.WorkspaceSvg.prototype.updateGridPattern_ = function() { + if (!this.options.gridPattern) { + return; // No grid. + } + // MSIE freaks if it sees a 0x0 pattern, so set empty patterns to 100x100. + var safeSpacing = (this.options.gridOptions['spacing'] * this.scale) || 100; + this.options.gridPattern.setAttribute('width', safeSpacing); + this.options.gridPattern.setAttribute('height', safeSpacing); + var half = Math.floor(this.options.gridOptions['spacing'] / 2) + 0.5; + var start = half - this.options.gridOptions['length'] / 2; + var end = half + this.options.gridOptions['length'] / 2; + var line1 = this.options.gridPattern.firstChild; + var line2 = line1 && line1.nextSibling; + half *= this.scale; + start *= this.scale; + end *= this.scale; + if (line1) { + line1.setAttribute('stroke-width', this.scale); + line1.setAttribute('x1', start); + line1.setAttribute('y1', half); + line1.setAttribute('x2', end); + line1.setAttribute('y2', half); + } + if (line2) { + line2.setAttribute('stroke-width', this.scale); + line2.setAttribute('x1', half); + line2.setAttribute('y1', start); + line2.setAttribute('x2', half); + line2.setAttribute('y2', end); + } +}; + // Export symbols that would otherwise be renamed by Closure compiler. Blockly.WorkspaceSvg.prototype['setVisible'] = Blockly.WorkspaceSvg.prototype.setVisible; diff --git a/core/zoom_controls.js b/core/zoom_controls.js new file mode 100644 index 000000000..a788d55bb --- /dev/null +++ b/core/zoom_controls.js @@ -0,0 +1,213 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2015 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Object representing a zoom icons. + * @author carloslfu@gmail.com (Carlos Galarza) + */ +'use strict'; + +goog.provide('Blockly.ZoomControls'); + +goog.require('goog.dom'); + + +/** + * Class for a zoom controls. + * @param {!Blockly.Workspace} workspace The workspace to sit in. + * @constructor + */ +Blockly.ZoomControls = function(workspace) { + this.workspace_ = workspace; +}; + +/** + * Width of the zoom controls. + * @type {number} + * @private + */ +Blockly.ZoomControls.prototype.WIDTH_ = 32; + +/** + * Height of the zoom controls. + * @type {number} + * @private + */ +Blockly.ZoomControls.prototype.HEIGHT_ = 110; + +/** + * Distance between zoom controls and bottom edge of workspace. + * @type {number} + * @private + */ +Blockly.ZoomControls.prototype.MARGIN_BOTTOM_ = 100; + +/** + * Distance between zoom controls and right edge of workspace. + * @type {number} + * @private + */ +Blockly.ZoomControls.prototype.MARGIN_SIDE_ = 35; + +/** + * The SVG group containing the zoom controls. + * @type {Element} + * @private + */ +Blockly.ZoomControls.prototype.svgGroup_ = null; + +/** + * Left coordinate of the zoom controls. + * @type {number} + * @private + */ +Blockly.ZoomControls.prototype.left_ = 0; + +/** + * Top coordinate of the zoom controls. + * @type {number} + * @private + */ +Blockly.ZoomControls.prototype.top_ = 0; + +/** + * Create the zoom controls. + * @return {!Element} The zoom controls SVG group. + */ +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)"> + + */ + this.svgGroup_ = Blockly.createSvgElement('g', + {'class': 'blocklyZoom'}, null); + var rnd = String(Math.random()).substring(2); + var clip = Blockly.createSvgElement('clipPath', + {'id': 'blocklyZoomresetClipPath' + rnd}, + this.svgGroup_); + Blockly.createSvgElement('rect', + {'width': 32, 'height': 32}, + clip); + var zoomresetSvg = Blockly.createSvgElement('image', + {'width': Blockly.SPRITE.width, + 'height': Blockly.SPRITE.height, 'y': -92, + 'clip-path': 'url(#blocklyZoomresetClipPath' + rnd + ')'}, + this.svgGroup_); + zoomresetSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', + workspace.options.pathToMedia + Blockly.SPRITE.url); + + var clip = Blockly.createSvgElement('clipPath', + {'id': 'blocklyZoominClipPath' + rnd}, + this.svgGroup_); + Blockly.createSvgElement('rect', + {'width': 32, 'height': 32, 'y': 43}, + clip); + var zoominSvg = Blockly.createSvgElement('image', + {'width': Blockly.SPRITE.width, + 'height': Blockly.SPRITE.height, + 'x': -32, + 'y': -49, + 'clip-path': 'url(#blocklyZoominClipPath' + rnd + ')'}, + this.svgGroup_); + zoominSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', + workspace.options.pathToMedia + Blockly.SPRITE.url); + + var clip = Blockly.createSvgElement('clipPath', + {'id': 'blocklyZoomoutClipPath' + rnd}, + this.svgGroup_); + Blockly.createSvgElement('rect', + {'width': 32, 'height': 32, 'y': 77}, + clip); + var zoomoutSvg = Blockly.createSvgElement('image', + {'width': Blockly.SPRITE.width, + 'height': Blockly.SPRITE.height, 'x': -64, + 'y': -15, + 'clip-path': 'url(#blocklyZoomoutClipPath' + rnd + ')'}, + this.svgGroup_); + zoomoutSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', + workspace.options.pathToMedia + Blockly.SPRITE.url); + + // Attach event listeners. + Blockly.bindEvent_(zoomresetSvg, 'mousedown', workspace, workspace.zoomReset); + Blockly.bindEvent_(zoominSvg, 'mousedown', null, function() { + workspace.zoomCenter(1); + }); + Blockly.bindEvent_(zoomoutSvg, 'mousedown', null, function() { + workspace.zoomCenter(-1); + }); + + return this.svgGroup_; +}; + +/** + * Initialize the zoom controls. + */ +Blockly.ZoomControls.prototype.init = function() { + // Initialize some stuff... (animations?) +}; + +/** + * Dispose of this zoom controls. + * Unlink from all DOM elements to prevent memory leaks. + */ +Blockly.ZoomControls.prototype.dispose = function() { + if (this.svgGroup_) { + goog.dom.removeNode(this.svgGroup_); + this.svgGroup_ = null; + } + this.workspace_ = null; +}; + +/** + * Move the zoom controls to the bottom-right corner. + */ +Blockly.ZoomControls.prototype.position = function() { + var metrics = this.workspace_.getMetrics(); + if (!metrics) { + // There are no metrics available (workspace is probably not visible). + return; + } + if (this.workspace_.RTL) { + this.left_ = this.MARGIN_SIDE_; + } else { + this.left_ = metrics.viewWidth + metrics.absoluteLeft - + this.WIDTH_ - this.MARGIN_SIDE_; + } + this.top_ = metrics.viewHeight + metrics.absoluteTop - + this.HEIGHT_ - this.MARGIN_BOTTOM_; + this.svgGroup_.setAttribute('transform', + 'translate(' + this.left_ + ',' + this.top_ + ')'); +}; diff --git a/demos/code/code.js b/demos/code/code.js index 09d24739b..3433bbc7e 100644 --- a/demos/code/code.js +++ b/demos/code/code.js @@ -382,7 +382,9 @@ Code.init = function() { snap: true}, media: '../../media/', rtl: rtl, - toolbox: toolbox}); + toolbox: toolbox, + zoom: {enabled: true} + }); // Add to reserved word list: Local variables in execution evironment (runJS) // and the infinite loop detection function. diff --git a/media/sprites.png b/media/sprites.png index 5da3f46db..7f704a5f1 100644 Binary files a/media/sprites.png and b/media/sprites.png differ diff --git a/media/sprites.svg b/media/sprites.svg index e8d1ccf85..3f09ef3a4 100644 --- a/media/sprites.svg +++ b/media/sprites.svg @@ -1,5 +1,5 @@ - + - + @@ -41,4 +51,24 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/playground.html b/tests/playground.html index 5011a0852..1444036a9 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -65,10 +65,7 @@ function enableRealtimeSpecificUi() { function start() { var toolbox = document.getElementById('toolbox'); workspace = Blockly.inject('blocklyDiv', - {rtl: rtl, - media: '../media/', - toolbox: toolbox, - comments: true, + {comments: true, disable: true, collapse: true, grid: @@ -76,13 +73,24 @@ function start() { length: 3, colour: '#ccc', snap: true}, + media: '../media/', readOnly: false, realtime: false, realtimeOptions: {clientId: 'YOUR CLIENT ID GOES HERE', chatbox: {elementId: 'chatbox'}, collabElementId: 'collaborators'}, - scrollbars: true + rtl: rtl, + scrollbars: true, + toolbox: toolbox, + zoom: + {enabled: true, + controls: true, + wheel: true, + maxScale: 2, + minScale: .1, + scaleSpeed: 1.1 + }, }); if (Blockly.Realtime.isEnabled()) { enableRealtimeSpecificUi();