Add test block for field image with a click handler (#3642)

This commit is contained in:
Sam El-Husseini
2020-01-23 16:19:24 -08:00
committed by GitHub
parent ae1058c3ea
commit f6b5e9ebb4
3 changed files with 19 additions and 0 deletions

View File

@@ -191,6 +191,10 @@ Blockly.FieldImage.prototype.initView = function() {
this.fieldGroup_));
this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS,
'xlink:href', /** @type {string} */ (this.value_));
if (this.clickHandler_) {
this.imageElement_.style.cursor = 'pointer';
}
};
/**

View File

@@ -1340,6 +1340,20 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
}
]); // END JSON EXTRACT (Do not delete this comment.)
Blockly.Blocks['test_images_clickhandler'] = {
init: function() {
this.appendDummyInput()
.appendField("Image click handler")
.appendField(new Blockly.FieldImage(
"https://blockly-demo.appspot.com/static/tests/media/a.png", 32, 32,
"image with click handlder", this.onClick_), "IMAGE");
this.setStyle('text_blocks');
},
onClick_: function() {
alert('Image clicked');
}
};
Blockly.Blocks['test_validators_text_null'] = {
init: function() {
this.appendDummyInput()

View File

@@ -1608,6 +1608,7 @@ var spaghettiXml = [
<block type="test_images_fliprtl"></block>
<block type="test_images_missing"></block>
<block type="test_images_many_icons"></block>
<block type="test_images_clickhandler"></block>
</category>
<category name="Emoji! o((*^ᴗ^*))o">
<label text="Unicode & Emojis"></label>