Parameter block is removed from init prototype of fields and its usage
is replaced by this.sourceBlock_
This commit is contained in:
miguel76 2016-04-09 12:01:38 -03:00
parent 78b4514f15
commit 1e3297ba0a
4 changed files with 12 additions and 14 deletions

View file

@ -58,14 +58,13 @@ Blockly.FieldCheckbox.prototype.CURSOR = 'default';
/**
* Install this checkbox on a block.
* @param {!Blockly.Block} block The block containing this text.
*/
Blockly.FieldCheckbox.prototype.init = function(block) {
Blockly.FieldCheckbox.prototype.init = function() {
if (this.fieldGroup_) {
// Checkbox has already been initialized once.
return;
}
Blockly.FieldCheckbox.superClass_.init.call(this, block);
Blockly.FieldCheckbox.superClass_.init.call(this);
// The checkbox doesn't use the inherited text element.
// Instead it uses a custom checkmark element that is either visible or not.
this.checkElement_ = Blockly.createSvgElement('text',

View file

@ -66,10 +66,9 @@ Blockly.FieldColour.prototype.columns_ = 0;
/**
* Install this field on a block.
* @param {!Blockly.Block} block The block containing this field.
*/
Blockly.FieldColour.prototype.init = function(block) {
Blockly.FieldColour.superClass_.init.call(this, block);
Blockly.FieldColour.prototype.init = function() {
Blockly.FieldColour.superClass_.init.call(this);
this.borderRect_.style['fillOpacity'] = 1;
this.setValue(this.getValue());
};

View file

@ -77,9 +77,8 @@ Blockly.FieldDropdown.prototype.CURSOR = 'default';
/**
* Install this dropdown on a block.
* @param {!Blockly.Block} block The block containing this text.
*/
Blockly.FieldDropdown.prototype.init = function(block) {
Blockly.FieldDropdown.prototype.init = function() {
if (this.fieldGroup_) {
// Dropdown has already been initialized once.
return;
@ -87,10 +86,10 @@ Blockly.FieldDropdown.prototype.init = function(block) {
// Add dropdown arrow: "option ▾" (LTR) or "▾ אופציה" (RTL)
this.arrow_ = Blockly.createSvgElement('tspan', {}, null);
this.arrow_.appendChild(document.createTextNode(
block.RTL ? Blockly.FieldDropdown.ARROW_CHAR + ' ' :
this.sourceBlock_.RTL ? Blockly.FieldDropdown.ARROW_CHAR + ' ' :
' ' + Blockly.FieldDropdown.ARROW_CHAR));
Blockly.FieldDropdown.superClass_.init.call(this, block);
Blockly.FieldDropdown.superClass_.init.call(this);
// Force a reset of the text to add the arrow.
var text = this.text_;
this.text_ = null;

View file

@ -79,18 +79,19 @@ Blockly.FieldVariable.prototype.setValidator = function(handler) {
/**
* Install this dropdown on a block.
* @param {!Blockly.Block} block The block containing this text.
*/
Blockly.FieldVariable.prototype.init = function(block) {
Blockly.FieldVariable.prototype.init = function() {
if (this.fieldGroup_) {
// Dropdown has already been initialized once.
return;
}
Blockly.FieldVariable.superClass_.init.call(this, block);
Blockly.FieldVariable.superClass_.init.call(this);
if (!this.getValue()) {
// Variables without names get uniquely named for this workspace.
var workspace =
block.isInFlyout ? block.workspace.targetWorkspace : block.workspace;
this.sourceBlock_.isInFlyout ?
this.sourceBlock_.workspace.targetWorkspace :
this.sourceBlock_.workspace;
this.setValue(Blockly.Variables.generateUniqueName(workspace));
}
};