API Block Manager

Artur Arseniev edited this page Aug 31, 2016 · 2 revisions

BlockManager

Block manager helps managing various, draggable, piece of contents that could be easily reused inside templates.

Before using methods you should get first the module from the editor instance, in this way:

var blockManager = editor.BlockManager;

Parameters

  • config Object Configurations
    • config.blocks Array.<Object>= Default blocks (optional, default [])

Examples

...
{
    blocks: [
     {id:'h1-block' label: 'Heading', content:'<h1>...</h1>'},
     ...
   ],
}
...

add

Add new block to the collection.

Parameters

  • id string Block id
  • opts Object Options
    • opts.label string Name of the block
    • opts.content string HTML content
    • opts.attributes Object= Block attributes (optional, default {})

Examples

blockManager.add('h1-block', {
  label: 'Heading',
  content: '<h1>Put your title here</h1>',
  attributes: {
    title: 'Insert h1 block'
  }
});

Returns Block Added block

get

Return block by id

Parameters

Examples

var block = blockManager.get('h1-block');
console.log(JSON.stringify(block));
// {label: 'Heading', content: '<h1>Put your ...', ...}

getAll

Return all blocks

Examples

var blocks = blockManager.getAll();
console.log(JSON.stringify(blocks));
// [{label: 'Heading', content: '<h1>Put your ...'}, ...]

Returns Collection

render

Render blocks

Returns HTMLElement