mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 07:35:48 +01:00
Small Descriptions
This commit is contained in:
parent
13f003434b
commit
46e9c89604
4 changed files with 86 additions and 37 deletions
|
|
@ -91,7 +91,7 @@
|
|||
codex.editor = 1;
|
||||
var editor = new CodexEditor({
|
||||
holderId : 'codex-editor',
|
||||
inittialBlock : 'paragraph',
|
||||
initialBlock : 'paragraph',
|
||||
tools: {
|
||||
quote: Quote,
|
||||
anotherTool : AnotherTool
|
||||
|
|
|
|||
31
src/codex.js
31
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 <https://ifmo.su>
|
||||
*
|
||||
* @author CodeX Team
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
|
|||
55
src/components/eventDispatcher.js
Normal file
55
src/components/eventDispatcher.js
Normal 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);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue