|
|
@ -1,13 +1,11 @@ |
|
|
import { isUndefined } from 'underscore'; |
|
|
import { isUndefined, defaults } from 'underscore'; |
|
|
|
|
|
|
|
|
module.exports = (config => { |
|
|
module.exports = (() => { |
|
|
var c = config || {}, |
|
|
const defaultConfig = require('./config/config'); |
|
|
defaults = require('./config/config'), |
|
|
const Editor = require('editor'); |
|
|
Editor = require('editor'), |
|
|
const PluginManager = require('plugin_manager'); |
|
|
PluginManager = require('plugin_manager'); |
|
|
const plugins = new PluginManager(); |
|
|
|
|
|
const editors = []; |
|
|
var plugins = new PluginManager(); |
|
|
|
|
|
var editors = []; |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
|
|
|
|
|
|
@ -33,35 +31,28 @@ module.exports = (config => { |
|
|
* style: '.hello{color: red}', |
|
|
* style: '.hello{color: red}', |
|
|
* }) |
|
|
* }) |
|
|
*/ |
|
|
*/ |
|
|
init(config) { |
|
|
init(config = {}) { |
|
|
var c = config || {}; |
|
|
const els = config.container; |
|
|
var els = c.container; |
|
|
|
|
|
|
|
|
|
|
|
// Make a missing $ more verbose
|
|
|
// Make a missing $ more verbose
|
|
|
if (isUndefined($)) { |
|
|
if (isUndefined($)) { |
|
|
throw 'jQuery not found'; |
|
|
throw 'jQuery not found'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Set default options
|
|
|
|
|
|
for (var name in defaults) { |
|
|
|
|
|
if (!(name in c)) |
|
|
|
|
|
c[name] = defaults[name]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!els) { |
|
|
if (!els) { |
|
|
throw new Error("'container' is required"); |
|
|
throw new Error("'container' is required"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
c.el = document.querySelector(els); |
|
|
defaults(config, defaultConfig); |
|
|
var editor = new Editor(c).init(); |
|
|
config.el = document.querySelector(els); |
|
|
|
|
|
const editor = new Editor(config).init(); |
|
|
|
|
|
|
|
|
// Load plugins
|
|
|
// Load plugins
|
|
|
var plugs = plugins.getAll(); |
|
|
config.plugins.forEach(pluginId => { |
|
|
c.plugins.forEach((pluginId) => { |
|
|
const plugin = plugins.get(pluginId); |
|
|
let plugin = plugins.get(pluginId); |
|
|
|
|
|
|
|
|
|
|
|
if (plugin) { |
|
|
if (plugin) { |
|
|
plugin(editor, c.pluginsOpts[pluginId] || {}); |
|
|
plugin(editor, config.pluginsOpts[pluginId] || {}); |
|
|
} else { |
|
|
} else { |
|
|
console.warn(`Plugin ${pluginId} not found`); |
|
|
console.warn(`Plugin ${pluginId} not found`); |
|
|
} |
|
|
} |
|
|
@ -72,7 +63,7 @@ module.exports = (config => { |
|
|
// is a good point to load stuff like components, css rules, etc.
|
|
|
// is a good point to load stuff like components, css rules, etc.
|
|
|
editor.getModel().loadOnStart(); |
|
|
editor.getModel().loadOnStart(); |
|
|
|
|
|
|
|
|
c.autorender && editor.render(); |
|
|
config.autorender && editor.render(); |
|
|
|
|
|
|
|
|
editors.push(editor); |
|
|
editors.push(editor); |
|
|
return editor; |
|
|
return editor; |
|
|
|