From 06858e8972f35596d9b8c2bcc3462a617a84d225 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 2 Feb 2016 16:20:02 -0800 Subject: [PATCH] Trivial number/text/colour blocks should inherit parent's tooltip. --- blocks/colour.js | 8 +++++++- blocks/math.js | 8 +++++++- blocks/text.js | 8 +++++++- core/tooltip.js | 4 ++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/blocks/colour.js b/blocks/colour.js index 7c92122ba..e425612dd 100644 --- a/blocks/colour.js +++ b/blocks/colour.js @@ -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; + }); } }; diff --git a/blocks/math.js b/blocks/math.js index f89704143..81fadc5b8 100644 --- a/blocks/math.js +++ b/blocks/math.js @@ -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; + }); } }; diff --git a/blocks/text.js b/blocks/text.js index 4d85c974c..c95f79ef8 100644 --- a/blocks/text.js +++ b/blocks/text.js @@ -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. diff --git a/core/tooltip.js b/core/tooltip.js index 4ac8049b9..4a8b83f32 100644 --- a/core/tooltip.js +++ b/core/tooltip.js @@ -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);