mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-02 01:02:12 -04:00
Hide hidden fields (issue 37).
This commit is contained in:
parent
86f79502ce
commit
a624b5d2da
4 changed files with 18 additions and 11 deletions
|
@ -873,8 +873,8 @@ Blockly.ConnectionDB.prototype.removeConnection_=function(a){if(!a.inDB_)throw"C
|
|||
Blockly.ConnectionDB.init=function(a){var b=[];b[Blockly.INPUT_VALUE]=new Blockly.ConnectionDB;b[Blockly.OUTPUT_VALUE]=new Blockly.ConnectionDB;b[Blockly.NEXT_STATEMENT]=new Blockly.ConnectionDB;b[Blockly.PREVIOUS_STATEMENT]=new Blockly.ConnectionDB;a.connectionDBList=b};
|
||||
// Copyright 2012 Google Inc. Apache License 2.0
|
||||
Blockly.Field=function(a){this.size_=new goog.math.Size(0,25);this.setText(a)};Blockly.Field.prototype.sourceBlock_=null;Blockly.Field.prototype.visible_=!0;Blockly.Field.prototype.clone=function(){goog.asserts.fail("There should never be an instance of Field, only its derived classes.")};Blockly.Field.NBSP="\u00a0";Blockly.Field.prototype.EDITABLE=!0;
|
||||
Blockly.Field.prototype.init=function(a){this.sourceBlock_||(this.sourceBlock_=a,this.fieldGroup_=Blockly.createSvgElement("g",{},null),this.borderRect_=Blockly.createSvgElement("rect",{rx:4,ry:4,x:-Blockly.BlockSvg.SEP_SPACE_X/2,y:-12,height:16},this.fieldGroup_),this.textElement_=Blockly.createSvgElement("text",{"class":"blocklyText"},this.fieldGroup_),this.updateEditable(),a.getSvgRoot().appendChild(this.fieldGroup_),this.mouseUpWrapper_=Blockly.bindEvent_(this.fieldGroup_,"mouseup",this,this.onMouseUp_),
|
||||
this.updateTextNode_())};Blockly.Field.prototype.dispose=function(){this.mouseUpWrapper_&&(Blockly.unbindEvent_(this.mouseUpWrapper_),this.mouseUpWrapper_=null);this.sourceBlock_=null;goog.dom.removeNode(this.fieldGroup_);this.borderRect_=this.textElement_=this.fieldGroup_=null};
|
||||
Blockly.Field.prototype.init=function(a){this.sourceBlock_||(this.sourceBlock_=a,this.fieldGroup_=Blockly.createSvgElement("g",{},null),this.visible_||(this.fieldGroup_.style.display="none"),this.borderRect_=Blockly.createSvgElement("rect",{rx:4,ry:4,x:-Blockly.BlockSvg.SEP_SPACE_X/2,y:-12,height:16},this.fieldGroup_),this.textElement_=Blockly.createSvgElement("text",{"class":"blocklyText"},this.fieldGroup_),this.updateEditable(),a.getSvgRoot().appendChild(this.fieldGroup_),this.mouseUpWrapper_=Blockly.bindEvent_(this.fieldGroup_,
|
||||
"mouseup",this,this.onMouseUp_),this.updateTextNode_())};Blockly.Field.prototype.dispose=function(){this.mouseUpWrapper_&&(Blockly.unbindEvent_(this.mouseUpWrapper_),this.mouseUpWrapper_=null);this.sourceBlock_=null;goog.dom.removeNode(this.fieldGroup_);this.borderRect_=this.textElement_=this.fieldGroup_=null};
|
||||
Blockly.Field.prototype.updateEditable=function(){this.EDITABLE&&(this.sourceBlock_.isEditable()?(Blockly.addClass_(this.fieldGroup_,"blocklyEditableText"),Blockly.removeClass_(this.fieldGroup_,"blocklyNoNEditableText"),this.fieldGroup_.style.cursor=this.CURSOR):(Blockly.addClass_(this.fieldGroup_,"blocklyNonEditableText"),Blockly.removeClass_(this.fieldGroup_,"blocklyEditableText"),this.fieldGroup_.style.cursor=""))};Blockly.Field.prototype.isVisible=function(){return this.visible_};
|
||||
Blockly.Field.prototype.setVisible=function(a){if(this.visible_!=a){this.visible_=a;var b=this.getSvgRoot();b&&(b.style.display=a?"block":"none",this.render_())}};Blockly.Field.prototype.getSvgRoot=function(){return this.fieldGroup_};
|
||||
Blockly.Field.prototype.render_=function(){if(this.visible_&&this.textElement_){try{var a=this.textElement_.getComputedTextLength()}catch(b){a=8*this.textElement_.textContent.length}this.borderRect_&&this.borderRect_.setAttribute("width",a+Blockly.BlockSvg.SEP_SPACE_X)}else a=0;this.size_.width=a};Blockly.Field.prototype.getSize=function(){this.size_.width||this.render_();return this.size_};Blockly.Field.prototype.getText=function(){return this.text_};
|
||||
|
@ -896,8 +896,8 @@ Blockly.Tooltip.wrapScore_=function(a,b,c){for(var d=[0],e=[],f=0;f<a.length;f++
|
|||
Blockly.Tooltip.wrapMutate_=function(a,b,c){for(var d=Blockly.Tooltip.wrapScore_(a,b,c),e,f=0;f<b.length-1;f++)if(b[f]!=b[f+1]){var g=[].concat(b);g[f]=!g[f];g[f+1]=!g[f+1];var h=Blockly.Tooltip.wrapScore_(a,g,c);h>d&&(d=h,e=g)}return e?Blockly.Tooltip.wrapMutate_(a,e,c):b};Blockly.Tooltip.wrapToText_=function(a,b){for(var c=[],d=0;d<a.length;d++)c.push(a[d]),void 0!==b[d]&&c.push(b[d]?"\n":" ");return c.join("")};
|
||||
// Copyright 2012 Google Inc. Apache License 2.0
|
||||
Blockly.FieldLabel=function(a){this.sourceBlock_=null;this.size_=new goog.math.Size(0,25);this.setText(a)};goog.inherits(Blockly.FieldLabel,Blockly.Field);Blockly.FieldLabel.prototype.clone=function(){return new Blockly.FieldLabel(this.getText())};Blockly.FieldLabel.prototype.EDITABLE=!1;
|
||||
Blockly.FieldLabel.prototype.init=function(a){this.sourceBlock_||(this.sourceBlock_=a,this.textElement_=Blockly.createSvgElement("text",{"class":"blocklyText"},null),a.getSvgRoot().appendChild(this.textElement_),this.textElement_.tooltip=this.sourceBlock_,Blockly.Tooltip.bindMouseEvents(this.textElement_),this.updateTextNode_())};Blockly.FieldLabel.prototype.dispose=function(){goog.dom.removeNode(this.textElement_);this.textElement_=null};Blockly.FieldLabel.prototype.getSvgRoot=function(){return this.textElement_};
|
||||
Blockly.FieldLabel.prototype.setTooltip=function(a){this.textElement_.tooltip=a};
|
||||
Blockly.FieldLabel.prototype.init=function(a){this.sourceBlock_||(this.sourceBlock_=a,this.textElement_=Blockly.createSvgElement("text",{"class":"blocklyText"},null),this.visible_||(this.textElement_.style.display="none"),a.getSvgRoot().appendChild(this.textElement_),this.textElement_.tooltip=this.sourceBlock_,Blockly.Tooltip.bindMouseEvents(this.textElement_),this.updateTextNode_())};Blockly.FieldLabel.prototype.dispose=function(){goog.dom.removeNode(this.textElement_);this.textElement_=null};
|
||||
Blockly.FieldLabel.prototype.getSvgRoot=function(){return this.textElement_};Blockly.FieldLabel.prototype.setTooltip=function(a){this.textElement_.tooltip=a};
|
||||
// Copyright 2012 Google Inc. Apache License 2.0
|
||||
Blockly.Input=function(a,b,c,d){this.type=a;this.name=b;this.sourceBlock_=c;this.connection=d;this.fieldRow=[];this.align=Blockly.ALIGN_LEFT;this.visible_=!0};
|
||||
Blockly.Input.prototype.appendField=function(a,b){if(!a&&!b)return this;goog.isString(a)&&(a=new Blockly.FieldLabel(a));this.sourceBlock_.rendered&&a.init(this.sourceBlock_);a.name=b;a.prefixField&&this.appendField(a.prefixField);this.fieldRow.push(a);a.suffixField&&this.appendField(a.suffixField);this.sourceBlock_.rendered&&(this.sourceBlock_.render(),this.sourceBlock_.bumpNeighbours_());return this};
|
||||
|
@ -1019,9 +1019,9 @@ Blockly.ContextMenu.hide=function(){Blockly.WidgetDiv.hideIfOwner(Blockly.Contex
|
|||
// Copyright 2012 Google Inc. Apache License 2.0
|
||||
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_);this.updateMovable()};
|
||||
goog.inherits(Blockly.BlockSvg,Blockly.Block);Blockly.BlockSvg.prototype.height=0;Blockly.BlockSvg.prototype.width=0;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();Blockly.readOnly||this.eventsInit_||Blockly.bindEvent_(this.getSvgRoot(),"mousedown",this,this.onMouseDown_);this.getSvgRoot().parentNode||this.workspace.getCanvas().appendChild(this.getSvgRoot());goog.isFunction(this.onchange)&&!this.eventsInit_&&Blockly.bindEvent_(this.workspace.getCanvas(),
|
||||
"blocklyWorkspaceChange",this,this.onchange);this.eventsInit_=!0};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.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();Blockly.readOnly||this.eventsInit_||Blockly.bindEvent_(this.getSvgRoot(),"mousedown",this,this.onMouseDown_);goog.isFunction(this.onchange)&&!this.eventsInit_&&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();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))};
|
||||
|
|
|
@ -71,6 +71,7 @@ Blockly.BlockSvg.INLINE = -1;
|
|||
|
||||
/**
|
||||
* Create and initialize the SVG representation of the block.
|
||||
* May be called more than once.
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.initSvg = function() {
|
||||
goog.asserts.assert(this.workspace.rendered, 'Workspace is headless.');
|
||||
|
@ -85,16 +86,16 @@ Blockly.BlockSvg.prototype.initSvg = function() {
|
|||
Blockly.bindEvent_(this.getSvgRoot(), 'mousedown', this,
|
||||
this.onMouseDown_);
|
||||
}
|
||||
if (!this.getSvgRoot().parentNode) {
|
||||
this.workspace.getCanvas().appendChild(this.getSvgRoot());
|
||||
}
|
||||
|
||||
// Bind an onchange function, if it exists.
|
||||
if (goog.isFunction(this.onchange) && !this.eventsInit_) {
|
||||
Blockly.bindEvent_(this.workspace.getCanvas(), 'blocklyWorkspaceChange',
|
||||
this, this.onchange);
|
||||
}
|
||||
this.eventsInit_ = true;
|
||||
|
||||
if (!this.getSvgRoot().parentNode) {
|
||||
this.workspace.getCanvas().appendChild(this.getSvgRoot());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -88,6 +88,9 @@ Blockly.Field.prototype.init = function(block) {
|
|||
this.sourceBlock_ = block;
|
||||
// Build the DOM.
|
||||
this.fieldGroup_ = Blockly.createSvgElement('g', {}, null);
|
||||
if (!this.visible_) {
|
||||
this.fieldGroup_.style.display = 'none';
|
||||
}
|
||||
this.borderRect_ = Blockly.createSvgElement('rect',
|
||||
{'rx': 4,
|
||||
'ry': 4,
|
||||
|
|
|
@ -72,6 +72,9 @@ Blockly.FieldLabel.prototype.init = function(block) {
|
|||
// Build the DOM.
|
||||
this.textElement_ = Blockly.createSvgElement('text',
|
||||
{'class': 'blocklyText'}, null);
|
||||
if (!this.visible_) {
|
||||
this.textElement_.style.display = 'none';
|
||||
}
|
||||
block.getSvgRoot().appendChild(this.textElement_);
|
||||
|
||||
// Configure the field to be transparent with respect to tooltips.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue