Skip to content

Commit 0f10e02

Browse files
author
Matthew Matz
committed
Fix menu bug related to experimental switch
1 parent 3000e62 commit 0f10e02

File tree

1 file changed

+43
-46
lines changed

1 file changed

+43
-46
lines changed

src/main/webapp/cdn/blockly/generators/propcToolbox.js

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,61 +1483,58 @@ var colorChanges = {
14831483

14841484
function filterToolbox(profileName) {
14851485

1486-
// Set the category's label (internationalization)
1487-
xmlToolbox = xmlToolbox.replace(/key="([\S]+)"/g, function(m, p) {
1488-
return 'name="' + toolbox_label[p] + '"';
1489-
});
1486+
// Set the category's label (internationalization)
1487+
xmlToolbox = xmlToolbox.replace(/key="([\S]+)"/g, function (m, p) {
1488+
return 'name="' + toolbox_label[p] + '"';
1489+
});
14901490

1491-
// Set the palette colors
1492-
if (getURLParameter('grayscale') == '1') {
1493-
xmlToolbox = xmlToolbox.replace(/colour="([\S]+)"/g, function(m, p) {
1494-
return 'colour="' + colorChanges[p] + '"';
1495-
});
1496-
}
1491+
// Set the palette colors
1492+
if (getURLParameter('grayscale') == '1') {
1493+
xmlToolbox = xmlToolbox.replace(/colour="([\S]+)"/g, function (m, p) {
1494+
return 'colour="' + colorChanges[p] + '"';
1495+
});
1496+
}
14971497

1498-
// Convert the string to an XML object
1499-
parser = new DOMParser();
1500-
xmlDoc = parser.parseFromString(xmlToolbox,"text/xml");
1498+
// Convert the string to an XML object
1499+
parser = new DOMParser();
1500+
xmlDoc = parser.parseFromString(xmlToolbox, "text/xml");
15011501

1502-
// Loop through the specified tags and filter based on their attributes
1503-
tagSearch = ['category', 'sep', 'block'];
1504-
var toRemove = [];
1502+
// Loop through the specified tags and filter based on their attributes
1503+
tagSearch = ['category', 'sep', 'block'];
1504+
var toRemove = [];
15051505

1506-
for(var j = 0; j < tagSearch.length; j++) {
1506+
for (var j = 0; j < tagSearch.length; j++) {
15071507

1508-
var xmlElem = xmlDoc.getElementsByTagName(tagSearch[j]);
1508+
var xmlElem = xmlDoc.getElementsByTagName(tagSearch[j]);
15091509

1510-
for(var t = 0; t < xmlElem.length; t++) {
1510+
for (var t = 0; t < xmlElem.length; t++) {
15111511

1512-
var toolboxEntry = xmlElem[t];
1512+
var toolboxEntry = xmlElem[t];
15131513

1514-
var include = toolboxEntry.getAttribute('include');
1515-
if (include && include.indexOf(profileName + ',') === -1) {
1516-
toRemove.push(toolboxEntry);
1517-
}
1514+
var include = toolboxEntry.getAttribute('include');
1515+
var exclude = toolboxEntry.getAttribute('exclude');
1516+
var experimental = toolboxEntry.getAttribute('experimental');
1517+
1518+
if (include && include.indexOf(profileName + ',') === -1) {
1519+
toRemove.push(toolboxEntry);
1520+
} else if (exclude && exclude.indexOf(profileName + ',') > -1) {
1521+
toRemove.push(toolboxEntry);
1522+
} else if (experimental && inDemo !== 'demo') {
1523+
// Remove toolbox categories that are experimental if not in demo
1524+
toRemove.push(toolboxEntry);
1525+
}
1526+
}
1527+
}
15181528

1519-
var exclude = toolboxEntry.getAttribute('exclude');
1520-
if (exclude && exclude.indexOf(profileName + ',') > -1) {
1521-
toRemove.push(toolboxEntry);
1522-
}
1529+
// Remove the XML nodes that were set to be deleted
1530+
for (j = 0; j < toRemove.length; j++) {
1531+
toRemove[j].parentNode.removeChild(toRemove[j]);
1532+
}
15231533

1524-
// Remove toolbox categories that are experimental if not in demo
1525-
var experimental = toolboxEntry.getAttribute('experimental');
1526-
if (experimental && inDemo !== 'demo') {
1527-
toRemove.push(toolboxEntry);
1528-
}
1529-
}
1530-
}
1534+
// Turn the XML object back into a string
1535+
out = new XMLSerializer();
1536+
var outStr = out.serializeToString(xmlDoc);
1537+
outStr = outStr.replace(/ include="[\S]+"/g, '').replace(/ exclude="[\S]+"/g, '');
15311538

1532-
// Remove the XML nodes that were set to be deleted
1533-
for (var j = 0; j < toRemove.length; j++) {
1534-
toRemove[j].parentNode.removeChild(toRemove[j]);
1535-
}
1536-
1537-
// Turn the XML object back into a string
1538-
out = new XMLSerializer();
1539-
var outStr = out.serializeToString(xmlDoc);
1540-
outStr = outStr.replace(/ include="[\S]+"/g, '').replace(/ exclude="[\S]+"/g, '');
1541-
1542-
return outStr;
1539+
return outStr;
15431540
}

0 commit comments

Comments
 (0)