From 89d1aafd5baac078014414453a2c74e677d4a8b7 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 28 Apr 2015 15:07:33 -0700 Subject: [PATCH] Update demos to use non-deprecated workspace calls. --- appengine/README.txt | 7 +++++-- appengine/app.yaml | 5 +++-- demos/code/code.js | 2 +- demos/generator/index.html | 2 +- demos/graph/index.html | 16 +++++++++++----- demos/interpreter/index.html | 12 ++++++------ demos/maxBlocks/index.html | 7 +++---- demos/plane/plane.js | 24 +++++++++++++++--------- demos/rtl/index.html | 4 ++-- 9 files changed, 47 insertions(+), 32 deletions(-) diff --git a/appengine/README.txt b/appengine/README.txt index 7bf4c48f6..f91e2d86a 100644 --- a/appengine/README.txt +++ b/appengine/README.txt @@ -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/ diff --git a/appengine/app.yaml b/appengine/app.yaml index a0655d844..001c4e481 100644 --- a/appengine/app.yaml +++ b/appengine/app.yaml @@ -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$ diff --git a/demos/code/code.js b/demos/code/code.js index 53e15bdae..d29ecdb33 100644 --- a/demos/code/code.js +++ b/demos/code/code.js @@ -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); diff --git a/demos/generator/index.html b/demos/generator/index.html index fa3f7026e..eadd4f6a3 100644 --- a/demos/generator/index.html +++ b/demos/generator/index.html @@ -115,7 +115,7 @@ diff --git a/demos/plane/plane.js b/demos/plane/plane.js index 64a24798e..38a183a09 100644 --- a/demos/plane/plane.js +++ b/demos/plane/plane.js @@ -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() { ''; 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()); }; /** diff --git a/demos/rtl/index.html b/demos/rtl/index.html index 00fd45daf..06d769f93 100644 --- a/demos/rtl/index.html +++ b/demos/rtl/index.html @@ -23,9 +23,9 @@