mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Add variable blocks by splicing them in
This commit is contained in:
parent
bf8bc08f42
commit
6fea7b31a5
1 changed files with 13 additions and 13 deletions
|
@ -441,25 +441,25 @@ Blockly.Flyout.prototype.show = function(xmlList) {
|
|||
this.hide();
|
||||
this.clearOldBlocks_();
|
||||
|
||||
// Handle dynamic categories, represented by a name instead of a list of XML.
|
||||
// Look up the correct category generation function and call that to get a
|
||||
// valid XML list.
|
||||
if (typeof xmlList == 'string') {
|
||||
var fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback(
|
||||
xmlList);
|
||||
goog.asserts.assert(goog.isFunction(fnToApply),
|
||||
'Couldn\'t find a callback function when opening a toolbox category.');
|
||||
xmlList = fnToApply(this.workspace_.targetWorkspace);
|
||||
goog.asserts.assert(goog.isArray(xmlList),
|
||||
'The result of a toolbox category callback must be an array.');
|
||||
}
|
||||
|
||||
this.setVisible(true);
|
||||
// Create the blocks to be shown in this flyout.
|
||||
var contents = [];
|
||||
var gaps = [];
|
||||
this.permanentlyDisabled_.length = 0;
|
||||
for (var i = 0, xml; xml = xmlList[i]; i++) {
|
||||
// Handle the dynamic category for variables, represented by a name instead of a list of XML.
|
||||
// Look up the correct category generation function and call that to get a
|
||||
// valid XML list.
|
||||
if (typeof xmlList[i] === 'string') {
|
||||
var fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback(
|
||||
xmlList[i]);
|
||||
var newList = fnToApply(this.workspace_.targetWorkspace);
|
||||
// insert the new list of variable blocks in the middle of the list
|
||||
// we use splice to insert at index i, and remove a single element (the placeholder string)
|
||||
// because the spread operator (...) is not available, use apply and concat the array
|
||||
xmlList.splice.apply(xmlList, [i, 1].concat(newList));
|
||||
xml = xmlList[i];
|
||||
}
|
||||
if (xml.tagName) {
|
||||
var tagName = xml.tagName.toUpperCase();
|
||||
var default_gap = this.horizontalLayout_ ? this.GAP_X : this.GAP_Y;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue