From f6b5e9ebb4d91505fbcd28349e61a58248cca1e6 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Thu, 23 Jan 2020 16:19:24 -0800 Subject: [PATCH] Add test block for field image with a click handler (#3642) --- core/field_image.js | 4 ++++ tests/blocks/test_blocks.js | 14 ++++++++++++++ tests/playground.html | 1 + 3 files changed, 19 insertions(+) diff --git a/core/field_image.js b/core/field_image.js index f60c40a92..96a2d272a 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -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'; + } }; /** diff --git a/tests/blocks/test_blocks.js b/tests/blocks/test_blocks.js index ff9b8a08b..bb1da03f9 100644 --- a/tests/blocks/test_blocks.js +++ b/tests/blocks/test_blocks.js @@ -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() diff --git a/tests/playground.html b/tests/playground.html index 3523caa67..3f4362eba 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -1608,6 +1608,7 @@ var spaghettiXml = [ +