Open and close toolbox categories dynamically by javascript manipulation.

119 views
Skip to first unread message

能勢純也

unread,
Dec 16, 2021, 7:05:08 AM12/16/21
to Blockly
I want to open and close toolbox categories dynamically by javascript manipulation.
Is there any technique to do this?

(I thought I could do it by changing "Class: ToolboxCategory" to
"Class: CollapsibleToolboxCategory", I thought I could do it, but I don't even know how to change it.)
Message has been deleted

fu6...@gmail.com

unread,
Dec 16, 2021, 11:34:04 AM12/16/21
to Blockly
Hi,
I am not sure which code you need.

If you want to show/hide a specific category.

var toolbox = Blockly.getMainWorkspace().toolbox_;
var categoryID = "category_logic";
var items = toolbox.getToolboxItems();
for (let item of items) {
        if (item.toolboxItemDef_.id==categoryID) {
                toolbox.setSelectedItem(item);
                setTimeout(function() {
                        toolbox.clearSelection();
                }, 3000);
                break;
        }        
};

If you want to show/hide the toolbox.

var toolbox = document.getElementsByClassName("blocklyToolboxDiv blocklyNonSelectable")[0];
if (toolbox) {
        toolbox.style.display=toolbox.style.display=="none"?"block":"none";
        Blockly.getMainWorkspace().resize();
}

Hope this helps.
toolbox.mp4

fu6...@gmail.com

unread,
Dec 16, 2021, 11:44:02 AM12/16/21
to Blockly
var toolbox = Blockly.getMainWorkspace().toolbox_;
var categoryID = "category_logic";
var items = toolbox.getToolboxItems();
for (let item of items) {
        if (item.toolboxItemDef_.id==categoryID) {
                item.hide();
                setTimeout(function() {
                        item.show();
                }, 3000);
                break;
        }        
};
category.mp4
Reply all
Reply to author
Forward
0 new messages