BUG: load blocks closed by default?
Question
I am using the following bit of code to collapse all the block categories, unfortunately, this is not working
const categories = editor.BlockManager.getCategories();
categories.each(category => {
category.set('open', false).on('change:open', opened => {
opened.get('open') && categories.each(category => {
category !== opened && category.set('open', false)
})
})
})
live demo : https://jsfiddle.net/d4702yoh/2/
What is wrong here?
Answers (3)
That should be enough editor.Blocks.getCategories().forEach(ct => ct.set('open', false)) but categories are not created until the render of blocks (which happens, by default, when you click the Blocks tab) so you just need to execute that script once are rendered.
Hello, i have made it to close all blocks in one plugin, try to adapt to you.:
export default (editor, opt = {}) => {
const Commands = editor.Commands;
Commands.add("dina:hide-all-blocks",(editor)=>{
editor.Panels.getButton("views","open-blocks").set("active",1);
let categories = editor.BlockManager.getCategories().models;
categories.map(elem=>{
elem.view.$el.css("display","none");
});
})
};
const Commands = editor.Commands; Commands.add("dina:hide-all-blocks",(editor)=>{ editor.Panels.getButton("views","open-blocks").set("active",1); let categories = editor.BlockManager.getCategories().models; categories.map(elem=>{ elem.view.$el.css("display","none"); }); })
still the same here jsfidle : https://jsfiddle.net/46mfqeht/
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2569
[QUESTION] Show all block categories
Hi all, I am using the following bit of code to collapse all the block categories, what would the code be to expand them all?
Issue #454
Make block manager default open panel?
I tried this code: It works but doing this will hide the device selector in the top left for some reason.
Issue #1290
[BUG]Set href for link block not editable once initialized
#1277 is closed but issue still exist so i have to post as new issue Thank you for the help for earlier @maryia-kabash @artf I have made a...
Issue #1294
How to add category for default block manager?
@artf I want put all default blocks to category named "Basic". But I can't find any documents about it. I use editor.BlockManager.getAll()....
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.