Fix field_image click handler (#1320)

This commit is contained in:
Rachel Fenichel
2017-09-18 13:01:19 -07:00
committed by GitHub
parent da6d392878
commit d4c21cea3a

View File

@@ -38,7 +38,8 @@ goog.require('goog.userAgent');
* @param {number} width Width of the image.
* @param {number} height Height of the image.
* @param {string=} opt_alt Optional alt text for when block is collapsed.
* @param {Function=} opt_onClick Optional function to be called when image is clicked
* @param {Function=} opt_onClick Optional function to be called when the image
* is clicked. If opt_onClick is defined, opt_alt must also be defined.
* @extends {Blockly.Field}
* @constructor
*/
@@ -92,6 +93,8 @@ Blockly.FieldImage.prototype.init = function() {
// Configure the field to be transparent with respect to tooltips.
this.setTooltip(this.sourceBlock_);
Blockly.Tooltip.bindMouseEvents(this.imageElement_);
this.maybeAddClickHandler_();
};
/**
@@ -103,6 +106,19 @@ Blockly.FieldImage.prototype.dispose = function() {
this.imageElement_ = null;
};
/**
* Bind events for a mouse down on the image, but only if a click handler has
* been defined.
* @private
*/
Blockly.FieldImage.prototype.maybeAddClickHandler_ = function() {
if (this.clickHandler_) {
this.mouseDownWrapper_ =
Blockly.bindEventWithChecks_(this.fieldGroup_, 'mousedown', this,
this.onMouseDown_);
}
};
/**
* Change the tooltip text for this field.
* @param {string|!Element} newTip Text for tooltip or a parent element to
@@ -171,8 +187,8 @@ Blockly.FieldImage.prototype.updateWidth = function() {
* If field click is called, and click handler defined,
* call the handler.
*/
Blockly.FieldImage.prototype.showEditor = function() {
if (this.clickHandler_){
this.clickHandler_(this);
}
};
Blockly.FieldImage.prototype.showEditor_ = function() {
if (this.clickHandler_){
this.clickHandler_(this);
}
};