Browse Source

Clean the index.js file

pull/803/head
Artur Arseniev 9 years ago
parent
commit
93e621126f
  1. 5
      src/editor/config/config.js
  2. 36
      src/index.js

5
src/editor/config/config.js

@ -2,9 +2,12 @@ module.exports = {
// Style prefix // Style prefix
stylePrefix: 'gjs-', stylePrefix: 'gjs-',
//TEMP // HTML string or object of components
components: '', components: '',
// CSS string or object of rules
style: '',
// Show an alert before unload the page with unsaved changes // Show an alert before unload the page with unsaved changes
noticeOnUnload: true, noticeOnUnload: true,

36
src/index.js

@ -1,33 +1,20 @@
import $ from 'cash-dom'; import $ from 'cash-dom';
import { defaults } from 'underscore'; import Editor from './editor';
import PluginManager from './plugin_manager';
import polyfills from 'utils/polyfills'; import polyfills from 'utils/polyfills';
polyfills(); polyfills();
module.exports = (() => { module.exports = (() => {
const Editor = require('editor');
const PluginManager = require('plugin_manager');
const plugins = new PluginManager(); const plugins = new PluginManager();
const editors = []; const editors = [];
const defaultConfig = { const defaultConfig = {
// If true renders editor on init // If true renders editor on init
autorender: 1, autorender: 1,
// Where init the editor
container: '',
// HTML string or object of components
components: '',
// CSS string or object of rules
style: '',
// If true, will fetch HTML and CSS from selected container // If true, will fetch HTML and CSS from selected container
fromElement: 0, fromElement: 0,
// Storage Manager
storageManager: {},
// Array of plugins to init // Array of plugins to init
plugins: [], plugins: [],
@ -51,9 +38,9 @@ module.exports = (() => {
* @param {string|HTMLElement} config.container Selector which indicates where render the editor * @param {string|HTMLElement} 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.components='' HTML string or Component model in JSON format
* @param {Object|string} config.style='' CSS string or CSS model in JSON format * @param {Object|string} config.style='' CSS string or CSS model in JSON format
* @param {Boolean} [config.fromElement=false] If true, will fetch HTML and CSS from selected container * @param {Boolean} [config.fromElement=false] If true, will fetch HTML and CSS from the selected container
* @param {Boolean} [config.undoManager=true] Enable/Disable undo manager
* @param {Array} [config.plugins=[]] Array of plugins to execute on start * @param {Array} [config.plugins=[]] Array of plugins to execute on start
* @param {Object} [config.pluginsOpts={}] Custom options for plugins
* @return {grapesjs.Editor} GrapesJS editor instance * @return {grapesjs.Editor} GrapesJS editor instance
* @example * @example
* var editor = grapesjs.init({ * var editor = grapesjs.init({
@ -64,14 +51,10 @@ module.exports = (() => {
*/ */
init(config = {}) { init(config = {}) {
const els = config.container; const els = config.container;
if (!els) throw new Error("'container' is required");
if (!els) { config = { ...config, ...defaultConfig };
throw new Error("'container' is required"); const ilEl = els instanceof window.HTMLElement;
} config.el = ilEl ? els : document.querySelector(els);
defaults(config, defaultConfig);
config.el =
els instanceof window.HTMLElement ? els : document.querySelector(els);
const editor = new Editor(config).init(); const editor = new Editor(config).init();
// Load plugins // Load plugins
@ -89,10 +72,9 @@ module.exports = (() => {
// A plugin might have extended/added some custom type so this // A plugin might have extended/added some custom type so this
// 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();
config.autorender && editor.render(); config.autorender && editor.render();
editors.push(editor); editors.push(editor);
return editor; return editor;
} }
}; };

Loading…
Cancel
Save