From b5146036e140bedc83ee2dfd32ff44a1b251ad13 Mon Sep 17 00:00:00 2001 From: Sandeep Dubey Date: Wed, 19 Dec 2018 03:08:53 +0530 Subject: [PATCH] Fix #1632: Added alt attribute to the field image. (#2178) * Added alt for field image. * Removed lint issues. --- core/field_image.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/field_image.js b/core/field_image.js index 01ffb23d0..42683e321 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -51,9 +51,9 @@ Blockly.FieldImage = function(src, width, height, opt_alt, opt_onClick) { this.width_ = Number(width); this.size_ = new goog.math.Size(this.width_, this.height_ + 2 * Blockly.BlockSvg.INLINE_PADDING_Y); - this.text_ = opt_alt || ''; this.tooltip_ = ''; this.setValue(src); + this.setText(opt_alt); if (typeof opt_onClick == 'function') { this.clickHandler_ = opt_onClick; @@ -107,6 +107,7 @@ Blockly.FieldImage.prototype.init = function() { }, this.fieldGroup_); this.setValue(this.src_); + this.setText(this.text_); this.sourceBlock_.getSvgRoot().appendChild(this.fieldGroup_); if (this.tooltip_) { @@ -193,6 +194,9 @@ Blockly.FieldImage.prototype.setText = function(alt) { return; } this.text_ = alt; + if (this.imageElement_) { + this.imageElement_.setAttribute('alt', alt || ''); + } }; /**