Skip to content

Commit

Permalink
fix: update the playground to load compressed when hosted (google#5835)
Browse files Browse the repository at this point in the history
  • Loading branch information
alschmiedt authored Jan 6, 2022
1 parent 18b56d5 commit 2adf326
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1,710 deletions.
23 changes: 17 additions & 6 deletions tests/multi_playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
<head>
<meta charset="utf-8">
<title>Multi-toolbox Playground</title>
<script src="../blockly_uncompressed.js"></script>
<script src="../msg/messages.js"></script>

<script>
// Custom requires for the playground.
goog.require('Blockly.blocks.all');
</script>
<!-- This script loads uncompressed when on localhost and loads compressed when it is being hosted.
Please add any other dependencies to playgrounds/load_all.js.-->
<script src="playgrounds/load_all.js"></script>

<script>
'use strict';

const IS_UNCOMPRESSED = !!document.getElementById('blockly-uncompressed-script');

var options = {
comments: true,
collapse: true,
Expand All @@ -37,6 +38,7 @@
};

function start() {
setBackgroundColour();
var match = location.search.match(/toolbox=([^&]+)/);
var toolbox =
document.getElementById('toolbox-' + (match ? match[1] : 'categories'));
Expand All @@ -63,6 +65,15 @@
options.toolboxPosition = position;
Blockly.inject('blocklyDiv' + suffix, options);
}

function setBackgroundColour() {
// Set background colour to differentiate between compressed and uncompressed mode.
if (IS_UNCOMPRESSED) {
document.body.style.backgroundColor = '#d6d6ff'; // Familiar lilac.
} else {
document.body.style.backgroundColor = '#60fcfc'; // Unfamiliar blue.
}
}
</script>

<style>
Expand Down
33 changes: 10 additions & 23 deletions tests/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,14 @@
<head>
<meta charset="utf-8">
<title>Blockly Playground</title>
<script src="../blockly_uncompressed.js"></script>
<script src="../msg/messages.js"></script>
<script src="themes/test_themes.js"></script>
<script src="./playgrounds/screenshot.js"></script>
<script src="../node_modules/@blockly/block-test/dist/index.js"></script>

<script>
// Custom requires for the playground.
goog.require('Blockly.Dart.all');
goog.require('Blockly.JavaScript.all');
goog.require('Blockly.Lua.all');
goog.require('Blockly.PHP.all');
goog.require('Blockly.Python.all');
goog.require('Blockly.WorkspaceCommentSvg');
goog.require('Blockly.blocks.all');
</script>
<!-- This script loads uncompressed when on localhost and loads compressed when it is being hosted.
Please add any other dependencies to playgrounds/load_all.js.-->
<script src="playgrounds/load_all.js"></script>
<script>
'use strict';

const IS_UNCOMPRESSED = !!document.getElementById('blockly-uncompressed-script');
var workspace = null;

function start() {
Expand Down Expand Up @@ -97,14 +87,11 @@
}

function setBackgroundColour() {
// Set background colour to differentiate file: vs. localhost
// vs. server copy.
if (location.protocol === 'file:') {
document.body.style.backgroundColor = '#89A203'; // Unpleasant green.
} else if (location.hostname === 'localhost' ||
location.hostname === '127.0.0.1' ||
location.hostname === '[::1]') {
document.body.style.backgroundColor = '#d6d6ff'; // Familliar lilac.
// Set background colour to differentiate between compressed and uncompressed mode.
if (IS_UNCOMPRESSED) {
document.body.style.backgroundColor = '#d6d6ff'; // Familiar lilac.
} else {
document.body.style.backgroundColor = '#60fcfc'; // Unfamiliar blue.
}
}

Expand Down
Loading

0 comments on commit 2adf326

Please sign in to comment.