Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion core/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ goog.provide('Blockly.Field');
goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockChange');
goog.require('Blockly.Gesture');
goog.require('Blockly.utils');
goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.Size');
goog.require('Blockly.utils.userAgent');
Expand All @@ -44,15 +45,30 @@ goog.require('Blockly.utils.style');
* @param {Function=} opt_validator A function that is called to validate
* changes to the field's value. Takes in a value & returns a validated
* value, or null to abort the change.
* @param {Object=} opt_config A map of options used to configure the field. See
* the individual field's documentation for a list of properties this
* parameter supports.
* @constructor
*/
Blockly.Field = function(value, opt_validator) {
Blockly.Field = function(value, opt_validator, opt_config) {
/**
* The size of the area rendered by the field.
* @type {Blockly.utils.Size}
*/
this.size_ = new Blockly.utils.Size(0, 0);

if (opt_config) {
var tooltip = opt_config['tooltip'];
if (typeof tooltip == 'string') {
tooltip = Blockly.utils.replaceMessageReferences(
opt_config['tooltip']);
}
tooltip && this.setTooltip(tooltip);

// TODO (#2884): Possibly add CSS class config option.
// TODO (#2885): Possibly add cursor config option.
}

this.setValue(value);
opt_validator && this.setValidator(opt_validator);
};
Expand Down
11 changes: 1 addition & 10 deletions core/field_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

goog.provide('Blockly.fieldRegistry');

goog.require('Blockly.utils');


/**
* The set of all registered fields, keyed by field type as used in the JSON
Expand Down Expand Up @@ -82,12 +80,5 @@ Blockly.fieldRegistry.fromJson = function(options) {
' being reached.');
return null;
}

var field = fieldClass.fromJson(options);
if (options['tooltip'] !== undefined) {
var rawValue = options['tooltip'];
var localizedText = Blockly.utils.replaceMessageReferences(rawValue);
field.setTooltip(localizedText);
}
return field;
return fieldClass.fromJson(options);
};
Loading