mirror of
https://github.com/codex-team/editor.js
synced 2024-06-02 05:52:38 +02:00
Merge pull request #201 from codex-team/add-update
Add content.clear and content.load methods
This commit is contained in:
commit
30464668b9
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -741,6 +741,63 @@ module.exports = (function (content) {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear editors content
|
||||
*
|
||||
* @param {Boolean} all — if true, delete all article data (content, id, etc.)
|
||||
*/
|
||||
content.clear = function (all) {
|
||||
|
||||
editor.nodes.redactor.innerHTML = '';
|
||||
editor.content.sync();
|
||||
editor.ui.saveInputs();
|
||||
if (all) {
|
||||
|
||||
editor.state.blocks = null;
|
||||
|
||||
} else if (editor.state.blocks) {
|
||||
|
||||
editor.state.blocks.items = [];
|
||||
|
||||
}
|
||||
|
||||
editor.content.currentNode = null;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Load new data to editor
|
||||
* If editor is not empty, just append articleData.items
|
||||
*
|
||||
* @param articleData.items
|
||||
*/
|
||||
content.load = function (articleData) {
|
||||
|
||||
var currentContent = editor.state.blocks ? Object.assign({}, editor.state.blocks) : null;
|
||||
|
||||
editor.content.clear();
|
||||
|
||||
if (!currentContent) {
|
||||
|
||||
editor.state.blocks = articleData;
|
||||
|
||||
} else if (!currentContent.items) {
|
||||
|
||||
currentContent.items = articleData.items;
|
||||
editor.state.blocks = currentContent;
|
||||
|
||||
} else {
|
||||
|
||||
currentContent.items = currentContent.items.concat(articleData.items);
|
||||
editor.state.blocks = currentContent;
|
||||
|
||||
}
|
||||
|
||||
editor.renderer.makeBlocksFromData();
|
||||
|
||||
};
|
||||
|
||||
return content;
|
||||
|
||||
})({});
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "codex.editor",
|
||||
"version": "1.7.5",
|
||||
"version": "1.7.6",
|
||||
"description": "Codex Editor. Native JS, based on API and Open Source",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in a new issue