mirror of
https://github.com/codex-team/editor.js
synced 2026-03-15 15:15:47 +01:00
First commit
This commit is contained in:
parent
bc8fb1aed9
commit
4aa8e352d8
11 changed files with 1240 additions and 1087 deletions
2798
codex-editor.js
2798
codex-editor.js
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
|
@ -20,6 +20,7 @@ var codex = (function(codex){
|
|||
codex.caret = require('./modules/caret');
|
||||
codex.notifications = require('./modules/notifications');
|
||||
codex.parser = require('./modules/parser');
|
||||
codex.comments = require('./modules/comments');
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -70,7 +71,8 @@ var codex = (function(codex){
|
|||
codex.state = {
|
||||
jsonOutput: [],
|
||||
blocks : [],
|
||||
inputs : []
|
||||
inputs : [],
|
||||
comments : []
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -749,6 +749,18 @@ var callbacks = (function(callbacks) {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Clicks on block comment button
|
||||
*/
|
||||
callbacks.showCommentButtonClicked = function(){
|
||||
|
||||
codex.comments.add(codex.content.currentNode);
|
||||
|
||||
codex.toolbar.toolbox.close();
|
||||
codex.toolbar.settings.hideRemoveActions();
|
||||
|
||||
};
|
||||
|
||||
return callbacks;
|
||||
|
||||
})({});
|
||||
|
|
|
|||
18
modules/comments.js
Normal file
18
modules/comments.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
var comments = function(comments) {
|
||||
|
||||
comments.add = function(node) {
|
||||
|
||||
var id = node.dataset.id,
|
||||
commentInput = codex.draw.commentInput();
|
||||
|
||||
commentInput.dataset.blockId = id;
|
||||
|
||||
node.insertBefore(commentInput, node.firstChild);
|
||||
|
||||
};
|
||||
|
||||
return comments;
|
||||
|
||||
}({});
|
||||
|
||||
module.exports = comments;
|
||||
|
|
@ -366,6 +366,7 @@ var content = (function(content) {
|
|||
}
|
||||
|
||||
newBlock.dataset.tool = tool;
|
||||
newBlock.dataset.id = +(new Date);
|
||||
return newBlock;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -190,6 +190,22 @@ var draw = (function(draw) {
|
|||
return toggler;
|
||||
};
|
||||
|
||||
|
||||
draw.commentButton = function() {
|
||||
var btn = draw.node('SPAN', 'ce-toolbar__comment-btn', {innerHTML: '<i class="ce-icon-newspaper"></i>'});
|
||||
|
||||
return btn;
|
||||
};
|
||||
|
||||
draw.commentInput = function() {
|
||||
var wrapper = draw.node('DIV', 'ce-comment__wrapper', {textContent: 'Ваш комментарий:'}),
|
||||
input = draw.node('TEXTAREA', 'ce-comment__input');
|
||||
|
||||
wrapper.appendChild(input);
|
||||
|
||||
return wrapper
|
||||
};
|
||||
|
||||
/**
|
||||
* Redactor tools wrapper
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -101,6 +101,22 @@ var saver = (function(saver) {
|
|||
codex.state.jsonOutput.push(output);
|
||||
};
|
||||
|
||||
saver.saveComments = function() {
|
||||
|
||||
var comments = codex.nodes.redactor.querySelectorAll('.ce-comment__wrapper');
|
||||
|
||||
for (var i = 0; i < comments.length; i++) {
|
||||
|
||||
var comment = {
|
||||
blockId: comments[i].dataset.blockId,
|
||||
text: comments[i].querySelector('.ce-comment__input').value
|
||||
};
|
||||
|
||||
codex.state.comments.push(comment);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return saver;
|
||||
|
||||
})({});
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ var ui = (function(ui){
|
|||
blockButtons,
|
||||
blockSettings,
|
||||
showSettingsButton,
|
||||
showCommentButton,
|
||||
showTrashButton,
|
||||
toolbox,
|
||||
plusButton;
|
||||
|
|
@ -74,6 +75,7 @@ var ui = (function(ui){
|
|||
inlineToolbar = codex.draw.inlineToolbar();
|
||||
plusButton = codex.draw.plusButton();
|
||||
showSettingsButton = codex.draw.settingsButton();
|
||||
showCommentButton = codex.draw.commentButton();
|
||||
showTrashButton = codex.toolbar.settings.makeRemoveBlockButton();
|
||||
blockSettings = codex.draw.blockSettings();
|
||||
blockButtons = codex.draw.blockButtons();
|
||||
|
|
@ -93,6 +95,7 @@ var ui = (function(ui){
|
|||
*/
|
||||
blockButtons.appendChild(showSettingsButton);
|
||||
blockButtons.appendChild(showTrashButton);
|
||||
blockButtons.appendChild(showCommentButton);
|
||||
blockButtons.appendChild(blockSettings);
|
||||
|
||||
/** Append plus button */
|
||||
|
|
@ -121,6 +124,7 @@ var ui = (function(ui){
|
|||
codex.nodes.defaultSettings = defaultSettings;
|
||||
codex.nodes.showSettingsButton = showSettingsButton;
|
||||
codex.nodes.showTrashButton = showTrashButton;
|
||||
codex.nodes.showCommentButton = showCommentButton;
|
||||
|
||||
codex.nodes.redactor = redactor;
|
||||
|
||||
|
|
@ -276,6 +280,13 @@ var ui = (function(ui){
|
|||
* Clicks to SETTINGS button in toolbar
|
||||
*/
|
||||
codex.nodes.showSettingsButton.addEventListener('click', codex.callback.showSettingsButtonClicked, false );
|
||||
|
||||
/**
|
||||
* Clicks to COMMENT button in toolbar
|
||||
*/
|
||||
codex.nodes.showCommentButton.addEventListener('click', codex.callback.showCommentButtonClicked, false );
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated ( but now in use for syncronization );
|
||||
* Any redactor changes: keyboard input, mouse cut/paste, drag-n-drop text
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
"babel-core": "^6.21.0",
|
||||
"babel-loader": "^6.2.10",
|
||||
"babel-polyfill": "^6.20.0",
|
||||
"babel-preset-es2015": "^6.18.0",
|
||||
"babel-runtime": "^6.20.0",
|
||||
"css-loader": "^0.26.1",
|
||||
"extract-text-webpack-plugin": "^1.0.1",
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue