Merge pull request #2084 from rachel-fenichel/bugfix/2030_remainder

Fix setting tooltips in field init for fields
This commit is contained in:
Rachel Fenichel
2018-10-17 14:00:35 -07:00
committed by GitHub
2 changed files with 22 additions and 6 deletions

View File

@@ -52,6 +52,7 @@ Blockly.FieldImage = function(src, width, height, opt_alt, opt_onClick) {
this.size_ = new goog.math.Size(this.width_,
this.height_ + 2 * Blockly.BlockSvg.INLINE_PADDING_Y);
this.text_ = opt_alt || '';
this.tooltip_ = '';
this.setValue(src);
if (typeof opt_onClick == 'function') {
@@ -108,8 +109,12 @@ Blockly.FieldImage.prototype.init = function() {
this.setValue(this.src_);
this.sourceBlock_.getSvgRoot().appendChild(this.fieldGroup_);
// Configure the field to be transparent with respect to tooltips.
this.setTooltip(this.sourceBlock_);
if (this.tooltip_) {
this.imageElement_.tooltip = this.tooltip_;
} else {
// Configure the field to be transparent with respect to tooltips.
this.setTooltip(this.sourceBlock_);
}
Blockly.Tooltip.bindMouseEvents(this.imageElement_);
this.maybeAddClickHandler_();
@@ -145,7 +150,10 @@ Blockly.FieldImage.prototype.maybeAddClickHandler_ = function() {
* link to for its tooltip.
*/
Blockly.FieldImage.prototype.setTooltip = function(newTip) {
this.imageElement_.tooltip = newTip;
this.tooltip_ = newTip;
if (this.imageElement_) {
this.imageElement_.tooltip = newTip;
}
};
/**

View File

@@ -44,6 +44,7 @@ Blockly.FieldLabel = function(text, opt_class) {
this.size_ = new goog.math.Size(0, 17.5);
this.class_ = opt_class;
this.setValue(text);
this.tooltip_ = '';
};
goog.inherits(Blockly.FieldLabel, Blockly.Field);
@@ -84,8 +85,12 @@ Blockly.FieldLabel.prototype.init = function() {
}
this.sourceBlock_.getSvgRoot().appendChild(this.textElement_);
// Configure the field to be transparent with respect to tooltips.
this.textElement_.tooltip = this.sourceBlock_;
if (this.tooltip_) {
this.textElement_.tooltip = this.tooltip_;
} else {
// Configure the field to be transparent with respect to tooltips.
this.textElement_.tooltip = this.sourceBlock_;
}
Blockly.Tooltip.bindMouseEvents(this.textElement_);
// Force a render.
this.render_();
@@ -116,7 +121,10 @@ Blockly.FieldLabel.prototype.getSvgRoot = function() {
* link to for its tooltip.
*/
Blockly.FieldLabel.prototype.setTooltip = function(newTip) {
this.textElement_.tooltip = newTip;
this.tooltip_ = newTip;
if (this.textElement_) {
this.textElement_.tooltip = newTip;
}
};
Blockly.Field.register('field_label', Blockly.FieldLabel);