mirror of https://github.com/artf/grapesjs.git
7 changed files with 161 additions and 1 deletions
@ -0,0 +1,52 @@ |
|||
define(function(require) { |
|||
|
|||
return function(config) { |
|||
|
|||
var c = config || {}, |
|||
defaults = require('./config/config'); |
|||
|
|||
// Set default options
|
|||
for (var name in defaults) { |
|||
if (!(name in c)) |
|||
c[name] = defaults[name]; |
|||
} |
|||
|
|||
var plugins = []; |
|||
/* |
|||
.plugins will be PluginManager |
|||
grapesjs.plugins.add('sheeet', function(editor){ |
|||
editor.commands.add('openbar', function(){}); |
|||
}); |
|||
*/ |
|||
var editors = []; |
|||
|
|||
return { |
|||
|
|||
plugins: plugins, |
|||
|
|||
/** |
|||
* Initializes an editor based on passed options |
|||
* @param {Object} config Configuration object |
|||
* @param {string} config.container Selector which indicates where render the editor |
|||
* @param {Object|string} config.components='' HTML string or Component model in JSON format |
|||
* @param {Object|string} config.style='' CSS string or CSS model in JSON format |
|||
* @param {Boolean} [config.copyPaste=true] Enable/Disable the possibility to copy(ctrl+c) & paste(ctrl+v) components |
|||
* @param {Boolean} [config.undoManager=true] Enable/Disable undo manager |
|||
* @param {Array} [config.plugins=[]] Array of plugins to execute on start |
|||
* @return {grapesjs.Editor} GrapesJS Editor instance |
|||
*/ |
|||
init: function(config) { |
|||
//
|
|||
var editor = new Editor(config); |
|||
//- new EditorView({model: editor}).render();
|
|||
//- inject and start plugins (plugins)
|
|||
// foreach config.plugins
|
|||
// pluginManager.get('plugin')(editor);
|
|||
//
|
|||
return editor; |
|||
}, |
|||
|
|||
}; |
|||
}; |
|||
|
|||
}); |
|||
@ -0,0 +1,7 @@ |
|||
define(function () { |
|||
return { |
|||
|
|||
plugins: [] |
|||
|
|||
}; |
|||
}); |
|||
@ -0,0 +1,59 @@ |
|||
define(function(require) { |
|||
|
|||
return function(config) { |
|||
|
|||
var c = config || {}, |
|||
defaults = require('./config/config'); |
|||
|
|||
// Set default options
|
|||
for (var name in defaults) { |
|||
if (!(name in c)) |
|||
c[name] = defaults[name]; |
|||
} |
|||
|
|||
var plugins = {}; |
|||
|
|||
return { |
|||
|
|||
/** |
|||
* Add new plugin. Plugins could not be overwritten |
|||
* @param {string} id Plugin ID |
|||
* @param {Function} plugin Function which contains all plugin logic |
|||
* @example |
|||
* PluginManager.add('some-plugin', function(editor){ |
|||
* editor.Commands.add('new-command', { |
|||
* run: function(editor, senderBtn){ |
|||
* console.log('Executed new-command'); |
|||
* } |
|||
* }) |
|||
* }); |
|||
*/ |
|||
add: function(id, plugin){ |
|||
plugins[id] = plugin; |
|||
return this; |
|||
}, |
|||
|
|||
/** |
|||
* Returns plugin by ID |
|||
* @param {string} id Plugin ID |
|||
* @return {Function|undefined} Plugin |
|||
* @example |
|||
* var plugin = PluginManager.get('some-plugin'); |
|||
* plugin(editor); |
|||
*/ |
|||
get: function(id){ |
|||
return plugins[id]; |
|||
}, |
|||
|
|||
/** |
|||
* Returns object with all plugins |
|||
* @return {Object} |
|||
*/ |
|||
getAll: function(){ |
|||
return plugins; |
|||
} |
|||
|
|||
}; |
|||
}; |
|||
|
|||
}); |
|||
@ -0,0 +1,39 @@ |
|||
var modulePath = './../../../test/specs/plugin_manager'; |
|||
|
|||
define(['PluginManager'], function(PluginManager) { |
|||
|
|||
describe('PluginManager', function() { |
|||
|
|||
describe('Main', function() { |
|||
|
|||
var obj; |
|||
var val; |
|||
var testPlugin = function(e){ |
|||
val = e; |
|||
}; |
|||
|
|||
beforeEach(function () { |
|||
obj = new PluginManager(); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete obj; |
|||
}); |
|||
|
|||
it('Object exists', function() { |
|||
obj.should.be.exist; |
|||
}); |
|||
|
|||
it('No plugins inside', function() { |
|||
obj.getAll().should.be.empty; |
|||
}); |
|||
|
|||
it('Add new plugin', function() { |
|||
obj.add('test', testPlugin); |
|||
obj.get('test').should.not.be.empty; |
|||
}); |
|||
|
|||
}); |
|||
|
|||
}); |
|||
}); |
|||
Loading…
Reference in new issue