mirror of
https://github.com/google/blockly.git
synced 2026-01-04 23:50:12 +01:00
Generate helpURL and tooltip for Javascript block definition
This commit is contained in:
@@ -250,20 +250,10 @@ FactoryUtils.formatJson_ = function(blockType, rootBlock) {
|
||||
var hue = parseInt(colourBlock.getFieldValue('HUE'), 10);
|
||||
JS.colour = hue;
|
||||
}
|
||||
// Tooltip.
|
||||
var tooltipBlock = rootBlock.getInputTargetBlock('TOOLTIP');
|
||||
if (tooltipBlock && !tooltipBlock.disabled) {
|
||||
JS.tooltip = tooltipBlock.getFieldValue('TEXT');
|
||||
} else {
|
||||
JS.tooltip = '';
|
||||
}
|
||||
// Help URL.
|
||||
var helpUrlBlock = rootBlock.getInputTargetBlock('HELPURL');
|
||||
if (helpUrlBlock && !helpUrlBlock.disabled) {
|
||||
JS.helpUrl = helpUrlBlock.getFieldValue('TEXT');
|
||||
} else {
|
||||
JS.helpUrl = 'http://www.example.com/';
|
||||
}
|
||||
|
||||
JS.tooltip = FactoryUtils.getTooltipFromRootBlock_(rootBlock);
|
||||
JS.helpUrl = FactoryUtils.getHelpUrlFromRootBlock_(rootBlock);
|
||||
|
||||
return JSON.stringify(JS, null, ' ');
|
||||
};
|
||||
|
||||
@@ -346,9 +336,11 @@ FactoryUtils.formatJavaScript_ = function(blockType, rootBlock, workspace) {
|
||||
code.push(' this.setColour(' + hue + ');');
|
||||
}
|
||||
}
|
||||
// TODO: Rachel: tooltip and helpurl
|
||||
code.push(" this.setTooltip('');");
|
||||
code.push(" this.setHelpUrl('http://www.example.com/');");
|
||||
|
||||
var tooltip = FactoryUtils.getTooltipFromRootBlock_(rootBlock);
|
||||
var helpUrl = FactoryUtils.getHelpUrlFromRootBlock_(rootBlock);
|
||||
code.push(" this.setTooltip('" + tooltip + "');");
|
||||
code.push(" this.setHelpUrl('" + helpUrl + "');");
|
||||
code.push(' }');
|
||||
code.push('};');
|
||||
return code.join('\n');
|
||||
@@ -964,3 +956,31 @@ FactoryUtils.savedBlockChanges = function(blockLibraryController) {
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Given the root block of the factory, return the tooltip specified by the user
|
||||
* or the empty string if no tooltip is found.
|
||||
* @param {!Blockly.Block} rootBlock Factory_base block.
|
||||
* @return {string} The tooltip for the generated block, or the empty string.
|
||||
*/
|
||||
FactoryUtils.getTooltipFromRootBlock_ = function(rootBlock) {
|
||||
var tooltipBlock = rootBlock.getInputTargetBlock('TOOLTIP');
|
||||
if (tooltipBlock && !tooltipBlock.disabled) {
|
||||
return tooltipBlock.getFieldValue('TEXT');
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
/**
|
||||
* Given the root block of the factory, return the help url specified by the
|
||||
* user or the empty string if no tooltip is found.
|
||||
* @param {!Blockly.Block} rootBlock Factory_base block.
|
||||
* @return {string} The help url for the generated block, or the empty string.
|
||||
*/
|
||||
FactoryUtils.getHelpUrlFromRootBlock_ = function(rootBlock) {
|
||||
var helpUrlBlock = rootBlock.getInputTargetBlock('HELPURL');
|
||||
if (helpUrlBlock && !helpUrlBlock.disabled) {
|
||||
return helpUrlBlock.getFieldValue('TEXT');
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user