diff --git a/example/example.html b/example/example.html index f024540d..bc7b9836 100644 --- a/example/example.html +++ b/example/example.html @@ -91,7 +91,7 @@ codex.editor = 1; var editor = new CodexEditor({ holderId : 'codex-editor', - inittialBlock : 'paragraph', + initialBlock : 'paragraph', tools: { quote: Quote, anotherTool : AnotherTool diff --git a/src/codex.js b/src/codex.js index 8af08a5b..b6f30a07 100644 --- a/src/codex.js +++ b/src/codex.js @@ -1,10 +1,39 @@ /** * Codex Editor * + * Short Description (눈_눈;) + * @version 2.0.0 * + * How to start? + * Example: + * new CodexEditor({ + * holderId : 'codex-editor', + * initialBlock : 'paragraph', + * placeholder : 'Write your story....', + * tools: { + * quote: Quote, + * anotherTool : AnotherTool + * }, + * toolsConfig: { + * quote: { + * iconClassname : 'quote-icon', + * displayInToolbox : true, + * enableLineBreaks : true + * }, + * anotherTool: { + * iconClassname : 'tool-icon' + * } + * } + * }); * + * - tools constist of object with key that is type/name of class constructor + * - toolsConfig is an additional configuration that uses Codex Editor API + * iconClassname - the name of icon class. Icon will be shown in toolbox + * displayInToolbox - if you want to see your Tool in toolbox hided in "plus" button, than set "True". By default : "False" + * enableLineBreaks - by default enter pastes new block that set as initialblock, but if you set this property "True", you break the lines + * + * @author CodeX-Team * - * @author CodeX Team */ /** diff --git a/src/components/eventDispatcher.js b/src/components/eventDispatcher.js new file mode 100644 index 00000000..8d382d2c --- /dev/null +++ b/src/components/eventDispatcher.js @@ -0,0 +1,55 @@ +/** + * @module eventDispatcher + * + * Has two important methods: + * - {Function} on - appends subscriber to the event. If event doesn't exist - creates new one + * - {Function} emit - fires all subscribers with data + * + */ +module.exports = class Events { + + /** + * @constructor + * + * @property {Object} subscribers - all subscribers grouped by event name + */ + constructor() { + + this.subscribers = {}; + + } + + /** + * @param {String} eventName - event name + * @param {Function} callback - subscriber + */ + on(eventName, callback) { + + if (!(eventName in this.subscribers)) { + + this.subscribers[eventName] = []; + + } + + // group by events + this.subscribers[eventName].push(callback); + + } + + /** + * @param {String} eventName - event name + * @param {Object} data - subscribers get this data when they were fired + */ + emit(eventName, data) { + + this.subscribers[eventName].reduce(function (previousData, currentHandler) { + + let newData = currentHandler(previousData); + + return newData ? newData : previousData; + + }, data); + + } + +}; diff --git a/src/components/modules/eventDispatcher.js b/src/components/modules/eventDispatcher.js deleted file mode 100644 index d8551641..00000000 --- a/src/components/modules/eventDispatcher.js +++ /dev/null @@ -1,35 +0,0 @@ - -module.exports = class Events { - - constructor() { - - this.subscribers = {}; - - } - - on(eventName, callback) { - - if (!(eventName in this.subscribers)) { - - this.subscribers[eventName] = []; - - } - - // group by events - this.subscribers[eventName].push(callback); - - } - - emit(eventName, data) { - - this.subscribers[eventName].reduce(function (previousData, currentHandler) { - - let newData = currentHandler(previousData); - - return newData ? newData : previousData; - - }, data); - - } - -};