--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
var xml = null;
var request = new XMLHttpRequest();
request.open('GET', '/blocky/js/basic/toolbox.xml', false);
request.send();
if (request.readyState == 4 && request.status == 200) {
xml = request.responseXML;
} var jsonCategory = document.createElement("category");
jsonCategory.setAttribute("name", "Json");
jsonCategory.setAttribute("colour", "#43b7ff");
xml.documentElement.insertBefore(jsonCategory, xml.documentElement.firstChild); [
CUSTOM_OBJECT_FROM_JSON_BLOCK_NAME,
CUSTOM_OBJECT_TO_JSON_BLOCK_NAME,
CUSTOM_OBJECT_GET_BLOCK_NAME,
CUSTOM_OBJECT_SET_BLOCK_NAME,
CUSTOM_OBJECT_CREATE_BLOCK_NAME
].forEach(function(blockType) {
var jsonBlock = document.createElement("block");
jsonBlock.setAttribute("type", blockType);
jsonCategory.appendChild(jsonBlock);
} var toolbox = new XMLSerializer().serializeToString(xml.documentElement);
--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
// Create a new XML document (which represents a toolbox)
var toolboxXml = document.implementation.createDocument(null, "toolbox");
[
"/blocky/js/basic/toolbox.xml",
"/blocky/js/json/toolbox.xml",
"/blocky/js/nodered/toolbox.xml"
].forEach(function(filePath) {
var request = new XMLHttpRequest();
request.open('GET', filePath, false); // `false` makes the request synchronous
request.send();
if (request.readyState == 4 && request.status == 200) {
// Get all categories in the new XML document
var newCategories = request.responseXML.getElementsByTagName("category");
// Iterate backwards since categories can be moved away from this list (to the toolbox)
for (i = newCategories.length - 1; i >= 0; --i) {
var newCategory = newCategories[i];
// Get the category name
var name = newCategory.getAttribute('name');
// Try to find an existing category with the same name.
// Indeed multiple toolboxes can put blocks in the same category...
var existingCategory = toolboxXml.getElementsByName(name);
if (existingCategory.length === 0) {
// If the new category didn't exist yet in the toolbox, move the entire new category to the start of the toolbox
toolboxXml.documentElement.insertBefore(newCategory, toolboxXml.documentElement.firstChild);
}
else {
var newBlocks = newCategory.children;
// Move all the blocks (and their children) from the newCategory to the existingCategory
for (var k = 0; k < newBlocks.length; k++) {
var newBlock = newBlocks[k];
existingCategory[0].appendChild(newBlock);
}
}
}
}
else {
console.log("Cannot load toolbox.xml for Blocky");
}
});
<xml xmlns="http://www.w3.org/1999/xhtml" id="toolbox" style="display: none;">
<category name="Json objects" colour="#43B7FF">
<block type="object_from_json"></block>
<block type="object_to_json"></block>
<block type="object_get">
<value name="field_name">
<shadow type="field_input">
<field name="text">payload</field>
</shadow>
</value>
</block>
<block type="object_set">
<field name="text">payload</field>
</block>
<block type="object_create"></block>
</category>
</xml>--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.