From 13b0442f75ff02ffbf03e3bdb7b0788f352da643 Mon Sep 17 00:00:00 2001 From: hpnrep6 Date: Fri, 16 Jul 2021 13:42:09 -0400 Subject: [PATCH] Fix code in code demo executing twice on mobile (#5037) * Prevent code from executing twice on touchscreens --- demos/code/code.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/demos/code/code.js b/demos/code/code.js index 0c2765325..2377203a2 100644 --- a/demos/code/code.js +++ b/demos/code/code.js @@ -549,8 +549,14 @@ Code.initLanguage = function() { /** * Execute the user's code. * Just a quick and dirty eval. Catch infinite loops. + * @param {Event} event Event created from listener bound to the function. */ -Code.runJS = function() { +Code.runJS = function(event) { + // Prevent code from being executed twice on touchscreens. + if (event.type == 'touchend') { + event.preventDefault(); + } + Blockly.JavaScript.INFINITE_LOOP_TRAP = 'checkTimeout();\n'; var timeouts = 0; var checkTimeout = function() {