From 94d3b6f4eaff6b879b2ce2b00dd5ba9b5069c0ca Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 21 Jul 2015 18:24:07 -0700 Subject: [PATCH] Add ellipsis to long fields. --- blockly_compressed.js | 6 +++--- core/field.js | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 29b1045aa..d08e520f7 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -913,15 +913,15 @@ Blockly.ConnectionDB.prototype=[];Blockly.ConnectionDB.constructor=Blockly.Conne 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_)}; // Copyright 2011 Google Inc. Apache License 2.0 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_)}; diff --git a/core/field.js b/core/field.js index f88cbb8bc..a7dae1523 100644 --- a/core/field.js +++ b/core/field.js @@ -45,6 +45,11 @@ Blockly.Field = function(text) { this.setText(text); }; +/** + * Maximum length of text to display before adding an ellipsis. + */ +Blockly.Field.prototype.maxDisplayLength = 50; + /** * Block this field is attached to. Starts as null, then in set in init. * @private @@ -261,6 +266,10 @@ Blockly.Field.prototype.updateTextNode_ = function() { return; } var text = this.text_; + if (text.length > this.maxDisplayLength) { + // Truncate displayed string and add an ellipsis ('...'). + text = text.substring(0, this.maxDisplayLength - 2) + '\u2026'; + } // Empty the text element. goog.dom.removeChildren(/** @type {!Element} */ (this.textElement_)); // Replace whitespace with non-breaking spaces so the text doesn't collapse.