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/ ...@@ -32,8 +32,11 @@ blockly/
|- javascript_compressed.js |- javascript_compressed.js
`- python_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 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, 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: ...@@ -74,8 +74,9 @@ skip_files:
- ^(.*/)?\..*$ - ^(.*/)?\..*$
# Custom skip patterns. # Custom skip patterns.
- ^static/appengine/.*$ - ^static/appengine/.*$
- ^static/apps/json/.*$ - ^static/demos/plane/soy/.+\.jar$
- ^static/apps/_soy/.+\.jar$ - ^static/demos/plane/template.soy$
- ^static/demos/plane/xlf/.*$
- ^static/i18n/.*$ - ^static/i18n/.*$
- ^static/msg/json/.*$ - ^static/msg/json/.*$
- ^.+\.soy$ - ^.+\.soy$
...@@ -483,7 +483,7 @@ Code.runJS = function() { ...@@ -483,7 +483,7 @@ Code.runJS = function() {
throw MSG['timeout']; throw MSG['timeout'];
} }
}; };
var code = Blockly.JavaScript.workspaceToCode(); var code = Blockly.JavaScript.workspaceToCode(Code.workspace);
Blockly.JavaScript.INFINITE_LOOP_TRAP = null; Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
try { try {
eval(code); eval(code);
......
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
<script> <script>
var workspace = Blockly.inject(document.getElementById('blocklyDiv'), var workspace = Blockly.inject(document.getElementById('blocklyDiv'),
{toolbox: document.getElementById('toolbox')}); {toolbox: document.getElementById('toolbox')});
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, Blockly.Xml.domToWorkspace(workspace,
document.getElementById('startBlocks')); document.getElementById('startBlocks'));
function showCode() { function showCode() {
......
...@@ -174,6 +174,12 @@ Blockly.JavaScript['graph_set_y'] = function(block) { ...@@ -174,6 +174,12 @@ Blockly.JavaScript['graph_set_y'] = function(block) {
*/ */
var Graph = {}; var Graph = {};
/**
* Main Blockly workspace.
* @type Blockly.WorkspaceSvg
*/
Graph.workspace = null;
/** /**
* Cached copy of the function string. * Cached copy of the function string.
* @type ?string * @type ?string
...@@ -198,7 +204,7 @@ Graph.options_ = { ...@@ -198,7 +204,7 @@ Graph.options_ = {
* https://developers.google.com/chart/interactive/docs/gallery/linechart * https://developers.google.com/chart/interactive/docs/gallery/linechart
*/ */
Graph.drawVisualization = function() { Graph.drawVisualization = function() {
var formula = Blockly.JavaScript.workspaceToCode(); var formula = Blockly.JavaScript.workspaceToCode(Graph.workspace);
if (formula === Graph.oldFormula_) { if (formula === Graph.oldFormula_) {
// No change in the formula, don't recompute. // No change in the formula, don't recompute.
return; return;
...@@ -263,14 +269,14 @@ Graph.resize = function() { ...@@ -263,14 +269,14 @@ Graph.resize = function() {
* Initialize Blockly and the graph. Called on page load. * Initialize Blockly and the graph. Called on page load.
*/ */
Graph.init = function() { Graph.init = function() {
Blockly.inject(document.getElementById('blocklyDiv'), Graph.workspace = Blockly.inject(document.getElementById('blocklyDiv'),
{toolbox: document.getElementById('toolbox')}); {toolbox: document.getElementById('toolbox')});
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, Blockly.Xml.domToWorkspace(Graph.workspace,
document.getElementById('startBlocks')); document.getElementById('startBlocks'));
// When Blockly changes, update the graph. // When Blockly changes, update the graph.
Blockly.addChangeListener(Graph.drawVisualization); Graph.workspace.addChangeListener(Graph.drawVisualization);
} };
window.addEventListener('load', Graph.init); window.addEventListener('load', Graph.init);
window.addEventListener('resize', Graph.resize); window.addEventListener('resize', Graph.resize);
......
...@@ -121,9 +121,9 @@ ...@@ -121,9 +121,9 @@
</xml> </xml>
<script> <script>
Blockly.inject(document.getElementById('blocklyDiv'), var workspace = Blockly.inject(document.getElementById('blocklyDiv'),
{toolbox: document.getElementById('toolbox')}); {toolbox: document.getElementById('toolbox')});
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, Blockly.Xml.domToWorkspace(workspace,
document.getElementById('startBlocks')); document.getElementById('startBlocks'));
var myInterpreter = null; var myInterpreter = null;
...@@ -157,7 +157,7 @@ ...@@ -157,7 +157,7 @@
var highlightPause = false; var highlightPause = false;
function highlightBlock(id) { function highlightBlock(id) {
Blockly.mainWorkspace.highlightBlock(id); workspace.highlightBlock(id);
highlightPause = true; highlightPause = true;
} }
...@@ -165,14 +165,14 @@ ...@@ -165,14 +165,14 @@
// 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');
var code = Blockly.JavaScript.workspaceToCode(); var code = Blockly.JavaScript.workspaceToCode(workspace);
myInterpreter = new Interpreter(code, initApi); myInterpreter = new Interpreter(code, initApi);
alert('Ready to execute this code:\n\n' + code); alert('Ready to execute this code:\n\n' + code);
document.getElementById('stepButton').disabled = ''; document.getElementById('stepButton').disabled = '';
highlightPause = false; highlightPause = false;
Blockly.mainWorkspace.traceOn(true); workspace.traceOn(true);
Blockly.mainWorkspace.highlightBlock(null); workspace.highlightBlock(null);
} }
function stepCode() { function stepCode() {
......
...@@ -79,15 +79,14 @@ ...@@ -79,15 +79,14 @@
</xml> </xml>
<script> <script>
Blockly.inject(document.getElementById('blocklyDiv'), var workspace = Blockly.inject(document.getElementById('blocklyDiv'),
{maxBlocks: 5, toolbox: document.getElementById('toolbox')}); {maxBlocks: 5, toolbox: document.getElementById('toolbox')});
function onchange() { function onchange() {
document.getElementById('capacity').innerHTML = Blockly.mainWorkspace.remainingCapacity(); document.getElementById('capacity').innerHTML = workspace.remainingCapacity();
} }
Blockly.addChangeListener(onchange); workspace.addChangeListener(onchange);
</script> </script>
</body> </body>
......
...@@ -74,6 +74,12 @@ Plane.LANGUAGE_NAME = { ...@@ -74,6 +74,12 @@ Plane.LANGUAGE_NAME = {
*/ */
Plane.LANGUAGE_RTL = ['ar', 'fa', 'he']; Plane.LANGUAGE_RTL = ['ar', 'fa', 'he'];
/**
* Main Blockly workspace.
* @type Blockly.WorkspaceSvg
*/
Plane.workspace = null;
/** /**
* Extracts a parameter from the URL. * Extracts a parameter from the URL.
* If the parameter is absent default_value is returned. * If the parameter is absent default_value is returned.
...@@ -137,11 +143,11 @@ Plane.loadBlocks = function(defaultXml) { ...@@ -137,11 +143,11 @@ Plane.loadBlocks = function(defaultXml) {
// Language switching stores the blocks during the reload. // Language switching stores the blocks during the reload.
delete window.sessionStorage.loadOnceBlocks; delete window.sessionStorage.loadOnceBlocks;
var xml = Blockly.Xml.textToDom(loadOnce); var xml = Blockly.Xml.textToDom(loadOnce);
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, xml); Blockly.Xml.domToWorkspace(Plane.workspace, xml);
} else if (defaultXml) { } else if (defaultXml) {
// Load the editor with default starting blocks. // Load the editor with default starting blocks.
var xml = Blockly.Xml.textToDom(defaultXml); 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() { ...@@ -154,7 +160,7 @@ Plane.changeLanguage = function() {
// not load Blockly. // not load Blockly.
// MSIE 11 does not support sessionStorage on file:// URLs. // MSIE 11 does not support sessionStorage on file:// URLs.
if (typeof Blockly != 'undefined' && window.sessionStorage) { 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); var text = Blockly.Xml.domToText(xml);
window.sessionStorage.loadOnceBlocks = text; window.sessionStorage.loadOnceBlocks = text;
} }
...@@ -256,7 +262,7 @@ Plane.init = function() { ...@@ -256,7 +262,7 @@ Plane.init = function() {
'width=725, initial-scale=.35, user-scalable=no'); 'width=725, initial-scale=.35, user-scalable=no');
} }
Blockly.inject(document.getElementById('blockly'), Plane.workspace = Blockly.inject(document.getElementById('blockly'),
{media: '../../media/', {media: '../../media/',
rtl: Plane.isRtl(), rtl: Plane.isRtl(),
toolbox: document.getElementById('toolbox')}); toolbox: document.getElementById('toolbox')});
...@@ -268,7 +274,7 @@ Plane.init = function() { ...@@ -268,7 +274,7 @@ Plane.init = function() {
'</xml>'; '</xml>';
Plane.loadBlocks(defaultXml); Plane.loadBlocks(defaultXml);
Blockly.addChangeListener(Plane.recalculate); Plane.workspace.addChangeListener(Plane.recalculate);
// Initialize the slider. // Initialize the slider.
var svg = document.getElementById('plane'); var svg = document.getElementById('plane');
...@@ -327,14 +333,14 @@ Plane.initLanguage = function() { ...@@ -327,14 +333,14 @@ Plane.initLanguage = function() {
Plane.recalculate = function() { Plane.recalculate = function() {
// Find the 'set' block and use it as the formula root. // Find the 'set' block and use it as the formula root.
var rootBlock = null; var rootBlock = null;
var blocks = Blockly.mainWorkspace.getTopBlocks(false); var blocks = Plane.workspace.getTopBlocks(false);
for (var i = 0, block; block = blocks[i]; i++) { for (var i = 0, block; block = blocks[i]; i++) {
if (block.type == 'plane_set_seats') { if (block.type == 'plane_set_seats') {
rootBlock = block; rootBlock = block;
} }
} }
var seats = NaN; var seats = NaN;
Blockly.JavaScript.init(Blockly.mainWorkspace); Blockly.JavaScript.init(Plane.workspace);
var code = Blockly.JavaScript.blockToCode(rootBlock); var code = Blockly.JavaScript.blockToCode(rootBlock);
try { try {
seats = eval(code); seats = eval(code);
...@@ -352,8 +358,8 @@ Plane.recalculate = function() { ...@@ -352,8 +358,8 @@ Plane.recalculate = function() {
block.customUpdate && block.customUpdate(); block.customUpdate && block.customUpdate();
} }
} }
updateBlocks(Blockly.mainWorkspace.getAllBlocks()); updateBlocks(Plane.workspace.getAllBlocks());
updateBlocks(Blockly.mainWorkspace.flyout_.workspace_.getAllBlocks()); updateBlocks(Plane.workspace.flyout_.workspace_.getAllBlocks());
}; };
/** /**
......
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
</style> </style>
<script> <script>
function init() { function init() {
Blockly.inject(document.getElementById('svgDiv'), var workspace = Blockly.inject(document.getElementById('svgDiv'),
{rtl: true, toolbox: document.getElementById('toolbox')}); {rtl: true, toolbox: document.getElementById('toolbox')});
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, Blockly.Xml.domToWorkspace(workspace,
document.getElementById('startBlocks')); document.getElementById('startBlocks'));
//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.';
......
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