Commit d05177e1 authored by Neil Fraser's avatar Neil Fraser

Fix error when creating uneditable blocks with mutators.

parent 9e81d411
......@@ -1649,7 +1649,7 @@ Blockly.Mutator=function(a){Blockly.Mutator.superClass_.constructor.call(this,nu
Blockly.Mutator.prototype.createIcon=function(){if(!this.iconMark_){Blockly.Icon.prototype.createIcon_.call(this);var a=Blockly.Icon.RADIUS/2;Blockly.createSvgElement("rect",{"class":"blocklyIconShield",width:4*a,height:4*a,rx:a,ry:a},this.iconGroup_);this.iconMark_=Blockly.createSvgElement("text",{"class":"blocklyIconMark",x:Blockly.Icon.RADIUS,y:2*Blockly.Icon.RADIUS-4},this.iconGroup_);this.iconMark_.appendChild(document.createTextNode("\u2605"))}};
Blockly.Mutator.prototype.iconClick_=function(a){this.block_.isEditable()&&Blockly.Icon.prototype.iconClick_.call(this,a)};
Blockly.Mutator.prototype.createEditor_=function(){this.svgDialog_=Blockly.createSvgElement("svg",{x:Blockly.Bubble.BORDER_WIDTH,y:Blockly.Bubble.BORDER_WIDTH},null);Blockly.createSvgElement("rect",{"class":"blocklyMutatorBackground",height:"100%",width:"100%"},this.svgDialog_);var a=this;this.workspace_=new Blockly.WorkspaceSvg(function(){return a.getFlyoutMetrics_()},null);this.workspace_.flyout_=new Blockly.Flyout;this.workspace_.flyout_.autoClose=!1;this.svgDialog_.appendChild(this.workspace_.flyout_.createDom());
this.svgDialog_.appendChild(this.workspace_.createDom());return this.svgDialog_};Blockly.Mutator.prototype.updateEditable=function(){this.block_.isEditable()?Blockly.Icon.prototype.updateEditable.call(this):(this.setVisible(!1),Blockly.removeClass_(this.iconGroup_,"blocklyIconGroup"))};
this.svgDialog_.appendChild(this.workspace_.createDom());return this.svgDialog_};Blockly.Mutator.prototype.updateEditable=function(){this.block_.isEditable()?Blockly.Icon.prototype.updateEditable.call(this):(this.setVisible(!1),this.iconGroup_&&Blockly.removeClass_(this.iconGroup_,"blocklyIconGroup"))};
Blockly.Mutator.prototype.resizeBubble_=function(){var a=2*Blockly.Bubble.BORDER_WIDTH,b=this.workspace_.getCanvas().getBBox(),c=this.workspace_.flyout_.getMetrics_(),d;d=Blockly.RTL?-b.x:b.width+b.x;b=Math.max(b.height+3*a,c.contentHeight+20);d+=3*a;if(Math.abs(this.workspaceWidth_-d)>a||Math.abs(this.workspaceHeight_-b)>a)this.workspaceWidth_=d,this.workspaceHeight_=b,this.bubble_.setBubbleSize(d+a,b+a),this.svgDialog_.setAttribute("width",this.workspaceWidth_),this.svgDialog_.setAttribute("height",
this.workspaceHeight_);Blockly.RTL&&(a="translate("+this.workspaceWidth_+",0)",this.workspace_.getCanvas().setAttribute("transform",a))};
Blockly.Mutator.prototype.setVisible=function(a){if(a!=this.isVisible())if(a){this.bubble_=new Blockly.Bubble(this.block_.workspace,this.createEditor_(),this.block_.svgPath_,this.iconX_,this.iconY_,null,null);var b=this;this.workspace_.flyout_.init(this.workspace_);var c=[];a=0;for(var d;d=this.quarkNames_[a];a++)c[a]=goog.dom.createDom("block",{type:d});this.workspace_.flyout_.show(c);this.rootBlock_=this.block_.decompose(this.workspace_);c=this.rootBlock_.getDescendants();for(a=0;d=c[a];a++)d.render();
......
......@@ -136,8 +136,10 @@ Blockly.Mutator.prototype.updateEditable = function() {
} else {
// Close any mutator bubble. Icon is not clickable.
this.setVisible(false);
Blockly.removeClass_(/** @type {!Element} */ (this.iconGroup_),
'blocklyIconGroup');
if (this.iconGroup_) {
Blockly.removeClass_(/** @type {!Element} */ (this.iconGroup_),
'blocklyIconGroup');
}
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment