Commit 89d1aafd authored by Neil Fraser's avatar Neil Fraser

Update demos to use non-deprecated workspace calls.

parent c014799d
......@@ -32,8 +32,11 @@ blockly/
|- javascript_compressed.js
`- python_compressed.js
Instructions for fetching Closure may be found here:
Instructions for fetching the optional Closure library may be found here:
https://developers.google.com/blockly/hacking/closure
Go to https://appengine.google.com/ and create your App Engine application.
Modify the 'application' name of app.yaml to your App Engine application name.
Finally, upload this directory structure to your App Engine account,
wait a minute, then go to http://YOURNAME.appspot.com/
wait a minute, then go to http://YOURAPPNAME.appspot.com/
......@@ -74,8 +74,9 @@ skip_files:
- ^(.*/)?\..*$
# Custom skip patterns.
- ^static/appengine/.*$
- ^static/apps/json/.*$
- ^static/apps/_soy/.+\.jar$
- ^static/demos/plane/soy/.+\.jar$
- ^static/demos/plane/template.soy$
- ^static/demos/plane/xlf/.*$
- ^static/i18n/.*$
- ^static/msg/json/.*$
- ^.+\.soy$
......@@ -483,7 +483,7 @@ Code.runJS = function() {
throw MSG['timeout'];
}
};
var code = Blockly.JavaScript.workspaceToCode();
var code = Blockly.JavaScript.workspaceToCode(Code.workspace);
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
try {
eval(code);
......
......@@ -115,7 +115,7 @@
<script>
var workspace = Blockly.inject(document.getElementById('blocklyDiv'),
{toolbox: document.getElementById('toolbox')});
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace,
Blockly.Xml.domToWorkspace(workspace,
document.getElementById('startBlocks'));
function showCode() {
......
......@@ -174,6 +174,12 @@ Blockly.JavaScript['graph_set_y'] = function(block) {
*/
var Graph = {};
/**
* Main Blockly workspace.
* @type Blockly.WorkspaceSvg
*/
Graph.workspace = null;
/**
* Cached copy of the function string.
* @type ?string
......@@ -198,7 +204,7 @@ Graph.options_ = {
* https://developers.google.com/chart/interactive/docs/gallery/linechart
*/
Graph.drawVisualization = function() {
var formula = Blockly.JavaScript.workspaceToCode();
var formula = Blockly.JavaScript.workspaceToCode(Graph.workspace);
if (formula === Graph.oldFormula_) {
// No change in the formula, don't recompute.
return;
......@@ -263,14 +269,14 @@ Graph.resize = function() {
* Initialize Blockly and the graph. Called on page load.
*/
Graph.init = function() {
Blockly.inject(document.getElementById('blocklyDiv'),
Graph.workspace = Blockly.inject(document.getElementById('blocklyDiv'),
{toolbox: document.getElementById('toolbox')});
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace,
Blockly.Xml.domToWorkspace(Graph.workspace,
document.getElementById('startBlocks'));
// When Blockly changes, update the graph.
Blockly.addChangeListener(Graph.drawVisualization);
}
Graph.workspace.addChangeListener(Graph.drawVisualization);
};
window.addEventListener('load', Graph.init);
window.addEventListener('resize', Graph.resize);
......
......@@ -121,9 +121,9 @@
</xml>
<script>
Blockly.inject(document.getElementById('blocklyDiv'),
var workspace = Blockly.inject(document.getElementById('blocklyDiv'),
{toolbox: document.getElementById('toolbox')});
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace,
Blockly.Xml.domToWorkspace(workspace,
document.getElementById('startBlocks'));
var myInterpreter = null;
......@@ -157,7 +157,7 @@
var highlightPause = false;
function highlightBlock(id) {
Blockly.mainWorkspace.highlightBlock(id);
workspace.highlightBlock(id);
highlightPause = true;
}
......@@ -165,14 +165,14 @@
// Generate JavaScript code and parse it.
Blockly.JavaScript.STATEMENT_PREFIX = 'highlightBlock(%1);\n';
Blockly.JavaScript.addReservedWords('highlightBlock');
var code = Blockly.JavaScript.workspaceToCode();
var code = Blockly.JavaScript.workspaceToCode(workspace);
myInterpreter = new Interpreter(code, initApi);
alert('Ready to execute this code:\n\n' + code);
document.getElementById('stepButton').disabled = '';
highlightPause = false;
Blockly.mainWorkspace.traceOn(true);
Blockly.mainWorkspace.highlightBlock(null);
workspace.traceOn(true);
workspace.highlightBlock(null);
}
function stepCode() {
......
......@@ -79,15 +79,14 @@
</xml>
<script>
Blockly.inject(document.getElementById('blocklyDiv'),
var workspace = Blockly.inject(document.getElementById('blocklyDiv'),
{maxBlocks: 5, toolbox: document.getElementById('toolbox')});
function onchange() {
document.getElementById('capacity').innerHTML = Blockly.mainWorkspace.remainingCapacity();
document.getElementById('capacity').innerHTML = workspace.remainingCapacity();
}
Blockly.addChangeListener(onchange);
workspace.addChangeListener(onchange);
</script>
</body>
......
......@@ -74,6 +74,12 @@ Plane.LANGUAGE_NAME = {
*/
Plane.LANGUAGE_RTL = ['ar', 'fa', 'he'];
/**
* Main Blockly workspace.
* @type Blockly.WorkspaceSvg
*/
Plane.workspace = null;
/**
* Extracts a parameter from the URL.
* If the parameter is absent default_value is returned.
......@@ -137,11 +143,11 @@ Plane.loadBlocks = function(defaultXml) {
// Language switching stores the blocks during the reload.
delete window.sessionStorage.loadOnceBlocks;
var xml = Blockly.Xml.textToDom(loadOnce);
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, xml);
Blockly.Xml.domToWorkspace(Plane.workspace, xml);
} else if (defaultXml) {
// Load the editor with default starting blocks.
var xml = Blockly.Xml.textToDom(defaultXml);
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, xml);
Blockly.Xml.domToWorkspace(Plane.workspace, xml);
}
};
......@@ -154,7 +160,7 @@ Plane.changeLanguage = function() {
// not load Blockly.
// MSIE 11 does not support sessionStorage on file:// URLs.
if (typeof Blockly != 'undefined' && window.sessionStorage) {
var xml = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace);
var xml = Blockly.Xml.workspaceToDom(Plane.workspace);
var text = Blockly.Xml.domToText(xml);
window.sessionStorage.loadOnceBlocks = text;
}
......@@ -256,7 +262,7 @@ Plane.init = function() {
'width=725, initial-scale=.35, user-scalable=no');
}
Blockly.inject(document.getElementById('blockly'),
Plane.workspace = Blockly.inject(document.getElementById('blockly'),
{media: '../../media/',
rtl: Plane.isRtl(),
toolbox: document.getElementById('toolbox')});
......@@ -268,7 +274,7 @@ Plane.init = function() {
'</xml>';
Plane.loadBlocks(defaultXml);
Blockly.addChangeListener(Plane.recalculate);
Plane.workspace.addChangeListener(Plane.recalculate);
// Initialize the slider.
var svg = document.getElementById('plane');
......@@ -327,14 +333,14 @@ Plane.initLanguage = function() {
Plane.recalculate = function() {
// Find the 'set' block and use it as the formula root.
var rootBlock = null;
var blocks = Blockly.mainWorkspace.getTopBlocks(false);
var blocks = Plane.workspace.getTopBlocks(false);
for (var i = 0, block; block = blocks[i]; i++) {
if (block.type == 'plane_set_seats') {
rootBlock = block;
}
}
var seats = NaN;
Blockly.JavaScript.init(Blockly.mainWorkspace);
Blockly.JavaScript.init(Plane.workspace);
var code = Blockly.JavaScript.blockToCode(rootBlock);
try {
seats = eval(code);
......@@ -352,8 +358,8 @@ Plane.recalculate = function() {
block.customUpdate && block.customUpdate();
}
}
updateBlocks(Blockly.mainWorkspace.getAllBlocks());
updateBlocks(Blockly.mainWorkspace.flyout_.workspace_.getAllBlocks());
updateBlocks(Plane.workspace.getAllBlocks());
updateBlocks(Plane.workspace.flyout_.workspace_.getAllBlocks());
};
/**
......
......@@ -23,9 +23,9 @@
</style>
<script>
function init() {
Blockly.inject(document.getElementById('svgDiv'),
var workspace = Blockly.inject(document.getElementById('svgDiv'),
{rtl: true, toolbox: document.getElementById('toolbox')});
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace,
Blockly.Xml.domToWorkspace(workspace,
document.getElementById('startBlocks'));
//window.onbeforeunload = function() {
// return 'Leaving this page will result in the loss of your work.';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment