From 346b24aa74887998f3d696eb9b92f100bcba86ed Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 25 Sep 2018 13:59:26 -0700 Subject: [PATCH] Playground upgrades (#2063) Adds two new blocks to the playground's test blocks. Fixes dropdown which previously could not be set to 'Test Blocks' due to missing condition. Simplifies detection of file:// url. --- tests/blocks/test_blocks.js | 21 +++++++++++++++++++- tests/playground.html | 39 +++++++++++++++---------------------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/tests/blocks/test_blocks.js b/tests/blocks/test_blocks.js index 6c7ecccdc..2698e7e17 100644 --- a/tests/blocks/test_blocks.js +++ b/tests/blocks/test_blocks.js @@ -25,6 +25,25 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "message0": "", "args0": [] }, + { + "type": "value_to_stack", + "message0": "value to stack", + "nextStatement": null, + "output": null, + "colour": 230 + }, + { + "type": "value_to_statement", + "message0": "value to statement %1", + "args0": [ + { + "type": "input_statement", + "name": "STATEMENT" + } + ], + "output": null, + "colour": 230 + }, { "type": "example_dropdown_long", "message0": "long: %1", @@ -523,4 +542,4 @@ Blockly.Blocks['empty_block_with_mutator'] = { init: function() { this.setMutator(new Blockly.Mutator(['math_number'])); } -}; \ No newline at end of file +}; diff --git a/tests/playground.html b/tests/playground.html index 0b22f4a93..39b4283a5 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -70,15 +70,21 @@ var workspace = null; function start() { - setBackgroundColor(); + setBackgroundColour(); // Parse the URL arguments. var match = location.search.match(/dir=([^&]+)/); var rtl = match && match[1] == 'rtl'; document.forms.options.elements.dir.selectedIndex = Number(rtl); var toolbox = getToolboxElement(); + var toolboxNames = [ + 'toolbox-categories', + 'toolbox-categories-typed-variables', + 'toolbox-simple', + 'toolbox-test-blocks' + ]; document.forms.options.elements.toolbox.selectedIndex = - getToolboxFormIndex(toolbox.id); + toolboxNames.indexOf(toolbox.id); match = location.search.match(/side=([^&]+)/); var side = match ? match[1] : 'start'; document.forms.options.elements.side.value = side; @@ -110,7 +116,7 @@ function start() { wheel: true, startScale: 1.0, maxScale: 4, - minScale: .25, + minScale: 0.25, scaleSpeed: 1.1 } }); @@ -130,14 +136,11 @@ function start() { taChange(); } -function setBackgroundColor() { - var lilac = '#d6d6ff'; - - var currentPage = window.location.href; - var regexFile = /^file[\S]*$/; - - if (regexFile.test(currentPage)) { - document.getElementsByTagName('body')[0].style.backgroundColor = lilac; +function setBackgroundColour() { + // Set background colour to differentiate server vs local copy. + if (location.protocol == 'file:') { + var lilac = '#d6d6ff'; + document.body.style.backgroundColor = lilac; } } @@ -151,18 +154,6 @@ function getToolboxElement() { return document.getElementById('toolbox-' + toolboxSuffix); } -function getToolboxFormIndex(id) { - if (id == 'toolbox-categories') { - return 0; - } else if (id == 'toolbox-categories-typed-variables') { - return 1; - } else if (id == 'toolbox-simple') { - return 2; - } - // Didn't recognize it. - return 0; -} - function toXml() { var output = document.getElementById('importExport'); var xml = Blockly.Xml.workspaceToDom(workspace); @@ -1063,6 +1054,8 @@ h1 { + +