diff --git a/core/flyout_base.js b/core/flyout_base.js
index f1ad80f97..82f8bbe20 100644
--- a/core/flyout_base.js
+++ b/core/flyout_base.js
@@ -447,11 +447,13 @@ Blockly.Flyout.prototype.show = function(xmlList) {
var contents = [];
var gaps = [];
this.permanentlyDisabled_.length = 0;
+ var default_gap = this.horizontalLayout_ ? this.GAP_X : this.GAP_Y;
for (var i = 0, xml; xml = xmlList[i]; i++) {
- if (xml.tagName) {
- var tagName = xml.tagName.toUpperCase();
- var default_gap = this.horizontalLayout_ ? this.GAP_X : this.GAP_Y;
- if (tagName == 'BLOCK') {
+ if (!xml.tagName) {
+ continue;
+ }
+ switch (xml.tagName.toUpperCase()) {
+ case 'BLOCK':
var curBlock = Blockly.Xml.domToBlock(xml, this.workspace_);
if (curBlock.disabled) {
// Record blocks that were initially disabled.
@@ -459,15 +461,16 @@ Blockly.Flyout.prototype.show = function(xmlList) {
this.permanentlyDisabled_.push(curBlock);
}
contents.push({type: 'block', block: curBlock});
+ // This is a deprecated method for adding gap to a block.
+ //
var gap = parseInt(xml.getAttribute('gap'), 10);
gaps.push(isNaN(gap) ? default_gap : gap);
- } else if (xml.tagName.toUpperCase() == 'SEP') {
- // Change the gap between two blocks.
+ break;
+ case 'SEP':
+ // Change the gap between two toolbox elements.
//
// The default gap is 24, can be set larger or smaller.
- // This overwrites the gap attribute on the previous block.
- // Note that a deprecated method is to add a gap to a block.
- //
+ // This overwrites the gap attribute on the previous element.
var newGap = parseInt(xml.getAttribute('gap'), 10);
// Ignore gaps before the first block.
if (!isNaN(newGap) && gaps.length > 0) {
@@ -475,14 +478,17 @@ Blockly.Flyout.prototype.show = function(xmlList) {
} else {
gaps.push(default_gap);
}
- } else if (tagName == 'BUTTON' || tagName == 'LABEL') {
+ break;
+ case 'LABEL':
// Labels behave the same as buttons, but are styled differently.
- var isLabel = tagName == 'LABEL';
+ var isLabel = true;
+ // Falls through.
+ case 'BUTTON':
var curButton = new Blockly.FlyoutButton(this.workspace_,
this.targetWorkspace_, xml, isLabel);
contents.push({type: 'button', button: curButton});
gaps.push(default_gap);
- }
+ break;
}
}
diff --git a/core/toolbox.js b/core/toolbox.js
index 82d852e39..c920d1f54 100644
--- a/core/toolbox.js
+++ b/core/toolbox.js
@@ -359,25 +359,14 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) {
lastElement = childIn;
break;
case 'SEP':
- if (lastElement) {
- if (lastElement.tagName.toUpperCase() == 'CATEGORY') {
- // Separator between two categories.
- //
- treeOut.add(new Blockly.Toolbox.TreeSeparator(
- this.treeSeparatorConfig_));
- } else {
- // Change the gap between two blocks.
- //
- // The default gap is 24, can be set larger or smaller.
- // Note that a deprecated method is to add a gap to a block.
- //
- var newGap = parseFloat(childIn.getAttribute('gap'));
- if (!isNaN(newGap) && lastElement) {
- lastElement.setAttribute('gap', newGap);
- }
- }
+ if (lastElement && lastElement.tagName.toUpperCase() == 'CATEGORY') {
+ // Separator between two categories.
+ //
+ treeOut.add(new Blockly.Toolbox.TreeSeparator(
+ this.treeSeparatorConfig_));
+ break;
}
- break;
+ // Otherwise falls through.
case 'BLOCK':
case 'SHADOW':
case 'LABEL':