Small Descriptions

This commit is contained in:
Murod Khaydarov 2017-11-25 18:32:08 +03:00
commit 46e9c89604
4 changed files with 86 additions and 37 deletions

View file

@ -91,7 +91,7 @@
codex.editor = 1;
var editor = new CodexEditor({
holderId : 'codex-editor',
inittialBlock : 'paragraph',
initialBlock : 'paragraph',
tools: {
quote: Quote,
anotherTool : AnotherTool

View file

@ -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 <https://ifmo.su>
*
* @author CodeX Team
*/
/**

View file

@ -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);
}
};

View file

@ -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);
}
};