mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
Change workspace name to playgroundWorkspace.
This commit is contained in:
@@ -126,9 +126,9 @@ BlockOption.prototype.showPreviewBlock = function() {
|
|||||||
var blockOptPreviewID = this.dom.id + '_workspace';
|
var blockOptPreviewID = this.dom.id + '_workspace';
|
||||||
|
|
||||||
// Inject preview block.
|
// Inject preview block.
|
||||||
var workspace = Blockly.inject(blockOptPreviewID, {readOnly:true});
|
var demoWorkspace = Blockly.inject(blockOptPreviewID, {readOnly:true});
|
||||||
Blockly.Xml.domToWorkspace(this.previewBlockXml, workspace);
|
Blockly.Xml.domToWorkspace(this.previewBlockXml, demoWorkspace);
|
||||||
this.previewWorkspace = workspace;
|
this.previewWorkspace = demoWorkspace;
|
||||||
|
|
||||||
// Center the preview block in the workspace.
|
// Center the preview block in the workspace.
|
||||||
this.centerBlock();
|
this.centerBlock();
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
</xml>
|
</xml>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var workspace = Blockly.inject('blocklyDiv',
|
var demoWorkspace = Blockly.inject('blocklyDiv',
|
||||||
{media: '../../media/',
|
{media: '../../media/',
|
||||||
toolbox: document.getElementById('toolbox')});
|
toolbox: document.getElementById('toolbox')});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
</xml>
|
</xml>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var workspace = Blockly.inject('blocklyDiv',
|
var demoWorkspace = Blockly.inject('blocklyDiv',
|
||||||
{media: '../../media/',
|
{media: '../../media/',
|
||||||
toolbox: document.getElementById('toolbox')});
|
toolbox: document.getElementById('toolbox')});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -113,16 +113,16 @@
|
|||||||
</xml>
|
</xml>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var workspace = Blockly.inject('blocklyDiv',
|
var demoWorkspace = Blockly.inject('blocklyDiv',
|
||||||
{media: '../../media/',
|
{media: '../../media/',
|
||||||
toolbox: document.getElementById('toolbox')});
|
toolbox: document.getElementById('toolbox')});
|
||||||
Blockly.Xml.domToWorkspace(document.getElementById('startBlocks'),
|
Blockly.Xml.domToWorkspace(document.getElementById('startBlocks'),
|
||||||
workspace);
|
demoWorkspace);
|
||||||
|
|
||||||
function showCode() {
|
function showCode() {
|
||||||
// Generate JavaScript code and display it.
|
// Generate JavaScript code and display it.
|
||||||
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
|
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
|
||||||
var code = Blockly.JavaScript.workspaceToCode(workspace);
|
var code = Blockly.JavaScript.workspaceToCode(demoWorkspace);
|
||||||
alert(code);
|
alert(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@
|
|||||||
window.LoopTrap = 1000;
|
window.LoopTrap = 1000;
|
||||||
Blockly.JavaScript.INFINITE_LOOP_TRAP =
|
Blockly.JavaScript.INFINITE_LOOP_TRAP =
|
||||||
'if (--window.LoopTrap == 0) throw "Infinite loop.";\n';
|
'if (--window.LoopTrap == 0) throw "Infinite loop.";\n';
|
||||||
var code = Blockly.JavaScript.workspaceToCode(workspace);
|
var code = Blockly.JavaScript.workspaceToCode(demoWorkspace);
|
||||||
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
|
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
|
||||||
try {
|
try {
|
||||||
eval(code);
|
eval(code);
|
||||||
|
|||||||
@@ -109,9 +109,9 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Create a headless workspace.
|
// Create a headless workspace.
|
||||||
var workspace = new Blockly.Workspace();
|
var demoWorkspace = new Blockly.Workspace();
|
||||||
Blockly.Xml.domToWorkspace(xml, workspace);
|
Blockly.Xml.domToWorkspace(xml, demoWorkspace);
|
||||||
var code = Blockly.Python.workspaceToCode(workspace);
|
var code = Blockly.Python.workspaceToCode(demoWorkspace);
|
||||||
document.getElementById('code_output').value = code;
|
document.getElementById('code_output').value = code;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -132,11 +132,11 @@
|
|||||||
</xml>
|
</xml>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var workspace = Blockly.inject('blocklyDiv',
|
var demoWorkspace = Blockly.inject('blocklyDiv',
|
||||||
{media: '../../media/',
|
{media: '../../media/',
|
||||||
toolbox: document.getElementById('toolbox')});
|
toolbox: document.getElementById('toolbox')});
|
||||||
Blockly.Xml.domToWorkspace(document.getElementById('startBlocks'),
|
Blockly.Xml.domToWorkspace(document.getElementById('startBlocks'),
|
||||||
workspace);
|
demoWorkspace);
|
||||||
|
|
||||||
// Exit is used to signal the end of a script.
|
// Exit is used to signal the end of a script.
|
||||||
Blockly.JavaScript.addReservedWords('exit');
|
Blockly.JavaScript.addReservedWords('exit');
|
||||||
@@ -179,12 +179,12 @@
|
|||||||
var latestCode = '';
|
var latestCode = '';
|
||||||
|
|
||||||
function highlightBlock(id) {
|
function highlightBlock(id) {
|
||||||
workspace.highlightBlock(id);
|
demoWorkspace.highlightBlock(id);
|
||||||
highlightPause = true;
|
highlightPause = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetStepUi(clearOutput) {
|
function resetStepUi(clearOutput) {
|
||||||
workspace.highlightBlock(null);
|
demoWorkspace.highlightBlock(null);
|
||||||
highlightPause = false;
|
highlightPause = false;
|
||||||
runButton.disabled = '';
|
runButton.disabled = '';
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@
|
|||||||
// Generate JavaScript code and parse it.
|
// Generate JavaScript code and parse it.
|
||||||
Blockly.JavaScript.STATEMENT_PREFIX = 'highlightBlock(%1);\n';
|
Blockly.JavaScript.STATEMENT_PREFIX = 'highlightBlock(%1);\n';
|
||||||
Blockly.JavaScript.addReservedWords('highlightBlock');
|
Blockly.JavaScript.addReservedWords('highlightBlock');
|
||||||
latestCode = Blockly.JavaScript.workspaceToCode(workspace);
|
latestCode = Blockly.JavaScript.workspaceToCode(demoWorkspace);
|
||||||
|
|
||||||
resetStepUi(true);
|
resetStepUi(true);
|
||||||
}
|
}
|
||||||
@@ -250,7 +250,7 @@
|
|||||||
|
|
||||||
// Load the interpreter now, and upon future changes.
|
// Load the interpreter now, and upon future changes.
|
||||||
generateCodeAndLoadIntoInterpreter();
|
generateCodeAndLoadIntoInterpreter();
|
||||||
workspace.addChangeListener(function(event) {
|
demoWorkspace.addChangeListener(function(event) {
|
||||||
if (!(event instanceof Blockly.Events.Ui)) {
|
if (!(event instanceof Blockly.Events.Ui)) {
|
||||||
// Something changed. Parser needs to be reloaded.
|
// Something changed. Parser needs to be reloaded.
|
||||||
resetInterpreter();
|
resetInterpreter();
|
||||||
|
|||||||
@@ -134,11 +134,11 @@
|
|||||||
</xml>
|
</xml>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var workspace = Blockly.inject('blocklyDiv',
|
var demoWorkspace = Blockly.inject('blocklyDiv',
|
||||||
{media: '../../media/',
|
{media: '../../media/',
|
||||||
toolbox: document.getElementById('toolbox')});
|
toolbox: document.getElementById('toolbox')});
|
||||||
Blockly.Xml.domToWorkspace(document.getElementById('startBlocks'),
|
Blockly.Xml.domToWorkspace(document.getElementById('startBlocks'),
|
||||||
workspace);
|
demoWorkspace);
|
||||||
|
|
||||||
var outputArea = document.getElementById('output');
|
var outputArea = document.getElementById('output');
|
||||||
var stepButton = document.getElementById('stepButton');
|
var stepButton = document.getElementById('stepButton');
|
||||||
@@ -173,12 +173,12 @@
|
|||||||
var latestCode = '';
|
var latestCode = '';
|
||||||
|
|
||||||
function highlightBlock(id) {
|
function highlightBlock(id) {
|
||||||
workspace.highlightBlock(id);
|
demoWorkspace.highlightBlock(id);
|
||||||
highlightPause = true;
|
highlightPause = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetStepUi(clearOutput) {
|
function resetStepUi(clearOutput) {
|
||||||
workspace.highlightBlock(null);
|
demoWorkspace.highlightBlock(null);
|
||||||
highlightPause = false;
|
highlightPause = false;
|
||||||
|
|
||||||
if (clearOutput) {
|
if (clearOutput) {
|
||||||
@@ -190,7 +190,7 @@
|
|||||||
// Generate JavaScript code and parse it.
|
// Generate JavaScript code and parse it.
|
||||||
Blockly.JavaScript.STATEMENT_PREFIX = 'highlightBlock(%1);\n';
|
Blockly.JavaScript.STATEMENT_PREFIX = 'highlightBlock(%1);\n';
|
||||||
Blockly.JavaScript.addReservedWords('highlightBlock');
|
Blockly.JavaScript.addReservedWords('highlightBlock');
|
||||||
latestCode = Blockly.JavaScript.workspaceToCode(workspace);
|
latestCode = Blockly.JavaScript.workspaceToCode(demoWorkspace);
|
||||||
|
|
||||||
resetStepUi(true);
|
resetStepUi(true);
|
||||||
}
|
}
|
||||||
@@ -240,7 +240,7 @@
|
|||||||
|
|
||||||
// Load the interpreter now, and upon future changes.
|
// Load the interpreter now, and upon future changes.
|
||||||
generateCodeAndLoadIntoInterpreter();
|
generateCodeAndLoadIntoInterpreter();
|
||||||
workspace.addChangeListener(function(event) {
|
demoWorkspace.addChangeListener(function(event) {
|
||||||
if (!(event instanceof Blockly.Events.Ui)) {
|
if (!(event instanceof Blockly.Events.Ui)) {
|
||||||
// Something changed. Parser needs to be reloaded.
|
// Something changed. Parser needs to be reloaded.
|
||||||
generateCodeAndLoadIntoInterpreter();
|
generateCodeAndLoadIntoInterpreter();
|
||||||
|
|||||||
@@ -80,17 +80,17 @@
|
|||||||
</xml>
|
</xml>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var workspace = Blockly.inject('blocklyDiv',
|
var demoWorkspace = Blockly.inject('blocklyDiv',
|
||||||
{media: '../../media/',
|
{media: '../../media/',
|
||||||
maxBlocks: 5,
|
maxBlocks: 5,
|
||||||
toolbox: document.getElementById('toolbox')});
|
toolbox: document.getElementById('toolbox')});
|
||||||
|
|
||||||
function onchange(event) {
|
function onchange(event) {
|
||||||
document.getElementById('capacity').textContent =
|
document.getElementById('capacity').textContent =
|
||||||
workspace.remainingCapacity();
|
demoWorkspace.remainingCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
workspace.addChangeListener(onchange);
|
demoWorkspace.addChangeListener(onchange);
|
||||||
onchange();
|
onchange();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
<script>
|
<script>
|
||||||
var blocklyArea = document.getElementById('blocklyArea');
|
var blocklyArea = document.getElementById('blocklyArea');
|
||||||
var blocklyDiv = document.getElementById('blocklyDiv');
|
var blocklyDiv = document.getElementById('blocklyDiv');
|
||||||
var workspace = Blockly.inject(blocklyDiv,
|
var demoWorkspace = Blockly.inject(blocklyDiv,
|
||||||
{media: '../../media/',
|
{media: '../../media/',
|
||||||
toolbox: document.getElementById('toolbox')});
|
toolbox: document.getElementById('toolbox')});
|
||||||
var onresize = function(e) {
|
var onresize = function(e) {
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
};
|
};
|
||||||
window.addEventListener('resize', onresize, false);
|
window.addEventListener('resize', onresize, false);
|
||||||
onresize();
|
onresize();
|
||||||
Blockly.svgResize(workspace);
|
Blockly.svgResize(demoWorkspace);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -23,12 +23,12 @@
|
|||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
function init() {
|
function init() {
|
||||||
var workspace = Blockly.inject('blocklyDiv',
|
var demoWorkspace = Blockly.inject('blocklyDiv',
|
||||||
{media: '../../media/',
|
{media: '../../media/',
|
||||||
rtl: true,
|
rtl: true,
|
||||||
toolbox: document.getElementById('toolbox')});
|
toolbox: document.getElementById('toolbox')});
|
||||||
Blockly.Xml.domToWorkspace(document.getElementById('startBlocks'),
|
Blockly.Xml.domToWorkspace(document.getElementById('startBlocks'),
|
||||||
workspace);
|
demoWorkspace);
|
||||||
//window.onbeforeunload = function() {
|
//window.onbeforeunload = function() {
|
||||||
// return 'Leaving this page will result in the loss of your work.';
|
// return 'Leaving this page will result in the loss of your work.';
|
||||||
//};
|
//};
|
||||||
|
|||||||
@@ -80,7 +80,7 @@
|
|||||||
</xml>
|
</xml>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var workspace = Blockly.inject('blocklyDiv',
|
var demoWorkspace = Blockly.inject('blocklyDiv',
|
||||||
{media: '../../media/',
|
{media: '../../media/',
|
||||||
toolbox: document.getElementById('toolbox')});
|
toolbox: document.getElementById('toolbox')});
|
||||||
|
|
||||||
|
|||||||
@@ -334,7 +334,7 @@
|
|||||||
</xml>
|
</xml>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var workspace = Blockly.inject('blocklyDiv',
|
var demoWorkspace = Blockly.inject('blocklyDiv',
|
||||||
{media: '../../media/',
|
{media: '../../media/',
|
||||||
toolbox: document.getElementById('toolbox')});
|
toolbox: document.getElementById('toolbox')});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -73,10 +73,10 @@
|
|||||||
<script>
|
<script>
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var workspace = null;
|
var demoWorkspace = null;
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
workspace = Blockly.inject('blocklyDiv',
|
demoWorkspace = Blockly.inject('blocklyDiv',
|
||||||
{grid:
|
{grid:
|
||||||
{spacing: 25,
|
{spacing: 25,
|
||||||
length: 3,
|
length: 3,
|
||||||
@@ -129,14 +129,14 @@ function fromXml(xmlText) {
|
|||||||
output.value = xmlText;
|
output.value = xmlText;
|
||||||
output.scrollTop = 0;
|
output.scrollTop = 0;
|
||||||
output.scrollLeft = 0;
|
output.scrollLeft = 0;
|
||||||
workspace.clear();
|
demoWorkspace.clear();
|
||||||
try {
|
try {
|
||||||
var xmlDoc = Blockly.Xml.textToDom(xmlText);
|
var xmlDoc = Blockly.Xml.textToDom(xmlText);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert('Error parsing XML:\n' + e);
|
alert('Error parsing XML:\n' + e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Blockly.Xml.domToWorkspace(xmlDoc, workspace);
|
Blockly.Xml.domToWorkspace(xmlDoc, demoWorkspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setOutput(text) {
|
function setOutput(text) {
|
||||||
@@ -147,7 +147,8 @@ function setOutput(text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function toXml() {
|
function toXml() {
|
||||||
var xmlDom = Blockly.Xml.workspaceToDom(workspace, /* opt_noId */ true);
|
var xmlDom = Blockly.Xml.workspaceToDom(demoWorkspace,
|
||||||
|
/* opt_noId */ true);
|
||||||
var xmlText = Blockly.Xml.domToPrettyText(xmlDom);
|
var xmlText = Blockly.Xml.domToPrettyText(xmlDom);
|
||||||
xmlText = xmlText.replace(/ id="\d+"/g, '');
|
xmlText = xmlText.replace(/ id="\d+"/g, '');
|
||||||
setOutput(xmlText);
|
setOutput(xmlText);
|
||||||
@@ -155,34 +156,34 @@ function toXml() {
|
|||||||
|
|
||||||
function toJavaScript() {
|
function toJavaScript() {
|
||||||
var code = '\'use strict\';\n\n'
|
var code = '\'use strict\';\n\n'
|
||||||
code += Blockly.JavaScript.workspaceToCode(workspace);
|
code += Blockly.JavaScript.workspaceToCode(demoWorkspace);
|
||||||
setOutput(code);
|
setOutput(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toPython() {
|
function toPython() {
|
||||||
var code = Blockly.Python.workspaceToCode(workspace);
|
var code = Blockly.Python.workspaceToCode(demoWorkspace);
|
||||||
setOutput(code);
|
setOutput(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toPhp() {
|
function toPhp() {
|
||||||
var code = Blockly.PHP.workspaceToCode(workspace);
|
var code = Blockly.PHP.workspaceToCode(demoWorkspace);
|
||||||
setOutput(code);
|
setOutput(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toLua() {
|
function toLua() {
|
||||||
var code = Blockly.Lua.workspaceToCode(workspace);
|
var code = Blockly.Lua.workspaceToCode(demoWorkspace);
|
||||||
setOutput(code);
|
setOutput(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toDart() {
|
function toDart() {
|
||||||
var code = Blockly.Dart.workspaceToCode(workspace);
|
var code = Blockly.Dart.workspaceToCode(demoWorkspace);
|
||||||
setOutput(code);
|
setOutput(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeIndex() {
|
function changeIndex() {
|
||||||
var oneBasedIndex = document.getElementById('indexing').checked;
|
var oneBasedIndex = document.getElementById('indexing').checked;
|
||||||
workspace.options.oneBasedIndex = oneBasedIndex;
|
demoWorkspace.options.oneBasedIndex = oneBasedIndex;
|
||||||
workspace.toolbox_.flyout_.workspace_.options.oneBasedIndex = oneBasedIndex;
|
demoWorkspace.toolbox_.flyout_.workspace_.options.oneBasedIndex = oneBasedIndex;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user