From df56c64f4f751c9f7e106cefde529f82fb8e5e5b Mon Sep 17 00:00:00 2001 From: Sean Lip Date: Thu, 17 Nov 2016 16:13:43 -0800 Subject: [PATCH] Fix some bugs arising in the toolbox modal for the no-categories case. --- accessible/toolbox-modal.service.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/accessible/toolbox-modal.service.js b/accessible/toolbox-modal.service.js index 7bf2c0bed..525e6635d 100644 --- a/accessible/toolbox-modal.service.js +++ b/accessible/toolbox-modal.service.js @@ -49,17 +49,22 @@ blocklyApp.ToolboxModalService = ng.core.Class({ } ); } else { - // If there are no top-level categories, we create a single category - // containing all the top-level blocks. - var workspace = new Blockly.Workspace(); - Array.from(xmlToolboxElt.children).forEach(function(topLevelNode) { - Blockly.Xml.domToBlock(workspace, topLevelNode); - }); + // A timeout seems to be needed in order for the .children accessor to + // work correctly. + var that = this; + setTimeout(function() { + // If there are no top-level categories, we create a single category + // containing all the top-level blocks. + var workspace = new Blockly.Workspace(); + Array.from(toolboxXmlElt.children).forEach(function(topLevelNode) { + Blockly.Xml.domToBlock(workspace, topLevelNode); + }); - this.toolboxCategories = [{ - categoryName: 'Available Blocks', - blocks: workspace.topBlocks_ - }]; + that.toolboxCategories = [{ + categoryName: 'Available Blocks', + blocks: workspace.topBlocks_ + }]; + }); } }], registerPreShowHook: function(preShowHook) {