diff --git a/src/block_manager/main.js b/src/block_manager/main.js index 647df6d91..55e392db6 100644 --- a/src/block_manager/main.js +++ b/src/block_manager/main.js @@ -1,4 +1,5 @@ /** + * * [init](#init) * * [add](#add) * * [get](#get) * * [getAll](#getall) @@ -13,35 +14,57 @@ * ``` * * @module BlockManager - * @param {Object} config Configurations - * @param {Array} [config.blocks=[]] Default blocks - * @example - * ... - * blockManager: { - * blocks: [ - * {id:'h1-block' label: 'Heading', content:'

...

'}, - * ... - * ], - * } - * ... */ define(function(require) { - return function(config) { - var c = config || {}, - defaults = require('./config/config'), - Blocks = require('./model/Blocks'), - BlocksView = require('./view/BlocksView'); + return function() { + var c = {}, + defaults = require('./config/config'), + Blocks = require('./model/Blocks'), + BlocksView = require('./view/BlocksView'); + var blocks, view; - for (var name in defaults) { - if (!(name in c)) - c[name] = defaults[name]; - } + return { - var blocks = new Blocks(c.blocks); - var view = new BlocksView({ collection: blocks }, c); + /** + * Name of the module + * @type {String} + * @private + */ + name: 'BlockManager', - return { + /** + * Indicates if module is public + * @type {Boolean} + * @private + */ + public: true, + + /** + * Initialize module. Automatically called with a new instance of the editor + * @param {Object} config Configurations + * @param {Array} [config.blocks=[]] Default blocks + * @example + * ... + * { + * blocks: [ + * {id:'h1-block' label: 'Heading', content:'

...

'}, + * ... + * ], + * } + * ... + * @return {this} + */ + init: function(config) { + c = config || {}; + for (var name in defaults) { + if (!(name in c)) + c[name] = defaults[name]; + } + blocks = new Blocks(c.blocks); + view = new BlocksView({ collection: blocks }, c); + return this; + }, /** * Add new block to the collection. diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index 5f73cb973..2d6d0c045 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -76,7 +76,7 @@ define([ this.initCanvas(); this.initUndoManager(); this.initStyleManager(); - this.initBlockManager(); // Requres utils, canvas + this.loadModule('BlockManager'); // Requres utils, canvas this.on('change:selectedComponent', this.componentSelected, this); }, @@ -120,17 +120,6 @@ define([ this.set('Editor', editor); }, - /** - * Initialize block manager - * @private - * */ - initBlockManager: function(){ - var cfg = this.config.blockManager; - cfg.em = this; - cfg.pStylePrefix = this.config.stylePrefix; - this.set('BlockManager', new BlockManager(cfg)); - }, - /** * Initialize device manager * @private diff --git a/test/specs/block_manager/main.js b/test/specs/block_manager/main.js index 20d207e08..a7aff1e81 100644 --- a/test/specs/block_manager/main.js +++ b/test/specs/block_manager/main.js @@ -19,7 +19,7 @@ define([ 'BlockManager', label: 'Heading', content: '

Test

' }; - obj = new BlockManager(); + obj = new BlockManager().init(); }); afterEach(function () {