Trivial number/text/colour blocks should inherit parent's tooltip.

This commit is contained in:
Neil Fraser
2016-02-02 16:20:02 -08:00
parent acd6af1c45
commit 06858e8972
4 changed files with 23 additions and 5 deletions

View File

@@ -51,9 +51,15 @@ Blockly.Blocks['colour_picker'] = {
],
"output": "Colour",
"colour": Blockly.Blocks.colour.HUE,
"tooltip": Blockly.Msg.COLOUR_PICKER_TOOLTIP,
"helpUrl": Blockly.Msg.COLOUR_PICKER_HELPURL
});
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
// Colour block is trivial. Use tooltip of parent block if it exists.
this.setTooltip(function() {
var parent = thisBlock.getParent();
return (parent && parent.tooltip) || Blockly.Msg.COLOUR_PICKER_TOOLTIP;
});
}
};

View File

@@ -46,7 +46,13 @@ Blockly.Blocks['math_number'] = {
.appendField(new Blockly.FieldTextInput('0',
Blockly.FieldTextInput.numberValidator), 'NUM');
this.setOutput(true, 'Number');
this.setTooltip(Blockly.Msg.MATH_NUMBER_TOOLTIP);
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
// Number block is trivial. Use tooltip of parent block if it exists.
this.setTooltip(function() {
var parent = thisBlock.getParent();
return (parent && parent.tooltip) || Blockly.Msg.MATH_NUMBER_TOOLTIP;
});
}
};

View File

@@ -47,7 +47,13 @@ Blockly.Blocks['text'] = {
.appendField(new Blockly.FieldTextInput(''), 'TEXT')
.appendField(this.newQuote_(false));
this.setOutput(true, 'String');
this.setTooltip(Blockly.Msg.TEXT_TEXT_TOOLTIP);
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
// Text block is trivial. Use tooltip of parent block if it exists.
this.setTooltip(function() {
var parent = thisBlock.getParent();
return (parent && parent.tooltip) || Blockly.Msg.TEXT_TEXT_TOOLTIP;
});
},
/**
* Create an image of an open or closed quote.

View File

@@ -99,7 +99,7 @@ Blockly.Tooltip.RADIUS_OK = 10;
/**
* Delay before tooltip appears.
*/
Blockly.Tooltip.HOVER_MS = 1000;
Blockly.Tooltip.HOVER_MS = 750;
/**
* Horizontal padding between tooltip and screen edge.
@@ -236,7 +236,7 @@ Blockly.Tooltip.show_ = function() {
goog.dom.removeChildren(/** @type {!Element} */ (Blockly.Tooltip.DIV));
// Get the new text.
var tip = Blockly.Tooltip.element_.tooltip;
if (goog.isFunction(tip)) {
while (goog.isFunction(tip)) {
tip = tip();
}
tip = Blockly.Tooltip.wrap_(tip, Blockly.Tooltip.LIMIT);